From 9fb9d82c6d6070960a5f45c2fb2eb6eba205c9d7 Mon Sep 17 00:00:00 2001 From: Dan Fuchs Date: Wed, 17 Jul 2024 16:48:10 -0500 Subject: [PATCH 1/2] Test support constant for data directory --- tests/handlers/github_ci_app_test.py | 5 ++--- tests/handlers/github_refresh_app_test.py | 5 ++--- tests/support/constants.py | 5 +++++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/handlers/github_ci_app_test.py b/tests/handlers/github_ci_app_test.py index 5ef67aa0..809268c3 100644 --- a/tests/handlers/github_ci_app_test.py +++ b/tests/handlers/github_ci_app_test.py @@ -3,7 +3,6 @@ import hashlib import hmac from dataclasses import dataclass -from pathlib import Path from string import Template import pytest @@ -13,7 +12,7 @@ from mobu.services.github_ci.ci_manager import CiManager -from ..support.constants import TEST_GITHUB_CI_APP_SECRET +from ..support.constants import TEST_DATA_DIR, TEST_GITHUB_CI_APP_SECRET from ..support.gafaelfawr import mock_gafaelfawr @@ -33,7 +32,7 @@ def webhook_request( with_prs: bool = True, ) -> GitHubRequest: """Build a GitHub webhook request and headers with the right hash.""" - data_path = Path(__file__).parent.parent / "data" / "github_webhooks" + data_path = TEST_DATA_DIR / "github_webhooks" suffix = "_no_prs" if not with_prs else "" template = (data_path / f"{event}_{action}{suffix}.tmpl.json").read_text() payload = Template(template).substitute( diff --git a/tests/handlers/github_refresh_app_test.py b/tests/handlers/github_refresh_app_test.py index d2619291..09bac988 100644 --- a/tests/handlers/github_refresh_app_test.py +++ b/tests/handlers/github_refresh_app_test.py @@ -3,7 +3,6 @@ import hashlib import hmac from dataclasses import dataclass -from pathlib import Path from string import Template import pytest @@ -11,7 +10,7 @@ from httpx import AsyncClient from pytest_mock import MockerFixture -from ..support.constants import TEST_GITHUB_REFRESH_APP_SECRET +from ..support.constants import TEST_DATA_DIR, TEST_GITHUB_REFRESH_APP_SECRET from ..support.gafaelfawr import mock_gafaelfawr @@ -23,7 +22,7 @@ class GithubRequest: def webhook_request(org: str, repo: str, ref: str) -> GithubRequest: """Build a Github webhook request and headers with the right hash.""" - data_path = Path(__file__).parent.parent / "data" / "github_webhooks" + data_path = TEST_DATA_DIR / "github_webhooks" template = (data_path / "push.tmpl.json").read_text() payload = Template(template).substitute(org=org, repo=repo, ref=ref) diff --git a/tests/support/constants.py b/tests/support/constants.py index d93b18b1..1fddc874 100644 --- a/tests/support/constants.py +++ b/tests/support/constants.py @@ -1,8 +1,13 @@ """Constants used in text fixtures and setup.""" +from pathlib import Path + TEST_BASE_URL = "https://example.com" """Base URL used for the test `httpx.AsyncClient`.""" +TEST_DATA_DIR = Path(__file__).parent.parent / "data" +"""Directory that contains test data.""" + TEST_GITHUB_REFRESH_APP_SECRET = "some-webhook-secret" """Webhook secret used for hashing test github refresh app webhook payloads.""" From d736875744712eb24f0233f87c8240530e715bd1 Mon Sep 17 00:00:00 2001 From: Dan Fuchs Date: Wed, 17 Jul 2024 16:49:14 -0500 Subject: [PATCH 2/2] Move test notebooks into data dir --- tests/business/notebookrunner_test.py | 11 ++++++----- tests/{ => data}/notebooks/test-notebook.ipynb | 0 tests/{ => data}/notebooks_recursive/data-file | 0 tests/{ => data}/notebooks_recursive/exception.ipynb | 0 .../some-dir/test-some-dir-notebook.ipynb | 0 .../double-nested-dir/test-double-nested-dir.ipynb | 0 .../some-other-dir/test-some-other-dir.ipynb | 0 .../notebooks_recursive/test-notebook.ipynb | 0 8 files changed, 6 insertions(+), 5 deletions(-) rename tests/{ => data}/notebooks/test-notebook.ipynb (100%) rename tests/{ => data}/notebooks_recursive/data-file (100%) rename tests/{ => data}/notebooks_recursive/exception.ipynb (100%) rename tests/{ => data}/notebooks_recursive/some-dir/test-some-dir-notebook.ipynb (100%) rename tests/{ => data}/notebooks_recursive/some-other-dir/nested-dir/double-nested-dir/test-double-nested-dir.ipynb (100%) rename tests/{ => data}/notebooks_recursive/some-other-dir/test-some-other-dir.ipynb (100%) rename tests/{ => data}/notebooks_recursive/test-notebook.ipynb (100%) diff --git a/tests/business/notebookrunner_test.py b/tests/business/notebookrunner_test.py index 6fcbd778..52c2484b 100644 --- a/tests/business/notebookrunner_test.py +++ b/tests/business/notebookrunner_test.py @@ -14,6 +14,7 @@ from mobu.storage.git import Git +from ..support.constants import TEST_DATA_DIR from ..support.gafaelfawr import mock_gafaelfawr from ..support.jupyter import MockJupyter from ..support.util import wait_for_business, wait_for_log_message @@ -39,7 +40,7 @@ async def test_run( cwd = Path.cwd() # Set up a notebook repository. - source_path = Path(__file__).parent.parent / "notebooks" + source_path = TEST_DATA_DIR / "notebooks" repo_path = tmp_path / "notebooks" shutil.copytree(str(source_path), str(repo_path)) @@ -119,7 +120,7 @@ async def test_run_recursive( cwd = Path.cwd() # Set up a notebook repository. - source_path = Path(__file__).parent.parent / "notebooks_recursive" + source_path = TEST_DATA_DIR / "notebooks_recursive" repo_path = tmp_path / "notebooks" shutil.copytree(str(source_path), str(repo_path)) @@ -219,7 +220,7 @@ async def test_refresh( cwd = Path.cwd() # Set up a notebook repository. - source_path = Path(__file__).parent.parent / "notebooks" + source_path = TEST_DATA_DIR / "notebooks" repo_path = tmp_path / "notebooks" shutil.copytree(str(source_path), str(repo_path)) @@ -297,7 +298,7 @@ async def test_exclude_dirs( cwd = Path.cwd() # Set up a notebook repository. - source_path = Path(__file__).parent.parent / "notebooks_recursive" + source_path = TEST_DATA_DIR / "notebooks_recursive" repo_path = tmp_path / "notebooks" shutil.copytree(str(source_path), str(repo_path)) @@ -396,7 +397,7 @@ async def test_alert( mock_gafaelfawr(respx_mock) # Set up a notebook repository with the exception notebook. - source_path = Path(__file__).parent.parent / "notebooks_recursive" + source_path = TEST_DATA_DIR / "notebooks_recursive" repo_path = tmp_path / "notebooks" repo_path.mkdir() shutil.copy(str(source_path / "exception.ipynb"), str(repo_path)) diff --git a/tests/notebooks/test-notebook.ipynb b/tests/data/notebooks/test-notebook.ipynb similarity index 100% rename from tests/notebooks/test-notebook.ipynb rename to tests/data/notebooks/test-notebook.ipynb diff --git a/tests/notebooks_recursive/data-file b/tests/data/notebooks_recursive/data-file similarity index 100% rename from tests/notebooks_recursive/data-file rename to tests/data/notebooks_recursive/data-file diff --git a/tests/notebooks_recursive/exception.ipynb b/tests/data/notebooks_recursive/exception.ipynb similarity index 100% rename from tests/notebooks_recursive/exception.ipynb rename to tests/data/notebooks_recursive/exception.ipynb diff --git a/tests/notebooks_recursive/some-dir/test-some-dir-notebook.ipynb b/tests/data/notebooks_recursive/some-dir/test-some-dir-notebook.ipynb similarity index 100% rename from tests/notebooks_recursive/some-dir/test-some-dir-notebook.ipynb rename to tests/data/notebooks_recursive/some-dir/test-some-dir-notebook.ipynb diff --git a/tests/notebooks_recursive/some-other-dir/nested-dir/double-nested-dir/test-double-nested-dir.ipynb b/tests/data/notebooks_recursive/some-other-dir/nested-dir/double-nested-dir/test-double-nested-dir.ipynb similarity index 100% rename from tests/notebooks_recursive/some-other-dir/nested-dir/double-nested-dir/test-double-nested-dir.ipynb rename to tests/data/notebooks_recursive/some-other-dir/nested-dir/double-nested-dir/test-double-nested-dir.ipynb diff --git a/tests/notebooks_recursive/some-other-dir/test-some-other-dir.ipynb b/tests/data/notebooks_recursive/some-other-dir/test-some-other-dir.ipynb similarity index 100% rename from tests/notebooks_recursive/some-other-dir/test-some-other-dir.ipynb rename to tests/data/notebooks_recursive/some-other-dir/test-some-other-dir.ipynb diff --git a/tests/notebooks_recursive/test-notebook.ipynb b/tests/data/notebooks_recursive/test-notebook.ipynb similarity index 100% rename from tests/notebooks_recursive/test-notebook.ipynb rename to tests/data/notebooks_recursive/test-notebook.ipynb