Skip to content

Commit

Permalink
fix linting issues'
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkandersson committed Nov 24, 2023
1 parent 7f731bf commit 1738dc9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 126 deletions.
51 changes: 9 additions & 42 deletions tests/integration/test_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@
# tests easier to understand
# pylint: disable=duplicate-code

from uuid import uuid4

import pytest
from github.Branch import Branch

from repo_policy_compliance import PushInput, policy, push
from repo_policy_compliance.check import Result

from .types_ import BranchWithProtection, RequestedCollaborator
from .types_ import RequestedCollaborator


def test_invalid_policy():
Expand All @@ -27,47 +24,33 @@ def test_invalid_policy():
policy_document = {"invalid": "value"}

report = push(
input_=PushInput(
repository_name="repository 1",
branch_name="branch 1",
commit_sha="commit sha 1",
),
input_=PushInput(repository_name="repository 1"),
policy_document=policy_document,
)

assert report.result == Result.FAIL, report.reason


@pytest.mark.parametrize(
"github_branch, protected_github_branch, collaborators_with_permission, policy_enabled, "
"expected_result",
"collaborators_with_permission, policy_enabled, expected_result",
[
pytest.param(
f"test-branch/push/collaborators-fail-enabled/{uuid4()}",
BranchWithProtection(),
RequestedCollaborator("admin", "admin"),
True,
Result.FAIL,
id="policy enabled",
),
pytest.param(
f"test-branch/push/collaborators-fail-disabled/{uuid4()}",
BranchWithProtection(),
RequestedCollaborator("admin", "admin"),
False,
Result.PASS,
id="policy disabled",
),
],
indirect=["github_branch", "protected_github_branch", "collaborators_with_permission"],
indirect=["collaborators_with_permission"],
)
@pytest.mark.usefixtures("protected_github_branch", "collaborators_with_permission")
def test_collaborators(
github_branch: Branch,
github_repository_name: str,
policy_enabled: bool,
expected_result: Result,
):
@pytest.mark.usefixtures("collaborators_with_permission")
def test_collaborators(github_repository_name: str, policy_enabled: bool, expected_result: Result):
"""
arrange: given a branch that are compliant and outside collaborators with more than read
permission and whether the policy is enabled
Expand All @@ -81,37 +64,21 @@ def test_collaborators(
}

report = push(
input_=PushInput(
repository_name=github_repository_name,
branch_name=github_branch.name,
commit_sha=github_branch.commit.sha,
),
input_=PushInput(repository_name=github_repository_name),
policy_document=policy_document,
)

assert report.result == expected_result


@pytest.mark.parametrize(
"github_branch, protected_github_branch",
[pytest.param(f"test-branch/push/pass/{uuid4()}", BranchWithProtection())],
indirect=True,
)
@pytest.mark.usefixtures("protected_github_branch")
def test_pass(
github_branch: Branch, github_repository_name: str, caplog: pytest.LogCaptureFixture
):
def test_pass(github_repository_name: str, caplog: pytest.LogCaptureFixture):
"""
arrange: given a branch and repository that is compliant
act: when push is called
assert: then a pass report is returned.
"""
report = push(
input_=PushInput(
repository_name=github_repository_name,
branch_name=github_branch.name,
commit_sha=github_branch.commit.sha,
),
input_=PushInput(repository_name=github_repository_name),
)

assert report.result == Result.PASS
Expand Down
51 changes: 9 additions & 42 deletions tests/integration/test_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@
# tests easier to understand
# pylint: disable=duplicate-code

from uuid import uuid4

import pytest
from github.Branch import Branch

from repo_policy_compliance import ScheduleInput, policy, schedule
from repo_policy_compliance.check import Result

from .types_ import BranchWithProtection, RequestedCollaborator
from .types_ import RequestedCollaborator


def test_invalid_policy():
Expand All @@ -27,47 +24,33 @@ def test_invalid_policy():
policy_document = {"invalid": "value"}

report = schedule(
input_=ScheduleInput(
repository_name="repository 1",
branch_name="branch 1",
commit_sha="commit sha 1",
),
input_=ScheduleInput(repository_name="repository 1"),
policy_document=policy_document,
)

assert report.result == Result.FAIL, report.reason


@pytest.mark.parametrize(
"github_branch, protected_github_branch, collaborators_with_permission, policy_enabled, "
"expected_result",
"collaborators_with_permission, policy_enabled, expected_result",
[
pytest.param(
f"test-branch/schedule/collaborators-fail-enabled/{uuid4()}",
BranchWithProtection(),
RequestedCollaborator("admin", "admin"),
True,
Result.FAIL,
id="policy enabled",
),
pytest.param(
f"test-branch/schedule/collaborators-fail-disabled/{uuid4()}",
BranchWithProtection(),
RequestedCollaborator("admin", "admin"),
False,
Result.PASS,
id="policy disabled",
),
],
indirect=["github_branch", "protected_github_branch", "collaborators_with_permission"],
indirect=["collaborators_with_permission"],
)
@pytest.mark.usefixtures("protected_github_branch", "collaborators_with_permission")
def test_collaborators(
github_branch: Branch,
github_repository_name: str,
policy_enabled: bool,
expected_result: Result,
):
@pytest.mark.usefixtures("collaborators_with_permission")
def test_collaborators(github_repository_name: str, policy_enabled: bool, expected_result: Result):
"""
arrange: given a branch that are compliant and outside collaborators with more than read
permission and whether the policy is enabled
Expand All @@ -81,37 +64,21 @@ def test_collaborators(
}

