-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(Email Notifications): Mise à jour côté Brevo du choix pour les communications Marketing #1639
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from unittest.mock import patch | ||
|
||
from django.test import TestCase | ||
from django.urls import reverse | ||
|
||
|
@@ -88,7 +90,11 @@ def test_get_form_displays_correctly(self): | |
self.assertContains(response, group.display_name) | ||
self.assertContains(response, " checked>", count=2) | ||
|
||
def test_form_submission_updates_preferences(self): | ||
@patch("lemarche.utils.apis.api_brevo.sib_api_v3_sdk.ContactsApi") | ||
def test_form_submission_updates_preferences_with_marketing_disabled(self, mock_contacts_api): | ||
# Setup the mock | ||
mock_api_instance = mock_contacts_api.return_value | ||
|
||
self.assertEqual(self.user.disabled_emails.count(), 0) | ||
self.client.force_login(self.user) | ||
response = self.client.post( | ||
|
@@ -99,7 +105,40 @@ def test_form_submission_updates_preferences(self): | |
}, | ||
follow=True, | ||
) | ||
|
||
# Verify the API was called correctly | ||
mock_api_instance.update_contact.assert_called_once() | ||
call_args = mock_api_instance.update_contact.call_args | ||
self.assertEqual(call_args[1]["identifier"], self.user.email) | ||
self.assertEqual(call_args[1]["update_contact"].email_blacklisted, True) | ||
|
||
self.assertContains(response, "Vos préférences de notifications ont été mises à jour.") | ||
self.user.refresh_from_db() | ||
self.assertEqual(self.user.disabled_emails.count(), 1) | ||
self.assertEqual(self.user.disabled_emails.first().group.pk, 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Il faut éviter de tester de cette manière, en faisant |
||
|
||
@patch("lemarche.utils.apis.api_brevo.sib_api_v3_sdk.ContactsApi") | ||
def test_form_submission_updates_preferences_with_marketing_enabled(self, mock_contacts_api): | ||
# Setup the mock | ||
mock_api_instance = mock_contacts_api.return_value | ||
|
||
self.assertEqual(self.user.disabled_emails.count(), 0) | ||
self.client.force_login(self.user) | ||
response = self.client.post( | ||
self.url, | ||
{ | ||
"email_group_1": True, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. J'ai mis un peu de temps à comprendre à quoi correspondaient
Et pour les tests ca permettrait d'individualiser lequel est désactivé ou non |
||
"email_group_2": True, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. En fait, "email_group_2" => "Communication marketing" ? |
||
}, | ||
follow=True, | ||
) | ||
|
||
# Verify the API was called correctly | ||
mock_api_instance.update_contact.assert_called_once() | ||
call_args = mock_api_instance.update_contact.call_args | ||
self.assertEqual(call_args[1]["identifier"], self.user.email) | ||
self.assertEqual(call_args[1]["update_contact"].email_blacklisted, False) | ||
|
||
self.assertContains(response, "Vos préférences de notifications ont été mises à jour.") | ||
self.user.refresh_from_db() | ||
self.assertEqual(self.user.disabled_emails.count(), 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seuls les message du logger et l'argument vers
.UpdateContact()
changent par rapport à la fonction du dessus,update_contact
. Il faudrait peut être factoriser cela.