From 90c7f47a0fd8afc77e8f1024858b2c9a4e07ccac Mon Sep 17 00:00:00 2001 From: Abhaas Goyal Date: Mon, 29 Jan 2024 23:06:13 +1100 Subject: [PATCH] Test whether user is member of the project read from config --- benchcab/config.py | 5 +++-- tests/test_config.py | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/benchcab/config.py b/benchcab/config.py index 7f99611b..1602b919 100644 --- a/benchcab/config.py +++ b/benchcab/config.py @@ -98,8 +98,9 @@ def read_optional_key(config: dict): ) if config["project"] not in groups: - msg = f"Could not validate project name ({config['project']}): Check if project name is correct" - raise ConfigValidationError(msg) + msg = f"User is not a member of project [{config['project']}]: Check if project key is correct" + + raise ValueError(msg) if "realisations" in config: for r in config["realisations"]: diff --git a/tests/test_config.py b/tests/test_config.py index d6f6e000..221129eb 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -170,15 +170,28 @@ def test_read_optional_key_add_data(input_config, output_config, request): assert pformat(config) == pformat(request.getfixturevalue(output_config)) -def test_no_project(default_only_config, monkeypatch): +def test_no_project_name(default_only_config, monkeypatch): """If project key and $PROJECT are not provided, then raise error.""" monkeypatch.delenv("PROJECT") - error_msg = re.escape( + err_msg = re.escape( """Couldn't resolve project: check 'project' in config.yaml and/or $PROJECT set in ~/.config/gadi-login.conf """ ) - with pytest.raises(ValueError, match=error_msg): + with pytest.raises(ValueError, match=err_msg): + bc.read_optional_key(default_only_config) + + +def test_user_not_in_project(default_only_config): + """If user is not in viewable NCI projects, raise error.""" + default_only_config["project"] = "non_existing" + err_msg = re.escape( + "User is not a member of project [non_existing]: Check if project key is correct" + ) + with pytest.raises( + ValueError, + match=err_msg, + ): bc.read_optional_key(default_only_config)