def test_timeout_argument_forwarded_to_requests(self, get): first = mock.Mock() first.status_code = 200 first.content = 'foobar'.encode('utf-8') second = mock.Mock() second.status_code = 200 second.content = json.dumps(metadata['foobar']).encode('utf-8') get.side_effect = [first, second] credentials.retrieve_iam_role_credentials(timeout=10) self.assertEqual(get.call_args[1]['timeout'], 10)
def test_retry_errors(self, get): # First attempt we get a connection error. first = mock.Mock() first.side_effect = ConnectionError # Next attempt we get a response with the foobar key. second = mock.Mock() second.status_code = 200 second.content = "foobar".encode("utf-8") # Next attempt we get a response with the foobar creds. third = mock.Mock() third.status_code = 200 third.content = json.dumps(metadata["foobar"]).encode("utf-8") get.side_effect = [first, second, third] retrieved = credentials.retrieve_iam_role_credentials(num_attempts=2) self.assertEqual(retrieved["foobar"]["AccessKeyId"], "foo")
def test_request_timeout_occurs(self, get): first = mock.Mock() first.side_effect = ConnectionError d = credentials.retrieve_iam_role_credentials(timeout=10) self.assertEqual(d, {})