Skip to content

Commit

Permalink
clearer with decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienReuiller committed Jan 13, 2025
1 parent 4a84394 commit 50f6ba5
Showing 1 changed file with 26 additions and 44 deletions.
70 changes: 26 additions & 44 deletions lemarche/conversations/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from datetime import datetime
from unittest import mock
from unittest.mock import patch

from django.core.exceptions import ValidationError
Expand Down Expand Up @@ -157,60 +156,43 @@ def test_get_template_id(self):
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_brevo.brevo_id)

def test_send_transactional_email_mailjet(self):
with mock.patch(
"lemarche.conversations.models.api_mailjet.send_transactional_email_with_template"
) as mock_send_transactional_email_mailjet:
self.tt_active_mailjet.save()
self.tt_active_mailjet.send_transactional_email(
recipient_email="test@example.com", recipient_name="test", variables={}
)
@patch("lemarche.conversations.models.api_mailjet.send_transactional_email_with_template")
def test_send_transactional_email_mailjet(self, mock_send_transactional_email_mailjet):
self.tt_active_mailjet.save()
self.tt_active_mailjet.send_transactional_email(
recipient_email="test@example.com", recipient_name="test", variables={}
)
mock_send_transactional_email_mailjet.assert_called_once()

def test_send_transactional_email_brevo(self):
with mock.patch(
"lemarche.conversations.models.api_brevo.send_transactional_email_with_template"
) as mock_send_transactional_email_brevo:
self.tt_active_brevo.save()
self.tt_active_brevo.send_transactional_email(
recipient_email="test@example.com", recipient_name="test", variables={}
)
@patch("lemarche.conversations.models.api_brevo.send_transactional_email_with_template")
def test_send_transactional_email_brevo(self, mock_send_transactional_email_brevo):
self.tt_active_brevo.save()
self.tt_active_brevo.send_transactional_email(
recipient_email="test@example.com", recipient_name="test", variables={}
)
mock_send_transactional_email_brevo.assert_called_once()

def test_send_transactional_email_inactive(self):
with mock.patch(
"lemarche.conversations.models.api_mailjet.send_transactional_email_with_template"
) as mock_send_transactional_email_mailjet:
with mock.patch(
"lemarche.conversations.models.api_brevo.send_transactional_email_with_template"
) as mock_send_transactional_email_brevo:
self.tt_inactive.save()
self.tt_inactive.send_transactional_email(
recipient_email="test@example.com", recipient_name="test", variables={}
)
@patch("lemarche.conversations.models.api_brevo.send_transactional_email_with_template")
@patch("lemarche.conversations.models.api_mailjet.send_transactional_email_with_template")
def test_send_transactional_email_inactive(
self, mock_send_transactional_email_mailjet, mock_send_transactional_email_brevo
):
self.tt_inactive.save()
self.tt_inactive.send_transactional_email(
recipient_email="test@example.com", recipient_name="test", variables={}
)

mock_send_transactional_email_mailjet.assert_not_called()
mock_send_transactional_email_brevo.assert_not_called()

def test_disabled_email_group(self):
@patch("lemarche.conversations.models.api_brevo.send_transactional_email_with_template")
def test_disabled_email_group(self, mock_send_transactional_email_brevo):
email_test = "test@example.com"
user = UserFactory(email=email_test)
with mock.patch(
"lemarche.conversations.models.api_brevo.send_transactional_email_with_template"
) as mock_send_transactional_email_brevo:
self.tt_active_brevo.save()
self.tt_active_brevo.send_transactional_email(
recipient_email=email_test, recipient_name="test", variables={}
)
mock_send_transactional_email_brevo.assert_called_once()

DisabledEmail.objects.create(user=user, group=self.email_group)
with mock.patch(
"lemarche.conversations.models.api_brevo.send_transactional_email_with_template"
) as mock_send_transactional_email_brevo:
self.tt_active_brevo.send_transactional_email(
recipient_email=email_test, recipient_name="test", variables={}
)

self.tt_active_brevo.save()
self.tt_active_brevo.send_transactional_email(recipient_email=email_test, recipient_name="test", variables={})
mock_send_transactional_email_brevo.assert_not_called()


Expand Down

0 comments on commit 50f6ba5

Please sign in to comment.