Skip to content

Commit

Permalink
fix(EmailGroupFactory): call factory manualy before to prevent duplic…
Browse files Browse the repository at this point in the history
…ate key errors
  • Loading branch information
SebastienReuiller committed Dec 16, 2024
1 parent 83b5141 commit 745afd9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
22 changes: 16 additions & 6 deletions lemarche/conversations/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.utils import timezone

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

Expand Down Expand Up @@ -105,22 +105,31 @@ def test_get_template_id(self):

class TemplateTransactionalModelSaveTest(TransactionTestCase):
@classmethod
def setUpTestData(cls):
pass
def setUp(cls):
cls.email_group = EmailGroupFactory()

def test_template_transactional_field_rules(self):
self.assertRaises(IntegrityError, TemplateTransactionalFactory, source=None)
self.assertRaises(IntegrityError, TemplateTransactionalFactory, group=self.email_group, source=None)

def test_template_transactional_validation_on_save(self):
TemplateTransactionalFactory(
mailjet_id=None, brevo_id=None, source=conversation_constants.SOURCE_BREVO, is_active=False
group=self.email_group,
mailjet_id=None,
brevo_id=None,
source=conversation_constants.SOURCE_BREVO,
is_active=False,
)
TemplateTransactionalFactory(
mailjet_id=None, brevo_id=123, source=conversation_constants.SOURCE_BREVO, is_active=True
group=self.email_group,
mailjet_id=None,
brevo_id=123,
source=conversation_constants.SOURCE_BREVO,
is_active=True,
)
self.assertRaises(
ValidationError,
TemplateTransactionalFactory,
group=self.email_group,
mailjet_id=123,
brevo_id=None,
source=conversation_constants.SOURCE_BREVO,
Expand All @@ -129,6 +138,7 @@ def test_template_transactional_validation_on_save(self):
self.assertRaises(
ValidationError,
TemplateTransactionalFactory,
group=self.email_group,
mailjet_id=None,
brevo_id=123,
source=conversation_constants.SOURCE_MAILJET,
Expand Down
5 changes: 3 additions & 2 deletions lemarche/www/dashboard_siaes/tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.test import TestCase
from django.urls import reverse

from lemarche.conversations.factories import TemplateTransactionalFactory
from lemarche.conversations.factories import EmailGroupFactory, TemplateTransactionalFactory
from lemarche.perimeters.factories import PerimeterFactory
from lemarche.perimeters.models import Perimeter
from lemarche.sectors.factories import SectorFactory, SectorGroupFactory
Expand All @@ -23,7 +23,8 @@ def setUpTestData(cls):
cls.siae_with_user = SiaeFactory()
cls.siae_with_user.users.add(cls.user_siae)
cls.siae_without_user = SiaeFactory()
TemplateTransactionalFactory(code="SIAEUSERREQUEST_ASSIGNEE")
group = EmailGroupFactory()
TemplateTransactionalFactory(code="SIAEUSERREQUEST_ASSIGNEE", group=group)

def test_anonymous_user_cannot_adopt_siae(self):
url = reverse("dashboard_siaes:siae_search_by_siret")
Expand Down
5 changes: 3 additions & 2 deletions lemarche/www/tenders/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from django.utils import timezone
from sesame.utils import get_query_string as sesame_get_query_string

from lemarche.conversations.factories import TemplateTransactionalFactory
from lemarche.conversations.factories import EmailGroupFactory, TemplateTransactionalFactory
from lemarche.perimeters.factories import PerimeterFactory
from lemarche.perimeters.models import Perimeter
from lemarche.sectors.factories import SectorFactory
Expand Down Expand Up @@ -1133,7 +1133,8 @@ def setUpTestData(cls):
cls.tender_contact_click_stat_url = reverse(
"tenders:detail-contact-click-stat", kwargs={"slug": cls.tender.slug}
)
TemplateTransactionalFactory(code="TENDERS_AUTHOR_SIAE_INTERESTED_1")
group = EmailGroupFactory()
TemplateTransactionalFactory(code="TENDERS_AUTHOR_SIAE_INTERESTED_1", group=group)

def test_anonymous_user_cannot_notify_interested(self):
response = self.client.get(self.tender_detail_url)
Expand Down

0 comments on commit 745afd9

Please sign in to comment.