Skip to content

Commit

Permalink
Test whether user is member of the project read from config
Browse files Browse the repository at this point in the history
  • Loading branch information
abhaasgoyal committed Jan 29, 2024
1 parent 1751a66 commit 90c7f47
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
5 changes: 3 additions & 2 deletions benchcab/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand Down
19 changes: 16 additions & 3 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 90c7f47

Please sign in to comment.