Skip to content

Commit

Permalink
test: fix allow downloading directly from s3 container 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 026e4bb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
14 changes: 9 additions & 5 deletions src/backend/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions src/backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 1 addition & 6 deletions src/backend/tests/test_projects_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 026e4bb

Please sign in to comment.