mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-08 07:38:26 -04:00
test that S3 not getting hit in tests
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
import botocore
|
import botocore
|
||||||
from boto3 import Session
|
from boto3 import Session
|
||||||
from botocore.config import Config
|
from botocore.config import Config
|
||||||
@@ -29,6 +31,17 @@ def get_s3_object(
|
|||||||
)
|
)
|
||||||
s3 = session.resource("s3", config=AWS_CLIENT_CONFIG)
|
s3 = session.resource("s3", config=AWS_CLIENT_CONFIG)
|
||||||
obj = s3.Object(bucket_name, filename)
|
obj = s3.Object(bucket_name, filename)
|
||||||
|
# This 'proves' that use of moto in the relevant tests in test_send.py
|
||||||
|
# mocks everything related to S3. What you will see in the logs is:
|
||||||
|
# Exception: CREATED AT <MagicMock name='resource().Bucket().creation_date' id='4665562448'>
|
||||||
|
#
|
||||||
|
# raise Exception(f"CREATED AT {_s3.Bucket(bucket_name).creation_date}")
|
||||||
|
if os.getenv("NOTIFY_ENVIRONMENT") == "test":
|
||||||
|
teststr = str(s3.Bucket(bucket_name).creation_date).lower()
|
||||||
|
if "magicmock" not in teststr:
|
||||||
|
raise Exception(
|
||||||
|
f"xxxxxtest not mocked, use @mock_aws creation date is {teststr}"
|
||||||
|
)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user