Skip to content

Commit

Permalink
test that S3 not getting hit in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Kehl committed May 30, 2024
1 parent df032ba commit a4fc04a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/s3_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import botocore
from boto3 import Session
from botocore.config import Config
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit a4fc04a

Please sign in to comment.