Skip to content

Commit

Permalink
test: fix access to s3 container url during tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Nov 30, 2024
1 parent 4374938 commit b78e2aa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/backend/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -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}"
Expand Down
10 changes: 4 additions & 6 deletions src/backend/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2022, 2023 Humanitarian OpenStreetMap Team
# Copyright (c) Humanitarian OpenStreetMap Team
#
# This file is part of FMTM.
#
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down
11 changes: 4 additions & 7 deletions src/backend/tests/test_projects_routes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2022, 2023 Humanitarian OpenStreetMap Team
# Copyright (c) Humanitarian OpenStreetMap Team
#
# This file is part of FMTM.
#
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b78e2aa

Please sign in to comment.