diff --git a/src/backend/app/config.py b/src/backend/app/config.py index f4c895cb6c..fc941b7fdf 100644 --- a/src/backend/app/config.py +++ b/src/backend/app/config.py @@ -174,7 +174,7 @@ def assemble_cors_origins( # Handle localhost/testing scenario domain = info.data.get("FMTM_DOMAIN", "fmtm.localhost") - dev_port = info.data.get("FMTM_DEV_PORT", "") + dev_port = info.data.get("FMTM_DEV_PORT") # NOTE fmtm.dev.test is used as the Playwright test domain if "localhost" in domain or "fmtm.dev.test" in domain: local_server_port = ( @@ -268,6 +268,7 @@ def configure_s3_download_root(cls, v: Optional[str], info: ValidationInfo) -> s else: fmtm_domain = info.data.get("FMTM_DOMAIN") # Local dev + # NOTE for automated tests, this is overridden manually if info.data.get("DEBUG"): dev_port = info.data.get("FMTM_DEV_PORT") return f"http://s3.{fmtm_domain}:{dev_port}" diff --git a/src/backend/tests/conftest.py b/src/backend/tests/conftest.py index 391fa1affb..71866da535 100644 --- a/src/backend/tests/conftest.py +++ b/src/backend/tests/conftest.py @@ -1,4 +1,4 @@ -# Copyright (c) 2022, 2023 Humanitarian OpenStreetMap Team +# Copyright (c) Humanitarian OpenStreetMap Team # # This file is part of FMTM. # @@ -23,6 +23,7 @@ from io import BytesIO from pathlib import Path from typing import Any, AsyncGenerator +from urllib.parse import urlparse from uuid import uuid4 import pytest @@ -248,11 +249,8 @@ async def odk_project(db, client, project, tasks): data_extracts, ) - internal_file_path = ( - f"{settings.S3_ENDPOINT}" - f"{data_extract_s3_path.split(settings.FMTM_DEV_PORT)[1]}" - ) - response = requests.head(internal_file_path, allow_redirects=True) + internal_s3_url = f"{settings.S3_ENDPOINT}{urlparse(data_extract_s3_path).path}" + response = requests.head(internal_s3_url, allow_redirects=True) assert response.status_code < 400 xlsform_file = Path(f"{test_data_path}/buildings.xls") diff --git a/src/backend/tests/test_projects_routes.py b/src/backend/tests/test_projects_routes.py index 9c836477ce..f53a8c26ea 100644 --- a/src/backend/tests/test_projects_routes.py +++ b/src/backend/tests/test_projects_routes.py @@ -1,4 +1,4 @@ -# Copyright (c) 2022, 2023 Humanitarian OpenStreetMap Team +# Copyright (c) Humanitarian OpenStreetMap Team # # This file is part of FMTM. # @@ -22,6 +22,7 @@ from io import BytesIO from pathlib import Path from unittest.mock import Mock, patch +from urllib.parse import urlparse from uuid import uuid4 import pytest @@ -359,12 +360,8 @@ async def test_generate_project_files(db, client, project): data_extracts, ) assert data_extract_s3_path is not None - # Test url, but first sub localhost url with docker network for backend connection - internal_file_path = ( - f"{settings.S3_ENDPOINT}" - f"{data_extract_s3_path.split(settings.FMTM_DEV_PORT)[1]}" - ) - response = requests.head(internal_file_path, allow_redirects=True) + internal_s3_url = f"{settings.S3_ENDPOINT}{urlparse(data_extract_s3_path).path}" + response = requests.head(internal_s3_url, allow_redirects=True) assert response.status_code < 400 # Get custom XLSForm path