@@ -60,3 +60,41 @@ def test_simple_export_ert_environment_variables(snakeoil_export_surface: Path)
6060 avg_poro = FmuResults .model_validate (avg_poro_metadata ) # asserts valid
6161 assert avg_poro .root .fmu .ert .simulation_mode == ErtSimulationMode .test_run
6262 assert avg_poro .root .fmu .ert .experiment .id is not None
63+
64+
65+ def test_snakeoil_wf_case_metadata_includes_user (
66+ fmu_snakeoil_project : Path , monkeypatch : Any , mocker : Any
67+ ) -> None :
68+ """Test that if 'ert_username' argument is specified in WF_CREATE_CASE_METADATA
69+ a deprecation warning is emitted and the input is ignored.
70+ """
71+ monkeypatch .chdir (fmu_snakeoil_project / "ert/model" )
72+
73+ Path (
74+ fmu_snakeoil_project / "ert/bin/workflows/xhook_create_case_metadata"
75+ ).write_text (
76+ "WF_CREATE_CASE_METADATA <SCRATCH>/<USER>/<CASE_DIR> <CONFIG_PATH> <CASE_DIR> "
77+ "<USER>" , # ert user (now deprecated)
78+ encoding = "utf-8" ,
79+ )
80+
81+ add_create_case_workflow ("snakeoil.ert" )
82+
83+ mocker .patch (
84+ "sys.argv" ,
85+ ["ert" , "ensemble_experiment" , "snakeoil.ert" , "--disable-monitoring" ],
86+ )
87+ with pytest .warns (FutureWarning , match = "'ert_username' is deprecated" ):
88+ ert .__main__ .main ()
89+
90+ fmu_case_yml = (
91+ fmu_snakeoil_project / "scratch/user/snakeoil/share/metadata/fmu_case.yml"
92+ )
93+ assert fmu_case_yml .exists ()
94+
95+ with open (fmu_case_yml , encoding = "utf-8" ) as f :
96+ fmu_case = yaml .safe_load (f )
97+
98+ # check that user input is ignored
99+ assert fmu_case ["fmu" ]["case" ]["user" ]["id" ] != "user"
100+ assert fmu_case ["fmu" ]["case" ]["user" ]["id" ] == getpass .getuser ()
0 commit comments