-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1106 from maykinmedia/feature/2106-contact-confir…
…mation-email [#2106, #2203] Implemented 'contactform_confirmation' email
- Loading branch information
Showing
10 changed files
with
296 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from unittest.mock import patch | ||
from unittest.mock import ANY, patch | ||
|
||
from django.conf import settings | ||
from django.core import mail | ||
|
@@ -42,6 +42,9 @@ | |
|
||
|
||
@requests_mock.Mocker() | ||
@patch( | ||
"open_inwoner.cms.cases.views.status.send_contact_confirmation_mail", autospec=True | ||
) | ||
@patch.object( | ||
ContactmomentenClient, | ||
"retrieve_objectcontactmomenten_for_zaak", | ||
|
@@ -81,6 +84,7 @@ def setUp(self): | |
|
||
# openklant config | ||
self.ok_config = OpenKlantConfig.get_solo() | ||
self.ok_config.send_email_confirmation = True | ||
self.ok_config.register_contact_moment = True | ||
self.ok_config.register_bronorganisatie_rsin = "123456788" | ||
self.ok_config.register_type = "Melding" | ||
|
@@ -330,7 +334,9 @@ def _setUpExtraMocks(self, m): | |
json=self.contactmoment, | ||
) | ||
|
||
def test_form_is_shown_if_open_klant_api_configured(self, m, contactmoment_mock): | ||
def test_form_is_shown_if_open_klant_api_configured( | ||
self, m, mock_contactmoment, mock_send_confirm | ||
): | ||
self._setUpMocks(m) | ||
self._setUpExtraMocks(m) | ||
|
||
|
@@ -342,7 +348,11 @@ def test_form_is_shown_if_open_klant_api_configured(self, m, contactmoment_mock) | |
self.assertTrue(response.context["case"]["contact_form_enabled"]) | ||
self.assertTrue(contact_form) | ||
|
||
def test_form_is_shown_if_open_klant_email_configured(self, m, contactmoment_mock): | ||
mock_send_confirm.assert_not_called() | ||
|
||
def test_form_is_shown_if_open_klant_email_configured( | ||
self, m, mock_contactmoment, mock_send_confirm | ||
): | ||
self._setUpMocks(m) | ||
self._setUpExtraMocks(m) | ||
|
||
|
@@ -359,8 +369,10 @@ def test_form_is_shown_if_open_klant_email_configured(self, m, contactmoment_moc | |
self.assertTrue(response.context["case"]["contact_form_enabled"]) | ||
self.assertTrue(contact_form) | ||
|
||
mock_send_confirm.assert_not_called() | ||
|
||
def test_form_is_shown_if_open_klant_email_and_api_configured( | ||
self, m, contactmoment_mock | ||
self, m, mock_contactmoment, mock_send_confirm | ||
): | ||
self._setUpMocks(m) | ||
self._setUpExtraMocks(m) | ||
|
@@ -377,7 +389,11 @@ def test_form_is_shown_if_open_klant_email_and_api_configured( | |
self.assertTrue(response.context["case"]["contact_form_enabled"]) | ||
self.assertTrue(contact_form) | ||
|
||
def test_no_form_shown_if_open_klant_not_configured(self, m, contactmoment_mock): | ||
mock_send_confirm.assert_not_called() | ||
|
||
def test_no_form_shown_if_open_klant_not_configured( | ||
self, m, mock_contactmoment, mock_send_confirm | ||
): | ||
self._setUpMocks(m) | ||
|
||
# reset | ||
|
@@ -397,7 +413,11 @@ def test_no_form_shown_if_open_klant_not_configured(self, m, contactmoment_mock) | |
self.assertFalse(response.context["case"]["contact_form_enabled"]) | ||
self.assertFalse(contact_form) | ||
|
||
def test_no_form_shown_if_contact_form_disabled(self, m, contactmoment_mock): | ||
mock_send_confirm.assert_not_called() | ||
|
||
def test_no_form_shown_if_contact_form_disabled( | ||
self, m, mock_contactmoment, mock_send_confirm | ||
): | ||
self._setUpMocks(m) | ||
self._setUpExtraMocks(m) | ||
|
||
|
@@ -415,7 +435,9 @@ def test_no_form_shown_if_contact_form_disabled(self, m, contactmoment_mock): | |
self.assertFalse(response.context["case"]["contact_form_enabled"]) | ||
self.assertFalse(contact_form) | ||
|
||
def test_form_success_with_api(self, m, contactmoment_mock): | ||
mock_send_confirm.assert_not_called() | ||
|
||
def test_form_success_with_api(self, m, mock_contactmoment, mock_send_confirm): | ||
self._setUpMocks(m) | ||
self._setUpExtraMocks(m) | ||
|
||
|
@@ -450,8 +472,11 @@ def test_form_success_with_api(self, m, contactmoment_mock): | |
"type": "Melding", | ||
}, | ||
) | ||
mock_send_confirm.assert_called_once_with("[email protected]", ANY) | ||
|
||
def test_form_success_with_api_eherkenning_user(self, m, contactmoment_mock): | ||
def test_form_success_with_api_eherkenning_user( | ||
self, m, mock_contactmoment, mock_send_confirm | ||
): | ||
self._setUpMocks(m) | ||
self._setUpExtraMocks(m) | ||
|
||
|
@@ -515,8 +540,12 @@ def test_form_success_with_api_eherkenning_user(self, m, contactmoment_mock): | |
"type": "Melding", | ||
}, | ||
) | ||
# user was modified in loop | ||
eherkenning_user.refresh_from_db() | ||
mock_send_confirm.assert_called_once_with(eherkenning_user.email, ANY) | ||
mock_send_confirm.reset_mock() | ||
|
||
def test_form_success_with_email(self, m, contactmoment_mock): | ||
def test_form_success_with_email(self, m, mock_contactmoment, mock_send_confirm): | ||
self._setUpMocks(m) | ||
self._setUpExtraMocks(m) | ||
|
||
|
@@ -548,8 +577,11 @@ def test_form_success_with_email(self, m, contactmoment_mock): | |
message.subject, | ||
_("Contact formulier inzending vanaf Open Inwoner Platform"), | ||
) | ||
mock_send_confirm.assert_called_once_with("[email protected]", ANY) | ||
|
||
def test_form_success_with_both_email_and_api(self, m, contactmoment_mock): | ||
def test_form_success_with_both_email_and_api( | ||
self, m, mock_contactmoment, mock_send_confirm | ||
): | ||
self._setUpMocks(m) | ||
self._setUpExtraMocks(m) | ||
|
||
|
@@ -575,3 +607,43 @@ def test_form_success_with_both_email_and_api(self, m, contactmoment_mock): | |
self.assertEqual(redirect_messages[0].message, _("Vraag verstuurd!")) | ||
self.assertMockMatchersCalled(self.extra_matchers) | ||
self.assertEqual(len(mail.outbox), 1) | ||
|
||
mock_send_confirm.assert_called_once_with("[email protected]", ANY) | ||
|
||
def test_send_email_confirmation_is_configurable__send_enabled( | ||
self, m, mock_contactmoment, mock_send_confirm | ||
): | ||
self._setUpMocks(m) | ||
self._setUpExtraMocks(m) | ||
|
||
config = OpenKlantConfig.get_solo() | ||
config.send_email_confirmation = True | ||
config.save() | ||
|
||
response = self.app.get(self.case_detail_url, user=self.user) | ||
form = response.forms["contact-form"] | ||
form.action = reverse( | ||
"cases:case_detail_contact_form", kwargs={"object_id": self.zaak["uuid"]} | ||
) | ||
form["question"] = "Sample text" | ||
response = form.submit() | ||
mock_send_confirm.assert_called_once() | ||
|
||
def test_send_email_confirmation_is_configurable__send_disabled( | ||
self, m, mock_contactmoment, mock_send_confirm | ||
): | ||
self._setUpMocks(m) | ||
self._setUpExtraMocks(m) | ||
|
||
config = OpenKlantConfig.get_solo() | ||
config.send_email_confirmation = False | ||
config.save() | ||
|
||
response = self.app.get(self.case_detail_url, user=self.user) | ||
form = response.forms["contact-form"] | ||
form.action = reverse( | ||
"cases:case_detail_contact_form", kwargs={"object_id": self.zaak["uuid"]} | ||
) | ||
form["question"] = "Sample text" | ||
response = form.submit() | ||
mock_send_confirm.assert_not_called() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from mail_editor.helpers import find_template | ||
|
||
|
||
def send_contact_confirmation_mail(recipient_email: str, form_subject: str): | ||
template = find_template("contactform_confirmation") | ||
context = { | ||
"subject": form_subject, | ||
} | ||
template.send_email([recipient_email], context=context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django.core import mail | ||
from django.test import TestCase | ||
|
||
from open_inwoner.mail.service import send_contact_confirmation_mail | ||
|
||
|
||
class TestServices(TestCase): | ||
def test_send_contact_confirmation_mail(self): | ||
send_contact_confirmation_mail("[email protected]", "My subject") | ||
|
||
self.assertEqual(len(mail.outbox), 1) | ||
|
||
sent_mail = mail.outbox[0] | ||
html_body = sent_mail.alternatives[0][0] | ||
|
||
self.assertIn("Vraag ontvangen op ", sent_mail.subject) | ||
self.assertEqual(sent_mail.to, ["[email protected]"]) | ||
self.assertIn("My subject", html_body) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/open_inwoner/openklant/migrations/0012_openklantconfig_send_email_confirmation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Generated by Django 4.2.11 on 2024-04-18 07:57 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
( | ||
"openklant", | ||
"0011_alter_openklantconfig_use_rsin_for_innnnpid_query_parameter", | ||
), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="openklantconfig", | ||
name="send_email_confirmation", | ||
field=models.BooleanField( | ||
default=False, | ||
help_text="If enabled the 'contactform_confirmation' email template will be sent. If disabled the external API will send a confirmation email.", | ||
verbose_name="Stuur contactformulier e-mailbevestiging", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.