diff --git a/django_yubin/engine.py b/django_yubin/engine.py index 473f130..e36a2fe 100644 --- a/django_yubin/engine.py +++ b/django_yubin/engine.py @@ -28,11 +28,14 @@ def send_db_message(message_pk, log_message=None): logger.exception(msg, extra={'message_pk': message_pk}) return False - if not message.can_be_enqueued(): - msg = "Message can not be enqueued in it's current status." - logger.warning(msg) - message.add_log(msg) - return False + # Messages in STATUS_QUEUED can be sent to keep compatibility with previous yubin version. + # In future versions that condition can be removed and only check `can_be_enqueued()`. + if message.status != models.Message.STATUS_QUEUED: + if not message.can_be_enqueued(): + msg = "Message can not be enqueued in it's current status." + logger.warning(msg) + message.add_log(msg) + return False message.mark_as(models.Message.STATUS_QUEUED, log_message) message.mark_as(models.Message.STATUS_IN_PROCESS, "Trying to send the message.") diff --git a/tests/tests/test_engine.py b/tests/tests/test_engine.py index 2755bd0..700a06b 100644 --- a/tests/tests/test_engine.py +++ b/tests/tests/test_engine.py @@ -20,10 +20,20 @@ def test_send_email_not_found(self): self.assertFalse(send_db_message(-1)) def test_send_email_not_queueable(self): - self.message.status = Message.STATUS_SENT + self.message.status = Message.STATUS_IN_PROCESS self.message.save() self.assertFalse(send_db_message(self.message.pk)) + last_log_action = self.message.log_set.first().action + self.assertEqual(last_log_action, Message.STATUS_IN_PROCESS) + + def test_send_email_queued(self): + # Messages in STATUS_QUEUED can be sent to keep compatibility with previous yubin version. + # In future versions that condition can be removed with this test. + self.message.status = Message.STATUS_QUEUED + self.message.save() + self.assertTrue(send_db_message(self.message.pk)) + last_log_action = self.message.log_set.first().action self.assertEqual(last_log_action, Message.STATUS_SENT) diff --git a/tests/tests/test_models.py b/tests/tests/test_models.py index 7ac7e0e..b3ebbfc 100644 --- a/tests/tests/test_models.py +++ b/tests/tests/test_models.py @@ -52,7 +52,7 @@ def test_mark_as_queued(self): self.assertEqual(self.message.enqueued_count, enqueued_count+1) def test_enqueue_wrong_status(self): - self.message.mark_as(Message.STATUS_QUEUED) + self.message.mark_as(Message.STATUS_IN_PROCESS) self.assertFalse(self.message.enqueue()) def test_enqueue_exception(self):