test that S3 not getting hit in tests

This commit is contained in:
Kenneth Kehl
2024-05-30 08:25:00 -07:00
parent df032ba76d
commit a4fc04a659

View File

@@ -1,3 +1,5 @@
import os
import botocore
from boto3 import Session
from botocore.config import Config
@@ -29,6 +31,17 @@ def get_s3_object(
)
s3 = session.resource("s3", config=AWS_CLIENT_CONFIG)
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