示例#1
0
 def test_send_successful_message_status(self):
     """Message object should be updated if all transmissions were sent."""
     # create 2 batches (sent, queued)
     backend, dbm, t1, t2 = self.create_trans(s1='S', s2='Q')
     send_transmissions(backend.pk, dbm.pk, t2.values_list('id', flat=True))
     dbm = Message.objects.all()[0]
     self.assertEqual('S', dbm.status)
示例#2
0
 def test_send_successful_message_status_previous_error(self):
     """Message should be marked E even if current batch sends."""
     # create 2 batches (error, queued)
     backend, dbm, t1, t2 = self.create_trans(s1='E', s2='Q')
     send_transmissions(backend.pk, dbm.pk, t2.values_list('id', flat=True))
     dbm = Message.objects.all()[0]
     self.assertEqual('E', dbm.status)
示例#3
0
 def test_send_successful_status(self):
     """Transmissions should be marked with S if no errors occured."""
     # create 2 batches (queued, queued)
     backend, dbm, t1, t2 = self.create_trans(s1='Q', s2='Q')
     send_transmissions(backend.pk, dbm.pk, t1.values_list('id', flat=True))
     status = t1.values_list('status', flat=True).distinct()[0]
     self.assertEqual('S', status)
示例#4
0
 def test_all_transmissions_set_to_E_if_backend_sending_error(self):
     error_backend = RaisesBackend(self.get_router(), 'error_backend')
     self.backends['error_backend'] = {'ENGINE': RaisesBackend}
     dbm, t1, t2 = self.create_trans(s1='Q', s2='Q', backend=error_backend.model)
     both_transmisssion_sets = list(t1.values_list('id', flat=True)) + list(t2.values_list('id', flat=True))
     with override_settings(INSTALLED_BACKENDS=self.backends):
         with self.assertRaises(MessageSendingError):
             send_transmissions(error_backend.model.pk, dbm.pk, both_transmisssion_sets)
     errored = Transmission.objects.filter(status='E')
     # all of the transmissions should have a status of 'E' now
     self.assertEqual(4, errored.count())
示例#5
0
 def test_all_transmissions_set_to_E_if_backend_sending_error(self):
     error_backend = RaisesBackend(self.get_router(), 'error_backend')
     self.backends['error_backend'] = {'ENGINE': RaisesBackend}
     dbm, t1, t2 = self.create_trans(s1='Q', s2='Q', backend=error_backend.model)
     both_transmisssion_sets = list(t1.values_list('id', flat=True)) + list(t2.values_list('id', flat=True))
     with override_settings(INSTALLED_BACKENDS=self.backends):
         with self.assertRaises(MessageSendingError):
             send_transmissions(error_backend.model.pk, dbm.pk, both_transmisssion_sets)
     errored = Transmission.objects.filter(status='E')
     # all of the transmissions should have a status of 'E' now
     self.assertEqual(4, errored.count())
示例#6
0
 def test_only_failed_transmissions_set_to_E(self):
     # FailedIdentitiesBackend will fail any messages to an identity with a '1' in it.
     # create_trans creates 4 identities, only one of which has a '1' in it, so we expect
     # one failure.
     error_backend = FailedIdentitiesBackend(self.get_router(), 'error_backend')
     self.backends['error_backend'] = {'ENGINE': FailedIdentitiesBackend}
     dbm, t1, t2 = self.create_trans(s1='Q', s2='Q', backend=error_backend.model)
     both_transmisssion_sets = list(t1.values_list('id', flat=True)) + list(t2.values_list('id', flat=True))
     with override_settings(INSTALLED_BACKENDS=self.backends):
         with self.assertRaises(MessageSendingError):
             send_transmissions(error_backend.model.pk, dbm.pk, both_transmisssion_sets)
     errored = Transmission.objects.filter(status='E')
     # only 1 of the transmissions should have a status of 'E' now
     self.assertEqual(1, errored.count())
示例#7
0
 def test_only_failed_transmissions_set_to_E(self):
     # FailedIdentitiesBackend will fail any messages to an identity with a '1' in it.
     # create_trans creates 4 identities, only one of which has a '1' in it, so we expect
     # one failure.
     error_backend = FailedIdentitiesBackend(self.get_router(), 'error_backend')
     self.backends['error_backend'] = {'ENGINE': FailedIdentitiesBackend}
     dbm, t1, t2 = self.create_trans(s1='Q', s2='Q', backend=error_backend.model)
     both_transmisssion_sets = list(t1.values_list('id', flat=True)) + list(t2.values_list('id', flat=True))
     with override_settings(INSTALLED_BACKENDS=self.backends):
         with self.assertRaises(MessageSendingError):
             send_transmissions(error_backend.model.pk, dbm.pk, both_transmisssion_sets)
     errored = Transmission.objects.filter(status='E')
     # only 1 of the transmissions should have a status of 'E' now
     self.assertEqual(1, errored.count())
示例#8
0
 def test_send_doesnt_send_already_sent_transmissions(self):
     """If a transmission has already been sent, don't resend it.
     (This may occur during a retry, when some of the messages were sent and some failed)."""
     # create 2 batches (sent, queued)
     dbm, t1, t2 = self.create_trans(s1='S', s2='Q')
     both_transmisssion_sets = list(t1.values_list('id', flat=True)) + list(
         t2.values_list('id', flat=True))
     send_transmissions(self.backend.pk, dbm.pk, both_transmisssion_sets)
     dbm = Message.objects.get()
     self.assertEqual('S', dbm.status)
     # only 2 messages should be sent, both from t2
     self.assertEqual(2, len(self.sent_messages))
     self.assertEqual(set([m.identity for m in self.sent_messages]),
                      set([t.connection.identity for t in t2]))
示例#9
0
 def test_send_doesnt_send_already_sent_transmissions(self):
     """If a transmission has already been sent, don't resend it.
     (This may occur during a retry, when some of the messages were sent and some failed)."""
     # create 2 batches (sent, queued)
     dbm, t1, t2 = self.create_trans(s1='S', s2='Q')
     both_transmisssion_sets = list(t1.values_list('id', flat=True)) + list(t2.values_list('id', flat=True))
     send_transmissions(self.backend.pk, dbm.pk, both_transmisssion_sets)
     dbm = Message.objects.get()
     self.assertEqual('S', dbm.status)
     # only 2 messages should be sent, both from t2
     self.assertEqual(2, len(self.sent_messages))
     self.assertEqual(
         set([m.identity for m in self.sent_messages]),
         set([t.connection.identity for t in t2])
     )