Skip to content

Commit

Permalink
Merge pull request #255 from opensafely-core/iaindillingham/test-in-c…
Browse files Browse the repository at this point in the history
…heckout-copy-of-repository-permissions-yaml

Test in-checkout copy of `repository-permissions.yaml`
  • Loading branch information
iaindillingham authored Apr 30, 2024
2 parents 9537201 + 23158c4 commit 7afe75f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions opensafely/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
9 changes: 8 additions & 1 deletion tests/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,16 +348,23 @@ 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
branch = subprocess.run(["git", "rev-parse", "--abbrev-ref", "HEAD"])
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():
Expand Down

0 comments on commit 7afe75f

Please sign in to comment.