def test_call_async_gives_up(self): calls = self.mock_urlfetch([{ 'url': 'http://example.com', 'payload': 'blah', 'method': 'POST', 'headers': { 'A': 'a' }, 'response': (500, { 'error': 'zzz' }), } for _ in xrange(0, 4)]) with self.assertRaises(service_account.AccessTokenError) as err: service_account._call_async(url='http://example.com', payload='blah', method='POST', headers={ 'A': 'a' }).get_result() self.assertTrue(err.exception.transient) self.assertFalse(calls)
def test_call_async_not_json(self): calls = self.mock_urlfetch([ { 'url': 'http://example.com', 'payload': 'blah', 'method': 'POST', 'headers': { 'A': 'a' }, 'response': MockedResponse(200, 'not a json'), }, ]) with self.assertRaises(service_account.AccessTokenError) as err: service_account._call_async(url='http://example.com', payload='blah', method='POST', headers={ 'A': 'a' }).get_result() self.assertFalse(err.exception.transient) self.assertFalse(calls)
def test_call_async_transient_error(self): calls = self.mock_urlfetch([ { 'url': 'http://example.com', 'payload': 'blah', 'method': 'POST', 'headers': { 'A': 'a' }, 'response': (500, { 'error': 'zzz' }), }, { 'url': 'http://example.com', 'payload': 'blah', 'method': 'POST', 'headers': { 'A': 'a' }, 'response': urlfetch.Error('blah'), }, { 'url': 'http://example.com', 'payload': 'blah', 'method': 'POST', 'headers': { 'A': 'a' }, 'response': (200, { 'abc': 'def' }), }, ]) response = service_account._call_async(url='http://example.com', payload='blah', method='POST', headers={ 'A': 'a' }).get_result() self.assertEqual({'abc': 'def'}, response) self.assertFalse(calls)