-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/pdct 1570 add aws s3 docker image for integration tests (#254)
* Add localstack * Create S3 bucket in localstack and use in integration tests * Update .env.example * Remove unnecessary stuff * Fix unit tests * Update docker-compose.yml * WIP * WIP * Remove unnecessary logic * Update patch version * Fix unit tests * Add cleanup fixture that deletes files saved to s3 during integration tests * Update env example * Move init-s3 to the tests directory * Replace hard coded values with env variables and remove unnecessary code from s3 mock * Rename * Swallow exceptions if s3 cleanup has error * Add error handling * Point localstack to env file
- Loading branch information
Showing
12 changed files
with
154 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
# DB | ||
POSTGRES_USER=navigator | ||
POSTGRES_PASSWORD=password | ||
ADMIN_POSTGRES_HOST=admin_backend_db | ||
ADMIN_POSTGRES_HOST=admin_backend_db # for running tests outside docker this needs to be localhost | ||
PGUSER=navigator | ||
PGPASSWORD=password | ||
PGHOST=admin_backend_db | ||
PGHOST=admin_backend_db # for running tests outside docker this needs to be localhost | ||
|
||
# API | ||
SECRET_KEY=secret_test_key | ||
API_HOST=http://navigator-admin-backend:8888 | ||
|
||
# AWS | ||
BULK_IMPORT_BUCKET=skip | ||
BULK_IMPORT_BUCKET=bulk-import-bucket | ||
AWS_ACCESS_KEY_ID=test | ||
_AWS_SECRET_ACCESS_KEY=test | ||
AWS_SECRET_ACCESS_KEY=test | ||
AWS_ENDPOINT_URL=http://localstack:4566 # for running tests outside docker this needs to be http://localhost:4566 | ||
|
||
# Slack Notifications | ||
SLACK_WEBHOOK_URL=skip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,6 +108,7 @@ celerybeat.pid | |
|
||
# Environments | ||
.env | ||
.env.local | ||
.venv | ||
env/ | ||
venv/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "admin_backend" | ||
version = "2.17.16" | ||
version = "2.17.17" | ||
description = "" | ||
authors = ["CPR-dev-team <[email protected]>"] | ||
packages = [{ include = "app" }, { include = "tests" }] | ||
|
@@ -54,7 +54,7 @@ env_files = """ | |
.env.test | ||
.env | ||
""" | ||
markers = ["unit"] | ||
markers = ["unit", "s3"] | ||
asyncio_mode = "strict" | ||
|
||
[tool.pydocstyle] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import logging | ||
import os | ||
|
||
import boto3 | ||
from botocore.exceptions import BotoCoreError, ClientError | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
_LOGGER.setLevel(logging.DEBUG) | ||
|
||
|
||
def create_s3_bucket() -> None: | ||
""" | ||
Create an S3 bucket using environment variables for configuration. | ||
Raises: | ||
AssertionError: If a required environment variable is missing. | ||
BotoCoreError, ClientError: If there's an error with boto3 operation. | ||
""" | ||
required_vars = [ | ||
"AWS_ENDPOINT_URL", | ||
"AWS_ACCESS_KEY_ID", | ||
"AWS_SECRET_ACCESS_KEY", | ||
"BULK_IMPORT_BUCKET", | ||
] | ||
missing_vars = [var for var in required_vars if var not in os.environ] | ||
assert ( | ||
not missing_vars | ||
), f"🔥 Required environment variable(s) missing: {', '.join(missing_vars)}" | ||
|
||
try: | ||
s3_client = boto3.client( | ||
"s3", | ||
endpoint_url=os.environ["AWS_ENDPOINT_URL"], | ||
aws_access_key_id=os.environ["AWS_ACCESS_KEY_ID"], | ||
aws_secret_access_key=os.environ["AWS_SECRET_ACCESS_KEY"], | ||
) | ||
|
||
s3_client.create_bucket(Bucket=os.environ["BULK_IMPORT_BUCKET"]) | ||
|
||
_LOGGER.info("🎉 Bucket created successfully") | ||
|
||
except (BotoCoreError, ClientError) as e: | ||
_LOGGER.error(f"🔥 Error: {e}") | ||
|
||
|
||
create_s3_bucket() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.