1
1
"""Config file for extending pytest functionality to packages w/o native support."""
2
2
from pytest import fixture
3
+ from moto import mock_dynamodb
3
4
from os import environ
4
5
5
6
@@ -12,17 +13,54 @@ def mock_logs():
12
13
yield capture
13
14
14
15
15
- @fixture (scope = 'function ' )
16
- def aws_credentials ():
16
+ @fixture (scope = 'session ' )
17
+ def mock_aws_credentials ():
17
18
"""Mocked AWS Credentials for moto."""
18
19
environ ['AWS_ACCESS_KEY_ID' ] = 'testing'
19
20
environ ['AWS_SECRET_ACCESS_KEY' ] = 'testing'
20
21
environ ['AWS_SECURITY_TOKEN' ] = 'testing'
21
22
environ ['AWS_SESSION_TOKEN' ] = 'testing'
22
- environ ['AWS_REGION' ] = 'us-west-1'
23
+ # environ['AWS_REGION'] = 'us-west-1'
23
24
24
25
25
- @fixture (scope = 'function' )
26
- def dynamodb (aws_credentials ):
26
+ @fixture (scope = 'class' )
27
+ def mock_recipe (mock_aws_credentials ):
28
+ """Fixture for mocking a local dynamodb instance w/test credentials."""
29
+ with mock_dynamodb ():
30
+ # TODO: Figure out how to set test-config params for the pynamodb models
31
+ from backend .models import Recipe
32
+
33
+ # Recipe.Meta.host = 'http://localhost:8009'
34
+ Recipe .Meta .table_name = 'MockRecipe'
35
+ Recipe .Meta .aws_access_key_id = 'testing2'
36
+ Recipe .Meta .aws_secret_access_key = 'testing2'
37
+ Recipe .Meta .aws_session_token = 'testing2'
38
+ Recipe .Meta .aws_security_token = 'testing2'
39
+
40
+ Recipe .create_table (read_capacity_units = 5 , write_capacity_units = 5 )
41
+ print (f"new recipe count ======> { Recipe .count ()} " )
42
+
43
+ yield Recipe
44
+
45
+ # Teardown
46
+ Recipe .delete_table ()
47
+
48
+
49
+ @fixture (scope = 'class' )
50
+ def mock_replacement (mock_aws_credentials ):
27
51
"""Fixture for mocking a local dynamodb instance w/test credentials."""
28
- pass
52
+ with mock_dynamodb ():
53
+ from backend .models import Replacement
54
+
55
+ # Replacement.Meta.host = 'http://localhost:8009'
56
+ Replacement .Meta .table_name = 'MockReplacement'
57
+ Replacement .Meta .aws_access_key_id = 'testing3'
58
+ Replacement .Meta .aws_secret_access_key = 'testing3'
59
+ Replacement .Meta .aws_session_token = 'testing3'
60
+ Replacement .Meta .aws_security_token = 'testing3'
61
+ Replacement .create_table (read_capacity_units = 5 , write_capacity_units = 5 )
62
+
63
+ yield Replacement
64
+
65
+ # Teardown
66
+ Replacement .delete_table ()
0 commit comments