From 23158c479d303fff4f5e5d0b79c9c2096e58ebcb Mon Sep 17 00:00:00 2001 From: Iain Dillingham Date: Tue, 30 Apr 2024 11:50:20 +0100 Subject: [PATCH] Test in-checkout copy of `repository-permissions.yaml` If the in-checkout version of `repository-permissions.yaml` is invalid, then the test will fail. Closes #253 --- opensafely/check.py | 7 +++++++ tests/test_check.py | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/opensafely/check.py b/opensafely/check.py index 01230c1..d9b00b9 100644 --- a/opensafely/check.py +++ b/opensafely/check.py @@ -204,6 +204,13 @@ def get_datasource_permissions(permissions_url): return permissions +def get_local_permissions(): + path = Path(Path(PERMISSIONS_URL).name) + yaml = YAML() + permissions = yaml.load(path.read_text()) + return permissions + + def get_repository_name(continue_on_error): if "GITHUB_REPOSITORY" in os.environ: return os.environ["GITHUB_REPOSITORY"] diff --git a/tests/test_check.py b/tests/test_check.py index 5b05c5e..b385436 100644 --- a/tests/test_check.py +++ b/tests/test_check.py @@ -348,9 +348,10 @@ def test_check( validate_pass(capsys, continue_on_error) -def test_repository_permissions_yaml(): +def get_datasource_permissions(): try: permissions = check.get_datasource_permissions(check.PERMISSIONS_URL) + return permissions except RequestException as e: # This test should always pass on main, but if we've renamed the file # on the branch, it will fail before it's merged @@ -358,6 +359,12 @@ def test_repository_permissions_yaml(): if branch != "main" and "Error 404" in str(e): pytest.xfail("Permissions file does not exist on main yet") + +@pytest.mark.parametrize( + "get_permissions", [get_datasource_permissions, check.get_local_permissions] +) +def test_repository_permissions_yaml(get_permissions): + permissions = get_permissions() assert permissions, "empty permissions file" assert type(permissions) == CommentedMap, "invalid permissions file" for k, v in permissions.items():