1313import benchcab .utils as bu
1414
1515# Temporarily set $PROJECT for testing module
16- OPTIONAL_CONFIG_PROJECT = "tt1 "
16+ OPTIONAL_CONFIG_PROJECT = "ks32 "
1717
1818
1919@pytest .fixture (autouse = True )
@@ -24,6 +24,13 @@ def _set_project_env_variable(monkeypatch):
2424 yield
2525
2626
27+ @pytest .fixture (autouse = True )
28+ def _set_project_validation_dirs ():
29+ with mock .patch ("os.listdir" ) as mocked_listdir :
30+ mocked_listdir .return_value = ["hh5" , OPTIONAL_CONFIG_PROJECT ]
31+ yield
32+
33+
2734@pytest .fixture ()
2835def config_str (request ) -> str :
2936 """Provide relative YAML path string of data files."""
@@ -89,7 +96,7 @@ def all_optional_custom_config(default_only_config) -> dict:
8996 Reads from config-optional.yml
9097 """
9198 config = default_only_config | {
92- "project" : "optional " ,
99+ "project" : "hh5 " ,
93100 "fluxsite" : {
94101 "experiment" : "AU-Tum" ,
95102 "multiprocess" : False ,
@@ -163,15 +170,28 @@ def test_read_optional_key_add_data(input_config, output_config, request):
163170 assert pformat (config ) == pformat (request .getfixturevalue (output_config ))
164171
165172
166- def test_no_project (default_only_config , monkeypatch ):
173+ def test_no_project_name (default_only_config , monkeypatch ):
167174 """If project key and $PROJECT are not provided, then raise error."""
168175 monkeypatch .delenv ("PROJECT" )
169- error_msg = re .escape (
176+ err_msg = re .escape (
170177 """Couldn't resolve project: check 'project' in config.yaml
171178 and/or $PROJECT set in ~/.config/gadi-login.conf
172179 """
173180 )
174- with pytest .raises (ValueError , match = error_msg ):
181+ with pytest .raises (ValueError , match = err_msg ):
182+ bc .read_optional_key (default_only_config )
183+
184+
185+ def test_user_not_in_project (default_only_config ):
186+ """If user is not in viewable NCI projects, raise error."""
187+ default_only_config ["project" ] = "non_existing"
188+ err_msg = re .escape (
189+ "User is not a member of project [non_existing]: Check if project key is correct"
190+ )
191+ with pytest .raises (
192+ ValueError ,
193+ match = err_msg ,
194+ ):
175195 bc .read_optional_key (default_only_config )
176196
177197
0 commit comments