mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 18:31:13 -05:00
add migration for e2e tests and improve code coverage
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
import os
|
||||
from datetime import datetime
|
||||
from os import getenv
|
||||
|
||||
from app.aws.s3 import get_s3_file
|
||||
import pytest
|
||||
from botocore.exceptions import ClientError
|
||||
|
||||
from app.aws.s3 import file_exists, get_s3_file, remove_csv_object, remove_s3_object
|
||||
|
||||
default_access_key = getenv("CSV_AWS_ACCESS_KEY_ID")
|
||||
default_secret_key = getenv("CSV_AWS_SECRET_ACCESS_KEY")
|
||||
@@ -33,3 +37,82 @@ def test_get_s3_file_makes_correct_call(notify_api, mocker):
|
||||
default_secret_key,
|
||||
default_region,
|
||||
)
|
||||
|
||||
|
||||
def test_remove_csv_object(notify_api, mocker):
|
||||
get_s3_mock = mocker.patch("app.aws.s3.get_s3_object")
|
||||
remove_csv_object("mykey")
|
||||
|
||||
get_s3_mock.assert_called_once_with(
|
||||
os.getenv("CSV_BUCKET_NAME"),
|
||||
"mykey",
|
||||
default_access_key,
|
||||
default_secret_key,
|
||||
default_region,
|
||||
)
|
||||
|
||||
|
||||
def test_remove_csv_object_alternate(notify_api, mocker):
|
||||
get_s3_mock = mocker.patch("app.aws.s3.get_s3_object")
|
||||
remove_s3_object(
|
||||
os.getenv("CSV_BUCKET_NAME"),
|
||||
"mykey",
|
||||
default_access_key,
|
||||
default_secret_key,
|
||||
default_region,
|
||||
)
|
||||
|
||||
get_s3_mock.assert_called_once_with(
|
||||
os.getenv("CSV_BUCKET_NAME"),
|
||||
"mykey",
|
||||
default_access_key,
|
||||
default_secret_key,
|
||||
default_region,
|
||||
)
|
||||
|
||||
|
||||
def test_file_exists_true(notify_api, mocker):
|
||||
get_s3_mock = mocker.patch("app.aws.s3.get_s3_object")
|
||||
|
||||
file_exists(
|
||||
os.getenv("CSV_BUCKET_NAME"),
|
||||
"mykey",
|
||||
default_access_key,
|
||||
default_secret_key,
|
||||
default_region,
|
||||
)
|
||||
get_s3_mock.assert_called_once_with(
|
||||
os.getenv("CSV_BUCKET_NAME"),
|
||||
"mykey",
|
||||
default_access_key,
|
||||
default_secret_key,
|
||||
default_region,
|
||||
)
|
||||
|
||||
|
||||
def test_file_exists_false(notify_api, mocker):
|
||||
get_s3_mock = mocker.patch("app.aws.s3.get_s3_object")
|
||||
error_response = {
|
||||
"Error": {"Code": 500, "Message": "bogus"},
|
||||
"ResponseMetadata": {"HTTPStatusCode": 500},
|
||||
}
|
||||
get_s3_mock.side_effect = ClientError(
|
||||
error_response=error_response, operation_name="bogus"
|
||||
)
|
||||
|
||||
with pytest.raises(ClientError):
|
||||
file_exists(
|
||||
os.getenv("CSV_BUCKET_NAME"),
|
||||
"mykey",
|
||||
default_access_key,
|
||||
default_secret_key,
|
||||
default_region,
|
||||
)
|
||||
|
||||
get_s3_mock.assert_called_once_with(
|
||||
os.getenv("CSV_BUCKET_NAME"),
|
||||
"mykey",
|
||||
default_access_key,
|
||||
default_secret_key,
|
||||
default_region,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user