Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test in-checkout copy of repository-permissions.yaml #255

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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