11"""Generic setup and teardown for ACK backend tests"""
22
3- from tests .utils .mock_environment_variables import BucketNames , Firehose , REGION_NAME
3+ from unittest .mock import patch
4+
5+ from tests .utils .mock_environment_variables import BucketNames , MOCK_ENVIRONMENT_DICT , Firehose
6+
7+ # Ensure environment variables are mocked before importing from src files
8+ with patch .dict ("os.environ" , MOCK_ENVIRONMENT_DICT ):
9+ from clients import REGION_NAME
10+ from constants import AuditTableKeys , AUDIT_TABLE_NAME , AUDIT_TABLE_QUEUE_NAME_GSI , AUDIT_TABLE_FILENAME_GSI
411
512
613class GenericSetUp :
@@ -11,7 +18,7 @@ class GenericSetUp:
1118 * If firehose_client is provided, creates a firehose delivery stream
1219 """
1320
14- def __init__ (self , s3_client = None , firehose_client = None ):
21+ def __init__ (self , s3_client = None , firehose_client = None , dynamodb_client = None ):
1522
1623 if s3_client :
1724 for bucket_name in [BucketNames .SOURCE , BucketNames .DESTINATION , BucketNames .MOCK_FIREHOSE ]:
@@ -30,11 +37,41 @@ def __init__(self, s3_client=None, firehose_client=None):
3037 },
3138 )
3239
40+ if dynamodb_client :
41+ dynamodb_client .create_table (
42+ TableName = AUDIT_TABLE_NAME ,
43+ KeySchema = [{"AttributeName" : AuditTableKeys .MESSAGE_ID , "KeyType" : "HASH" }],
44+ AttributeDefinitions = [
45+ {"AttributeName" : AuditTableKeys .MESSAGE_ID , "AttributeType" : "S" },
46+ {"AttributeName" : AuditTableKeys .FILENAME , "AttributeType" : "S" },
47+ {"AttributeName" : AuditTableKeys .QUEUE_NAME , "AttributeType" : "S" },
48+ {"AttributeName" : AuditTableKeys .STATUS , "AttributeType" : "S" },
49+ ],
50+ ProvisionedThroughput = {"ReadCapacityUnits" : 5 , "WriteCapacityUnits" : 5 },
51+ GlobalSecondaryIndexes = [
52+ {
53+ "IndexName" : AUDIT_TABLE_FILENAME_GSI ,
54+ "KeySchema" : [{"AttributeName" : AuditTableKeys .FILENAME , "KeyType" : "HASH" }],
55+ "Projection" : {"ProjectionType" : "KEYS_ONLY" },
56+ "ProvisionedThroughput" : {"ReadCapacityUnits" : 5 , "WriteCapacityUnits" : 5 },
57+ },
58+ {
59+ "IndexName" : AUDIT_TABLE_QUEUE_NAME_GSI ,
60+ "KeySchema" : [
61+ {"AttributeName" : AuditTableKeys .QUEUE_NAME , "KeyType" : "HASH" },
62+ {"AttributeName" : AuditTableKeys .STATUS , "KeyType" : "RANGE" },
63+ ],
64+ "Projection" : {"ProjectionType" : "ALL" },
65+ "ProvisionedThroughput" : {"ReadCapacityUnits" : 5 , "WriteCapacityUnits" : 5 },
66+ },
67+ ],
68+ )
69+
3370
3471class GenericTearDown :
3572 """Performs generic tear down of mock resources"""
3673
37- def __init__ (self , s3_client = None , firehose_client = None ):
74+ def __init__ (self , s3_client = None , firehose_client = None , dynamodb_client = None ):
3875
3976 if s3_client :
4077 for bucket_name in [BucketNames .SOURCE , BucketNames .DESTINATION , BucketNames .MOCK_FIREHOSE ]:
@@ -44,3 +81,6 @@ def __init__(self, s3_client=None, firehose_client=None):
4481
4582 if firehose_client :
4683 firehose_client .delete_delivery_stream (DeliveryStreamName = Firehose .STREAM_NAME )
84+
85+ if dynamodb_client :
86+ dynamodb_client .delete_table (TableName = AUDIT_TABLE_NAME )
0 commit comments