diff --git a/.github/workflows/python_lint_test.yml b/.github/workflows/python_lint_test.yml index f320e2a..a83a726 100644 --- a/.github/workflows/python_lint_test.yml +++ b/.github/workflows/python_lint_test.yml @@ -32,5 +32,14 @@ jobs: black reusable_workflows/ flake8 reusable_workflows/ + - name: Create GitHub App Token + uses: actions/create-github-app-token@v1 + id: app-token + with: + app-id: ${{ vars.CLA_BOT_APP_ID }} + private-key: ${{ secrets.CLA_BOT_PRIVATE_KEY }} + - name: Run all tests - run: pytest --runslow reusable_workflows/ + run: pytest --integration-tests reusable_workflows/ + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} diff --git a/.gitignore b/.gitignore index 700939f..93b46df 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ sorting/target **/__pycache__ .env/** +.venv/** diff --git a/reusable_workflows/tests/conftest.py b/reusable_workflows/tests/conftest.py index e446d0a..8e719e8 100644 --- a/reusable_workflows/tests/conftest.py +++ b/reusable_workflows/tests/conftest.py @@ -3,19 +3,19 @@ def pytest_addoption(parser): parser.addoption( - "--runslow", action="store_true", default=False, help="run slow tests" + "--integration-tests", action="store_true", default=False, help="run integration tests" ) def pytest_configure(config): - config.addinivalue_line("markers", "slow: mark test as slow to run") + config.addinivalue_line("markers", "integration: mark test as integration test") def pytest_collection_modifyitems(config, items): - if config.getoption("--runslow"): - # --runslow given in cli: do not skip slow tests + if config.getoption("--integration-tests"): + # --integration-tests given in cli: do not skip integration tests return - skip_slow = pytest.mark.skip(reason="need --runslow option to run") + skip_integration = pytest.mark.skip(reason="need --integration-tests option to run") for item in items: - if "slow" in item.keywords: - item.add_marker(skip_slow) + if "integration" in item.keywords: + item.add_marker(skip_integration) diff --git a/reusable_workflows/tests/test_check_external_contrib.py b/reusable_workflows/tests/test_check_external_contrib.py index 4d44ce8..296720f 100644 --- a/reusable_workflows/tests/test_check_external_contrib.py +++ b/reusable_workflows/tests/test_check_external_contrib.py @@ -1,6 +1,7 @@ import os from unittest import mock +import github3 import pytest from check_membership.check_external_contrib import ( @@ -53,3 +54,9 @@ def test_github_token_not_passed_in(github_login_mock): assert ( str(exc.value) == "github login failed - maybe GH_TOKEN was not correctly set" ) + +@pytest.mark.integration +def test_check_repos_open_to_contributions_accessible(): + gh = github3.login(token=os.getenv("GH_TOKEN")) + + get_repos_open_to_contributions(gh) diff --git a/reusable_workflows/tests/test_compliance_checks.py b/reusable_workflows/tests/test_compliance_checks.py index 3cbeb98..7b9cd16 100644 --- a/reusable_workflows/tests/test_compliance_checks.py +++ b/reusable_workflows/tests/test_compliance_checks.py @@ -2,7 +2,9 @@ import sys from unittest import mock +import os import pytest +import github3 from github3.exceptions import NotFoundError from compliance.check_compliance.compliance_checks import ( @@ -318,3 +320,56 @@ def test_repo_permissions_team_name_not_found(get_team_name_mock): repo_permissions_check.check(helper) assert repo_permissions_check.succeeds is False assert repo_permissions_check.message == "Raised error: Only one team can be listed for repo-level codeowners." # fmt: skip + + +def integration_test_setup() -> ComplianceCheckHelper: + gh = github3.login(token=os.getenv("GH_TOKEN")) + repo = gh.repository("dfinity", "test-compliant-repository-public") + org = gh.organization("dfinity") + helper = ComplianceCheckHelper(repo, org) + return helper + +@pytest.mark.integration +def test_get_code_owners(): + helper = integration_test_setup() + + code_owners = helper.get_code_owners() + + assert code_owners == "* @dfinity/idx\n" + +@pytest.mark.integration +def test_get_repo_permissions(): + helper = integration_test_setup() + repo_permissions = RepoPermissions() + + repo_permissions.check(helper) + + assert repo_permissions.succeeds is True + assert repo_permissions.message == "Team idx has maintain permissions." + +@pytest.mark.integration +def test_branch_protection(): + helper = integration_test_setup() + branch_protection = BranchProtection() + + branch_protection.check(helper) + + assert branch_protection.succeeds is True + +@pytest.mark.integration +def test_license(): + helper = integration_test_setup() + license = License() + + license.check(helper) + + assert license.succeeds is True + +@pytest.mark.integration +def test_readme(): + helper = integration_test_setup() + readme = Readme() + + readme.check(helper) + + assert readme.succeeds is True diff --git a/reusable_workflows/tests/test_membership.py b/reusable_workflows/tests/test_membership.py index 18b1141..8632b99 100644 --- a/reusable_workflows/tests/test_membership.py +++ b/reusable_workflows/tests/test_membership.py @@ -1,6 +1,7 @@ import os from unittest import mock +import github3 from github3.exceptions import NotFoundError import pytest @@ -129,3 +130,11 @@ def test_github_token_not_passed_in(github_login_mock): assert ( str(exc.value) == "github login failed - maybe GH_TOKEN was not correctly set" ) + +@pytest.mark.integration +def test_is_member_of_org(): + gh = github3.login(token=os.getenv("GH_TOKEN")) + + is_member = is_member_of_org(gh, "dfinity", "sa-github-api") + + assert is_member is True diff --git a/reusable_workflows/tests/test_utils.py b/reusable_workflows/tests/test_utils.py index 3ae2aaf..f11283f 100644 --- a/reusable_workflows/tests/test_utils.py +++ b/reusable_workflows/tests/test_utils.py @@ -19,7 +19,7 @@ def test_download_file_succeeds_first_try(): assert repo.file_contents.call_count == 1 -@pytest.mark.slow +@pytest.mark.integration def test_download_file_succeeds_third_try(): repo = mock.MagicMock() file_content_obj = mock.Mock() @@ -35,7 +35,7 @@ def test_download_file_succeeds_third_try(): assert repo.file_contents.call_count == 3 -@pytest.mark.slow +@pytest.mark.integration @mock.patch("requests.get") def test_download_file_fails(mock_get): repo = mock.MagicMock()