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_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 range(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 queue_digests(some_users): generate_and_send_digests.delay( some_users, from_datetime, to_datetime, language=settings.LANGUAGE_CODE )
def test_generate_and_send_digests_retry_cs(self): """ """ with patch('notifier.tasks.generate_digest_content', side_effect=CommentsServiceException( 'timed out')) as mock_cs_call: # 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 try: generate_and_send_digests.delay( [usern(n) for n in xrange(2, 11)], datetime.datetime.now(), datetime.datetime.now()) except CommentsServiceException as e: self.assertEqual(mock_cs_call.call_count, expected_num_tries) else: # should have raised self.fail('task did not retry twice before giving up')
def test_generate_and_send_digests_retry_cs(self): """ """ with patch( 'notifier.tasks.generate_digest_content', side_effect=CommentsServiceException('timed out') ) as mock_cs_call: # 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 try: generate_and_send_digests.delay( [usern(n) for n in range(2, 11)], datetime.datetime.now(), datetime.datetime.now()) except CommentsServiceException as e: self.assertEqual(mock_cs_call.call_count, expected_num_tries) else: # should have raised self.fail('task did not retry twice before giving up')
def test_generate_and_send_digests_rewrite_recipient(self): """ """ data = json.load( open(join(dirname(__file__), 'cs_notifications.result.json'))) with patch('notifier.tasks.generate_digest_content', return_value=Parser.parse(data)) as p: # execute task task_result = generate_and_send_digests.delay( (usern(n) for n in xrange(2, 11)), datetime.datetime.now(), datetime.datetime.now()) self.assertTrue(task_result.successful()) # all messages were sent self.assertTrue(hasattr(djmail, 'outbox')) self.assertEqual(9, len(djmail.outbox)) # all messages' email addresses were rewritten for message in djmail.outbox: self.assertEqual(message.to, ['*****@*****.**'])
def test_generate_and_send_digests(self): """ """ data = json.load( open(join(dirname(__file__), 'cs_notifications.result.json'))) user_id, digest = Parser.parse(data).next() user = usern(10) with patch('notifier.tasks.generate_digest_content', return_value=[(user_id, digest)]) as p: # execute task task_result = generate_and_send_digests.delay( [user], datetime.datetime.now(), datetime.datetime.now()) self.assertTrue(task_result.successful()) # message was sent self.assertTrue(hasattr(djmail, 'outbox')) self.assertEqual(1, len(djmail.outbox)) # message has expected to, from, subj, and content self._check_message(user, digest, djmail.outbox[0])
def test_generate_and_send_digests_rewrite_recipient(self): """ """ data = json.load( open(join(dirname(__file__), 'cs_notifications.result.json'))) with patch( 'notifier.tasks.generate_digest_content', return_value=self._process_cs_response_with_user_info(data)): # execute task task_result = generate_and_send_digests.delay( (usern(n) for n in xrange(2, 11)), datetime.datetime.now(), datetime.datetime.now()) self.assertTrue(task_result.successful()) # all messages were sent self.assertTrue(hasattr(djmail, 'outbox')) self.assertEqual(9, len(djmail.outbox)) # all messages' email addresses were rewritten for message in djmail.outbox: self.assertEqual(message.to, ['*****@*****.**'])
def queue_digests(some_users): generate_and_send_digests.delay( some_users, from_datetime, to_datetime)