From 026e4bbd601a0299d181371faf936398372a8dcd Mon Sep 17 00:00:00 2001 From: spwoodcock Date: Sat, 30 Nov 2024 16:11:30 +0000 Subject: [PATCH] test: fix allow downloading directly from s3 container during tests --- src/backend/app/config.py | 14 +++++++++----- src/backend/tests/conftest.py | 7 ++----- src/backend/tests/test_projects_routes.py | 7 +------ 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/backend/app/config.py b/src/backend/app/config.py index f4c895cb6c..ba4a709d47 100644 --- a/src/backend/app/config.py +++ b/src/backend/app/config.py @@ -266,12 +266,16 @@ def configure_s3_download_root(cls, v: Optional[str], info: ValidationInfo) -> s # Containerised S3 else: - fmtm_domain = info.data.get("FMTM_DOMAIN") # Local dev - if info.data.get("DEBUG"): - dev_port = info.data.get("FMTM_DEV_PORT") - return f"http://s3.{fmtm_domain}:{dev_port}" - return f"https://s3.{fmtm_domain}" + dev_port = info.data.get("FMTM_DEV_PORT") + if dev_port: + # NOTE This allows us to access S3 data during manual testing + # in our web browser, from a domain like: http://s3.fmtm.localhost + return f"http://s3.{info.data.get("FMTM_DOMAIN")}:{dev_port}" + # return f"https://s3.{fmtm_domain}" + # NOTE this allows download via s3:9000 for automated tests, + # where the FMTM_DEV_PORT variable is not set + return info.data.get("S3_ENDPOINT") RAW_DATA_API_URL: HttpUrlStr = "https://api-prod.raw-data.hotosm.org/v1" RAW_DATA_API_AUTH_TOKEN: Optional[SecretStr] = None diff --git a/src/backend/tests/conftest.py b/src/backend/tests/conftest.py index 391fa1affb..3afc12fa33 100644 --- a/src/backend/tests/conftest.py +++ b/src/backend/tests/conftest.py @@ -248,11 +248,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(data_extract_s3_path, 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..8d2226ae2e 100644 --- a/src/backend/tests/test_projects_routes.py +++ b/src/backend/tests/test_projects_routes.py @@ -359,12 +359,7 @@ 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) + response = requests.head(data_extract_s3_path, allow_redirects=True) assert response.status_code < 400 # Get custom XLSForm path