def test_generate_and_send_digests_retry_ses(self): """ """ data = json.load( open(join(dirname(__file__), 'cs_notifications.result.json'))) with patch('notifier.tasks.generate_digest_content', return_value=list( self._process_cs_response_with_user_info(data))): # setting this here because override_settings doesn't seem to # work on celery task configuration decorators expected_num_tries = 1 + settings.FORUM_DIGEST_TASK_MAX_RETRIES mock_backend = Mock( name='mock_backend', send_messages=Mock(side_effect=SESMaxSendingRateExceededError( 400, 'Throttling'))) with patch('notifier.connection_wrapper.dj_get_connection', return_value=mock_backend) as p2: # execute task - should fail, retry twice and still fail, then # give up try: generate_and_send_digests.delay( [usern(n) for n in xrange(2, 11)], datetime.datetime.now(), datetime.datetime.now()) except SESMaxSendingRateExceededError as e: self.assertEqual(mock_backend.send_messages.call_count, expected_num_tries) else: # should have raised self.fail('task did not retry twice before giving up')
def test_retry_after_ses_throttling_error(self): self._test_retry_after_unlimited_retry_error( SESMaxSendingRateExceededError( 455, "Throttling: Sending rate exceeded"))