report = schedule(
input_=ScheduleInput(
repository_name=github_repository_name,
branch_name=github_branch.name,
commit_sha=github_branch.commit.sha,
),
input_=ScheduleInput(repository_name=github_repository_name),
policy_document=policy_document,
)

assert report.result == expected_result


@pytest.mark.parametrize(
"github_branch, protected_github_branch",
[pytest.param(f"test-branch/schedule/pass/{uuid4()}", BranchWithProtection())],
indirect=True,
)
@pytest.mark.usefixtures("protected_github_branch")
def test_pass(
github_branch: Branch, github_repository_name: str, caplog: pytest.LogCaptureFixture
):
def test_pass(github_repository_name: str, caplog: pytest.LogCaptureFixture):
"""
arrange: given a branch and repository that is compliant
act: when schedule is called
assert: then a pass report is returned.
"""
report = schedule(
input_=ScheduleInput(
repository_name=github_repository_name,
branch_name=github_branch.name,
commit_sha=github_branch.commit.sha,
),
input_=ScheduleInput(repository_name=github_repository_name),
)

assert report.result == Result.PASS
Expand Down
51 changes: 9 additions & 42 deletions tests/integration/test_workflow_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@

"""Tests for the workflow_dispatch function."""

from uuid import uuid4

import pytest
from github.Branch import Branch

from repo_policy_compliance import WorkflowDispatchInput, policy, workflow_dispatch
from repo_policy_compliance.check import Result

from .types_ import BranchWithProtection, RequestedCollaborator
from .types_ import RequestedCollaborator


def test_invalid_policy():
Expand All @@ -23,47 +20,33 @@ def test_invalid_policy():
policy_document = {"invalid": "value"}

report = workflow_dispatch(
input_=WorkflowDispatchInput(
repository_name="repository 1",
branch_name="branch 1",
commit_sha="commit sha 1",
),
input_=WorkflowDispatchInput(repository_name="repository 1"),
policy_document=policy_document,
)

assert report.result == Result.FAIL, report.reason


@pytest.mark.parametrize(
"github_branch, protected_github_branch, collaborators_with_permission, policy_enabled, "
"expected_result",
"collaborators_with_permission, policy_enabled, expected_result",
[
pytest.param(
f"test-branch/workflow_dispatch/collaborators-fail-enabled/{uuid4()}",
BranchWithProtection(),
RequestedCollaborator("admin", "admin"),
True,
Result.FAIL,
id="policy enabled",
),
pytest.param(
f"test-branch/workflow_dispatch/collaborators-fail-disabled/{uuid4()}",
BranchWithProtection(),
RequestedCollaborator("admin", "admin"),
False,
Result.PASS,
id="policy disabled",
),
],
indirect=["github_branch", "protected_github_branch", "collaborators_with_permission"],
indirect=["collaborators_with_permission"],
)
@pytest.mark.usefixtures("protected_github_branch", "collaborators_with_permission")
def test_collaborators(
github_branch: Branch,
github_repository_name: str,
policy_enabled: bool,
expected_result: Result,
):
@pytest.mark.usefixtures("collaborators_with_permission")
def test_collaborators(github_repository_name: str, policy_enabled: bool, expected_result: Result):
"""
arrange: given a branch that are compliant and outside collaborators with more than read
permission and whether the policy is enabled
Expand All @@ -77,37 +60,21 @@ def test_collaborators(
}

report = workflow_dispatch(
input_=WorkflowDispatchInput(
repository_name=github_repository_name,
branch_name=github_branch.name,
commit_sha=github_branch.commit.sha,
),
input_=WorkflowDispatchInput(repository_name=github_repository_name),
policy_document=policy_document,
)

assert report.result == expected_result


@pytest.mark.parametrize(
"github_branch, protected_github_branch",
[pytest.param(f"test-branch/workflow_dispatch/pass/{uuid4()}", BranchWithProtection())],
indirect=True,
)
@pytest.mark.usefixtures("protected_github_branch")
def test_pass(
github_branch: Branch, github_repository_name: str, caplog: pytest.LogCaptureFixture
):
def test_pass(github_repository_name: str, caplog: pytest.LogCaptureFixture):
"""
arrange: given a branch and repository that is compliant
act: when workflow_dispatch is called
assert: then a pass report is returned.
"""
report = workflow_dispatch(
input_=WorkflowDispatchInput(
repository_name=github_repository_name,
branch_name=github_branch.name,
commit_sha=github_branch.commit.sha,
),
input_=WorkflowDispatchInput(repository_name=github_repository_name),
)

assert report.result == Result.PASS
Expand Down

0 comments on commit 1738dc9

Please sign in to comment.