def test_request_retry(self): # we should retry on general errors consumer = Consumer(None, 'testsecret') self._test_request_retry(consumer, Exception('generic exception'), 2) # we should retry on server errors consumer = Consumer(None, 'testsecret') self._test_request_retry( consumer, APIError(500, 'code', 'Internal Server Error'), 2) # we should retry on HTTP 429 errors consumer = Consumer(None, 'testsecret') self._test_request_retry(consumer, APIError(429, 'code', 'Too Many Requests'), 2) # we should NOT retry on other client errors consumer = Consumer(None, 'testsecret') api_error = APIError(400, 'code', 'Client Errors') try: self._test_request_retry(consumer, api_error, 1) except APIError: pass else: self.fail('request() should not retry on client errors') # test for number of exceptions raise > retries value consumer = Consumer(None, 'testsecret', retries=3) self._test_request_retry( consumer, APIError(500, 'code', 'Internal Server Error'), 3)
def test_request_retry(self): # we should retry on general errors self._test_request_retry(Exception('generic exception'), 2) # we should retry on server errors self._test_request_retry( APIError(500, 'code', 'Internal Server Error'), 2) # we should retry on HTTP 429 errors self._test_request_retry(APIError(429, 'code', 'Too Many Requests'), 2) # we should NOT retry on other client errors api_error = APIError(400, 'code', 'Client Errors') try: self._test_request_retry(api_error, 1) except APIError: pass else: self.fail('request() should not retry on client errors') # test for number of exceptions raise > retries value self._test_request_retry( APIError(500, 'code', 'Internal Server Error'), 4)