forked from fugue/credstash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_session_test.py
78 lines (72 loc) · 2.65 KB
/
get_session_test.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import unittest
from unittest.mock import patch, MagicMock
from credstash import get_session, reset_sessions
class TestGetSession(unittest.TestCase):
def setUp(self):
reset_sessions()
@patch('boto3.Session')
def test_get_session_initial_session(self, mock_session):
mock_session.return_value = 'session1'
get_session(
aws_access_key_id='session1'
)
mock_session.assert_called_once_with(
aws_access_key_id='session1',
aws_secret_access_key=None,
aws_session_token=None,
profile_name=None
)
@patch('boto3.Session')
def test_get_session_single_last_session(self, mock_session):
mock_session.return_value = 'session1'
get_session(
aws_access_key_id='session1'
)
mock_session.assert_called_once_with(
aws_access_key_id='session1',
aws_secret_access_key=None,
aws_session_token=None,
profile_name=None
)
self.assertEqual(get_session(), 'session1')
@patch('boto3.Session')
def test_get_session_two_sessions(self, mock_session):
mock_session.side_effect = ['session1', 'session2']
get_session(
aws_access_key_id='session1'
)
mock_session.assert_called_with(
aws_access_key_id='session1',
aws_secret_access_key=None,
aws_session_token=None,
profile_name=None
)
get_session(
aws_access_key_id='session2'
)
mock_session.assert_called_with(
aws_access_key_id='session2',
aws_secret_access_key=None,
aws_session_token=None,
profile_name=None
)
self.assertEqual(get_session(), 'session2')
self.assertEqual(get_session(aws_access_key_id='session1'), 'session1')
self.assertEqual(get_session(), 'session1')
self.assertEqual(get_session(aws_access_key_id='session2'), 'session2')
self.assertEqual(get_session(), 'session2')
@patch('boto3.Session')
def test_get_session_no_params(self, mock_session):
mock_session.return_value = 'defaultsession'
self.assertEqual(get_session(), 'defaultsession')
self.assertEqual(get_session(), 'defaultsession')
mock_session.assert_called_once_with(profile_name=None)
@patch('boto3.Session')
def test_get_session_specify_profile(self, mock_session):
mock_session.return_value = 'session1'
get_session(
profile_name='profile1'
)
mock_session.assert_called_once_with(
profile_name='profile1'
)