Esempio n. 1
0
    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)
Esempio n. 2
0
 def test_request(cls):
     consumer = Consumer(None, 'testsecret')
     track = {
         'type': 'track',
         'event': 'python event',
         'userId': 'userId'
     }
     consumer.request([track])
Esempio n. 3
0
 def test_request(self):
     consumer = Consumer(None, 'testsecret')
     track = {
         'type': 'track',
         'event': 'python event',
         'userId': 'userId'
     }
     consumer.request([track])
Esempio n. 4
0
 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])