Skip to content

Commit

Permalink
New property get_template_id
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Dec 14, 2023
1 parent 6dec600 commit 875273d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lemarche/conversations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,12 @@ class Meta:

def __str__(self):
return self.name

@property
def get_template_id(self):
if self.is_active and self.source:
if self.source == conversation_constants.SOURCE_MAILJET:
return self.mailjet_id
elif self.source == conversation_constants.SOURCE_BREVO:
return self.brevo_id
return None
24 changes: 23 additions & 1 deletion lemarche/conversations/tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.test import TestCase

from lemarche.conversations import constants as conversation_constants
from lemarche.conversations.factories import ConversationFactory
from lemarche.conversations.models import Conversation
from lemarche.conversations.models import Conversation, TemplateTransactional
from lemarche.siaes.factories import SiaeFactory


Expand Down Expand Up @@ -64,3 +65,24 @@ def test_with_answer_stats(self):
conversation_queryset = Conversation.objects.with_answer_stats()
self.assertEqual(conversation_queryset.get(id=self.conversation.id).answer_count_annotated, 0)
self.assertEqual(conversation_queryset.get(id=self.conversation_with_answer.id).answer_count_annotated, 1)


class TemplateTransactionalModelTest(TestCase):
@classmethod
def setUpTestData(cls):
cls.tt_inactive = TemplateTransactional(
mailjet_id=10, brevo_id=11, source=conversation_constants.SOURCE_MAILJET, is_active=False
)
cls.tt_active_empty = TemplateTransactional(source=conversation_constants.SOURCE_MAILJET, is_active=False)
cls.tt_active_mailjet = TemplateTransactional(
mailjet_id=30, brevo_id=31, source=conversation_constants.SOURCE_MAILJET, is_active=True
)
cls.tt_active_brevo = TemplateTransactional(
mailjet_id=40, brevo_id=41, source=conversation_constants.SOURCE_BREVO, is_active=True
)

def test_get_template_id(self):
self.assertIsNone(self.tt_inactive.get_template_id)
self.assertIsNone(self.tt_active_empty.get_template_id)
self.assertEqual(self.tt_active_mailjet.get_template_id, self.tt_active_mailjet.mailjet_id)
self.assertEqual(self.tt_active_brevo.get_template_id, self.tt_active_mailjet.brevo_id)

0 comments on commit 875273d

Please sign in to comment.