def _test_request_retry(self, expected_exception, exception_count): def mock_post(*args, **kwargs): mock_post.call_count += 1 if mock_post.call_count <= exception_count: raise expected_exception mock_post.call_count = 0 with mock.patch('analytics.consumer.post', mock.Mock(side_effect=mock_post)): consumer = Consumer(None, 'testsecret') track = { 'type': 'track', 'event': 'python event', 'userId': 'userId' } # request() should succeed if the number of exceptions raised is less # than the retries paramater. if exception_count <= consumer.retries: consumer.request([track]) else: # if exceptions are raised more times than the retries parameter, # we expect the exception to be returned to the caller. try: consumer.request([track]) except type(expected_exception) as exc: self.assertEqual(exc, expected_exception) else: self.fail( "request() should raise an exception if still failing after %d retries" % consumer.retries)
def test_request(cls): consumer = Consumer(None, 'testsecret') track = { 'type': 'track', 'event': 'python event', 'userId': 'userId' } consumer.request([track])
def test_request(self): consumer = Consumer(None, 'testsecret') track = { 'type': 'track', 'event': 'python event', 'userId': 'userId' } consumer.request([track])
def test_proxies(cls): consumer = Consumer(None, 'testsecret', proxies='203.243.63.16:80') track = {'type': 'track', 'event': 'python event', 'userId': 'userId'} consumer.request([track])