From 57ee4f846a7256db37987fcab1fc199b3f2581e9 Mon Sep 17 00:00:00 2001 From: Michael Huneke Date: Tue, 28 Jan 2025 12:29:31 -0500 Subject: [PATCH] Add autouse fixture, use `join` --- analytics/tests/conftest.py | 5 +++++ api/local.env | 2 ++ api/src/util/file_util.py | 2 +- .../src/api/opportunities_v1/test_opportunity_route_get.py | 3 ++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/analytics/tests/conftest.py b/analytics/tests/conftest.py index 3c696a2f6..0b967f4eb 100644 --- a/analytics/tests/conftest.py +++ b/analytics/tests/conftest.py @@ -287,6 +287,11 @@ def reset_aws_env_vars(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setenv("AWS_DEFAULT_REGION", "us-east-1") +@pytest.fixture(autouse=True) +def use_cdn(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv("CDN_URL", "http://localhost:4566") + + @pytest.fixture def mock_s3() -> boto3.resource: """Instantiate an S3 bucket resource.""" diff --git a/api/local.env b/api/local.env index 0ac1aa68f..b6fabccbf 100644 --- a/api/local.env +++ b/api/local.env @@ -150,3 +150,5 @@ DEPLOY_GITHUB_REF=main DEPLOY_GITHUB_SHA=ffaca647223e0b6e54344122eefa73401f5ec131 DEPLOY_TIMESTAMP=2024-12-02T21:25:18Z DEPLOY_WHOAMI=local-developer + +CDN_URL=http://localhost:4566 diff --git a/api/src/util/file_util.py b/api/src/util/file_util.py index 5635dae67..0c44e278f 100644 --- a/api/src/util/file_util.py +++ b/api/src/util/file_util.py @@ -179,4 +179,4 @@ def convert_s3_to_cdn_url(file_path: str, cdn_url: str) -> str: raise ValueError(f"Expected s3:// path, got: {file_path}") _, key = split_s3_url(file_path) - return f"{cdn_url.rstrip('/')}/{key}" + return join(cdn_url, key) diff --git a/api/tests/src/api/opportunities_v1/test_opportunity_route_get.py b/api/tests/src/api/opportunities_v1/test_opportunity_route_get.py index 608a99799..3d53d5d4c 100644 --- a/api/tests/src/api/opportunities_v1/test_opportunity_route_get.py +++ b/api/tests/src/api/opportunities_v1/test_opportunity_route_get.py @@ -109,8 +109,9 @@ def test_get_opportunity_with_agency_200(client, api_auth_token, enable_factory_ def test_get_opportunity_s3_endpoint_url_200( - client, api_auth_token, enable_factory_create, db_session, mock_s3_bucket + client, api_auth_token, enable_factory_create, db_session, mock_s3_bucket, monkeypatch_session ): + monkeypatch_session.delenv("CDN_URL") # Create an opportunity with a specific attachment opportunity = OpportunityFactory.create(opportunity_attachments=[]) object_name = "test_file_1.txt"