-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmock_boto3session.py
46 lines (35 loc) · 1.36 KB
/
mock_boto3session.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import collections
class MockedBoto3Session:
"""
Mock for `boto3.session.Session()`
but only this parts:
* session.client()
* session.client().get_secret_value()
"""
def __init__(self):
self._secrets = collections.defaultdict(dict)
self.client = self # fake this call: session.client()
def __call__(self, *args, **kwargs):
return self
##########################################################################
# methods to load mock data:
def add_secret_string(self, **kwargs):
assert kwargs
for key, value in kwargs.items():
assert isinstance(key, str)
assert isinstance(value, str)
self._secrets[key]['SecretString'] = value
def add_secret_binary(self, **kwargs):
assert kwargs
for key, value in kwargs.items():
assert isinstance(key, str)
assert isinstance(value, bytes)
self._secrets[key]['SecretBinary'] = value
##########################################################################
# replicated API from boto3.session.Session()
def get_secret_value(self, SecretId):
try:
secret_value_response = self._secrets[SecretId]
except KeyError:
raise KeyError(f'Mock value for secret {SecretId!r} missing!')
return secret_value_response