13
13
import boto3
14
14
from boto3 import Session
15
15
from boto3 .dynamodb .conditions import Key
16
- import moto
16
+ from moto import mock_aws
17
17
18
18
# Mock the DynamoDB Service during the test
19
- @moto .mock_dynamodb
19
+ @mock_aws # Only use this decorator, remove @ moto.mock_dynamodb
20
20
class TestKinesisLambdaWithDynamoDB (TestCase ):
21
21
"""
22
22
Unit Test class for src/app.py
23
23
"""
24
+
24
25
def setUp (self ) -> None :
25
26
"""
26
27
Test Set up:
@@ -35,7 +36,7 @@ def setUp(self) -> None:
35
36
os .environ ["DYNAMODB_TABLE_NAME" ] = self .test_ddb_table_name
36
37
sam_template_table = self .read_sam_template ()["Resources" ]["DynamoDBTable" ]
37
38
sam_template_table_properties = sam_template_table ["Properties" ]
38
- self .mock_dynamodb = boto3 .Session ( region_name = "us-east-1" ) .resource ("dynamodb" )
39
+ self .mock_dynamodb = boto3 .Session .resource ("dynamodb" )
39
40
self .mock_dynamodb_table = self .mock_dynamodb .create_table (
40
41
TableName = self .test_ddb_table_name ,
41
42
KeySchema = sam_template_table_properties ["KeySchema" ],
@@ -47,7 +48,6 @@ def tearDown(self) -> None:
47
48
"""
48
49
For teardown, remove the environment variable
49
50
"""
50
-
51
51
del os .environ ['DYNAMODB_TABLE_NAME' ]
52
52
53
53
def read_sam_template (self , sam_template_fn : str = "template.yaml" ) -> dict :
@@ -64,7 +64,6 @@ def load_test_event(self, test_event_file_name: str) -> Dict[str, Any]:
64
64
Add the test isolation postfix to the path parameter {id}
65
65
"""
66
66
try :
67
-
68
67
with open (f"tests/events/{ test_event_file_name } .json" ,"r" ) as file_name :
69
68
event = json .load (file_name )
70
69
return event
0 commit comments