def test_session(self, mSession): iSession = MockSession() account = '123456' session, account_id = utils.create_session(account_id=account, session=iSession) self.assertEqual(session, iSession) self.assertEqual(account_id, account) self.assertEqual(mSession.mock_calls, [])
def test_lookup_region(self, mSession, mUrlOpen): # only check the logic for looking up the region # test_noargs will verify the rest of the logic is still working mSession.return_value = MockSession() region = 'east' az = region + 'a' mUrlOpen.return_value.read.return_value = az.encode() session, account_id = utils.create_session(account_id='12345') self.assertEqual(session.region, region)
def test_lookup_account(self): # only check the logic for looking up the account id # test_session will verify the rest of the logic is still working iSession = MockSession() client = iSession.client('iam') client.list_users.return_value = {'Users': [{'Arn': '1:2:3:4:5:6'}]} session, account_id = utils.create_session(session=iSession) self.assertEqual(account_id, '5') calls = [mock.call.list_users(MaxItems=1)] self.assertEqual(client.mock_calls, calls)
def test_noargs(self, mSession): iSession = mSession.return_value = MockSession() account = '123456' region = 'east' session, account_id = utils.create_session(account_id=account, region=region) self.assertEqual(session, iSession) self.assertEqual(account_id, account) self.assertEqual(iSession.region, region) calls = [mock.call()] self.assertEqual(mSession.mock_calls, calls)
def test_credentials(self, mSession): iSession = mSession.return_value = MockSession() access = 'XXX' secret = 'YYY' account = '123456' region = 'east' credentials = { 'aws_access_key': access, 'aws_secret_key': secret, 'aws_account_id': account, 'aws_region': region } session, account_id = utils.create_session(credentials=credentials) self.assertEqual(session, iSession) self.assertEqual(account_id, account) self.assertEqual(iSession.region, region) call = mock.call(aws_access_key_id=access, aws_secret_access_key=secret) calls = [call] self.assertEqual(mSession.mock_calls, calls)
def test_keys(self, mSession): iSession = mSession.return_value = MockSession() access = 'XXX' secret = 'YYY' account = '123456' region = 'east' credentials = { 'aws_access_key': access, 'aws_secret_key': secret, 'aws_account_id': account, 'aws_region': region } # Note: Same as test_credentials, except passing the arguments are key word args session, account_id = utils.create_session(**credentials) self.assertEqual(session, iSession) self.assertEqual(account_id, account) self.assertEqual(iSession.region, region) call = mock.call(aws_access_key_id=access, aws_secret_access_key=secret) calls = [call] self.assertEqual(mSession.mock_calls, calls)