Skip to content

Commit

Permalink
skip non-applicable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cbartz committed Aug 1, 2024
1 parent 2792fee commit 20dc596
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
12 changes: 11 additions & 1 deletion tests/app/integration/test_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from repo_policy_compliance import blueprint, github_client, policy
from tests import assert_

from .conftest import AuthenticationMethod
from .types_ import RequestedCollaborator

EXPECTED_PULL_REQUEST_KEYS = (
Expand Down Expand Up @@ -786,13 +787,21 @@ def test_always_fail(client: FlaskClient, runner_token: str):
@pytest.mark.parametrize(
"invalid_token", [pytest.param("", id="empty"), pytest.param("invalid", id="invalid")]
)
def test_health_fail(client: FlaskClient, invalid_token: str, monkeypatch: pytest.MonkeyPatch):
def test_health_fail(
client: FlaskClient,
invalid_token: str,
monkeypatch: pytest.MonkeyPatch,
github_auth: AuthenticationMethod,
):
"""
arrange: given flask application with the blueprint registered and invalid token set in
GITHUB_TOKEN environment variable
act: when the health check endpoint is requested
assert: then 500 is returned.
"""
if github_auth == AuthenticationMethod.GITHUB_APP:
pytest.skip("This test is not applicable for GitHub App authentication.")

monkeypatch.setenv(github_client.GITHUB_TOKEN_ENV_NAME, invalid_token)

response = client.get(blueprint.HEALTH_ENDPOINT)
Expand Down Expand Up @@ -864,6 +873,7 @@ def test_internal_server_error(
assert: 500 error is returned with reason.
"""
monkeypatch.setenv(github_client.GITHUB_TOKEN_ENV_NAME, "")
monkeypatch.setenv(github_client.GITHUB_APP_PRIVATE_KEY_ENV_NAME, "")
main_branch = github_repository.get_branch(github_repository.default_branch)
request_data = {
"repository_name": github_repository.full_name,
Expand Down
4 changes: 4 additions & 0 deletions tests/app/integration/test_github_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from repo_policy_compliance.check import Result, target_branch_protection
from repo_policy_compliance.github_client import GITHUB_TOKEN_ENV_NAME
from tests.app.integration.conftest import AuthenticationMethod


@pytest.mark.parametrize(
Expand Down Expand Up @@ -34,12 +35,15 @@ def test_github_token(
fail_reason: str,
github_repository_name: str,
monkeypatch: pytest.MonkeyPatch,
github_auth: AuthenticationMethod,
):
"""
arrange: A github repository name and a missing or invalid github token.
act: when the github client is injected to target_branch_protection.
assert: An expected error is raised with a specific error message.
"""
if github_auth == AuthenticationMethod.GITHUB_APP:
pytest.skip("This test is not applicable for GitHub App authentication.")
monkeypatch.setenv(GITHUB_TOKEN_ENV_NAME, str(github_token_value))
# The github_client is injected
report = target_branch_protection( # pylint: disable=no-value-for-parameter
Expand Down
12 changes: 10 additions & 2 deletions tests/app/integration/test_pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,27 @@ def test_invalid_policy():
],
indirect=["github_branch", "protected_github_branch"],
)
@pytest.mark.usefixtures("protected_github_branch")
def test_pull_request_disallow_fork(
@pytest.mark.usefixtures("protected_github_branch") # All the arguments are required for the test
def test_pull_request_disallow_fork( # pylint: disable=too-many-arguments
github_branch: Branch,
github_repository_name: str,
forked_github_repository: Repository,
policy_enabled: bool,
expected_result: Result,
github_auth: AuthenticationMethod,
):
"""
arrange: given a forked repository and a disable_fork policy enabled/disabled.
act: when pull_request is called
assert: then a expected result is returned.
"""
# this test requires the github auth method to have access to the personal fork
# which would require a separate installation id for the app auth to be passed to the test,
# which is currently not supported (few tests which requires it so the overhead
# of adding it is not worth it)
if github_auth == AuthenticationMethod.GITHUB_APP:
pytest.skip("This test requires a personal fork to be accessible by the Github App Auth.")

policy_document = {
policy.JobType.PULL_REQUEST: {
policy.PullRequestProperty.DISALLOW_FORK: {policy.ENABLED_KEY: policy_enabled},
Expand Down

0 comments on commit 20dc596

Please sign in to comment.