-
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.
Consolidate unit test S3 mocking (#52)
* Consolidate unit test S3 mocking * isolated conftest scope * remove unintended file * disabled autouse, reset test structure * typo * re-remove WIP file
- Loading branch information
1 parent
2f68ff2
commit bec4a93
Showing
11 changed files
with
274 additions
and
282 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
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
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,52 @@ | ||
import boto3 | ||
import json | ||
import os | ||
|
||
import pytest | ||
from moto import mock_s3, mock_athena | ||
from unittest import mock | ||
|
||
from src.handlers.shared.enums import BucketPath | ||
from src.handlers.shared.functions import read_metadata, write_metadata | ||
from tests.utils import get_mock_metadata, get_mock_auth, TEST_BUCKET, ITEM_COUNT | ||
|
||
|
||
def _init_mock_data(s3_client, bucket_name, site, study, subscription): | ||
s3_client.upload_file( | ||
"./tests/test_data/cube_simple_example.parquet", | ||
bucket_name, | ||
f"{BucketPath.AGGREGATE.value}/{site}/{study}/" | ||
f"{site}__{subscription}/{site}__{subscription}__aggregate.parquet", | ||
) | ||
s3_client.upload_file( | ||
"./tests/test_data/cube_simple_example.csv", | ||
bucket_name, | ||
f"{BucketPath.CSVAGGREGATE.value}/{site}/{study}/" | ||
f"{site}__{subscription}/{site}__{subscription}__aggregate.csv", | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def mock_bucket(): | ||
"""Mock for testing S3 usage. Should reset before each individual test.""" | ||
s3 = mock_s3() | ||
s3.start() | ||
s3_client = boto3.client("s3", region_name="us-east-1") | ||
s3_client.create_bucket(Bucket=TEST_BUCKET) | ||
aggregate_params = [ | ||
["general_hospital", "covid", "encounter"], | ||
["general_hospital", "lyme", "encounter"], | ||
["st_elsewhere", "covid", "encounter"], | ||
] | ||
for param_list in aggregate_params: | ||
_init_mock_data(s3_client, TEST_BUCKET, *param_list) | ||
metadata = get_mock_metadata() | ||
write_metadata(s3_client, TEST_BUCKET, metadata) | ||
yield | ||
s3.stop() | ||
|
||
|
||
def test_mock_bucket(): | ||
s3_client = boto3.client("s3", region_name="us-east-1") | ||
item = s3_client.list_objects_v2(Bucket=TEST_BUCKET) | ||
assert (len(item["Contents"])) == ITEM_COUNT |
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
Oops, something went wrong.