From 7361e1556d66a62ca91d82e067bb172172975ede Mon Sep 17 00:00:00 2001 From: vasileios Date: Wed, 11 Dec 2024 10:49:34 +0100 Subject: [PATCH] Fixed some remaining pieces Deleted the tests which were refering to the old flow as well. The new appointments do not have summary or steps so no need to test with such a configuration. --- .../templatetags/appointment_information.txt | 4 +- .../emails/templatetags/form_summary.py | 2 +- .../emails/tests/test_confirmation_email.py | 283 +----------------- .../admin/form_design/form-creation-form.js | 1 - .../submissions/models/submission.py | 1 - src/openforms/submissions/query.py | 2 +- .../tests/test_post_submission_event.py | 4 +- .../tests/test_tasks_confirmation_emails.py | 4 +- 8 files changed, 6 insertions(+), 295 deletions(-) diff --git a/src/openforms/emails/templates/emails/templatetags/appointment_information.txt b/src/openforms/emails/templates/emails/templatetags/appointment_information.txt index 76d9dcb371..b673c13c2c 100644 --- a/src/openforms/emails/templates/emails/templatetags/appointment_information.txt +++ b/src/openforms/emails/templates/emails/templatetags/appointment_information.txt @@ -23,7 +23,5 @@ {% trans "If you want to cancel or change your appointment, you can do so below." %} {% trans "Cancel appointment" %}: {{ appointment_cancel_link }} -{% if appointment_change_link %}{% trans "Change appointment" %}: {{ appointment_change_link }} -{% else %}{% trans "If you wish to change your appointment, please cancel it using the above link and create a new one." %} -{% endif %} +{% trans "If you wish to change your appointment, please cancel it using the above link and create a new one." %} {% endif %}{% endautoescape %} diff --git a/src/openforms/emails/templatetags/form_summary.py b/src/openforms/emails/templatetags/form_summary.py index 0ace645333..3fc5b93c45 100644 --- a/src/openforms/emails/templatetags/form_summary.py +++ b/src/openforms/emails/templatetags/form_summary.py @@ -16,7 +16,7 @@ @register.simple_tag(takes_context=True) def confirmation_summary(context): submission = context["_submission"] - # if it's a new-style appointment submission, there are no steps or summary to render + # There are no steps or summary to render in new-style appointment submission if get_appointment(submission) is not None: return "" diff --git a/src/openforms/emails/tests/test_confirmation_email.py b/src/openforms/emails/tests/test_confirmation_email.py index e29f69c77f..aa7d51ed30 100644 --- a/src/openforms/emails/tests/test_confirmation_email.py +++ b/src/openforms/emails/tests/test_confirmation_email.py @@ -1,7 +1,5 @@ import inspect -import re from copy import deepcopy -from datetime import date, datetime from decimal import Decimal from unittest.mock import patch @@ -10,15 +8,8 @@ from django.template import TemplateSyntaxError from django.test import TestCase, override_settings from django.urls import reverse -from django.utils.html import format_html from django.utils.translation import gettext as _ -from openforms.appointments.base import ( - AppointmentDetails, - BasePlugin, - Location, - Product, -) from openforms.appointments.constants import AppointmentDetailsStatus from openforms.appointments.contrib.demo.plugin import DemoAppointment from openforms.appointments.tests.factories import AppointmentInfoFactory @@ -32,7 +23,7 @@ ) from openforms.submissions.utils import send_confirmation_email from openforms.tests.utils import NOOP_CACHES -from openforms.utils.tests.html_assert import HTMLAssertMixin, strip_all_attributes +from openforms.utils.tests.html_assert import HTMLAssertMixin from openforms.utils.urls import build_absolute_uri from ..confirmation_emails import ( @@ -579,51 +570,6 @@ def test_email_payment_completed(self): self.assertNotIn(url, rendered_content) -class TestAppointmentPlugin(BasePlugin): - def get_available_products(self, current_products=None): - return [ - Product(identifier="1", name="Test product 1"), - Product(identifier="2", name="Test product 2"), - ] - - def get_locations(self, products): - return [Location(identifier="1", name="Test location")] - - def get_dates(self, products, location, start_at=None, end_at=None): - return [date(2021, 1, 1)] - - def get_times(self, products, location, day): - return [datetime(2021, 1, 1, 12, 0)] - - def get_required_customer_fields(self, products): - return [] - - def create_appointment(self, products, location, start_at, client, remarks=None): - return "1" - - def delete_appointment(self, identifier: str) -> None: - return - - def get_appointment_details(self, identifier: str): - return AppointmentDetails( - identifier=identifier, - products=[ - Product(identifier="1", name="Test product 1 & 2"), - Product(identifier="2", name="Test product 3"), - ], - location=Location( - identifier="1", - name="Test location", - city="Teststad", - postalcode="1234ab", - ), - start_at=datetime(2021, 1, 1, 12, 0), - end_at=datetime(2021, 1, 1, 12, 15), - remarks="Remarks", - other={"Some": "

Data

"}, - ) - - @override_settings(DEFAULT_FROM_EMAIL="foo@sender.com") class ConfirmationEmailRenderingIntegrationTest(HTMLAssertMixin, TestCase): template = """ @@ -647,233 +593,6 @@ class ConfirmationEmailRenderingIntegrationTest(HTMLAssertMixin, TestCase): """ maxDiff = None - @patch( - "openforms.emails.templatetags.appointments.get_plugin", - return_value=TestAppointmentPlugin("test"), - ) - def test_send_confirmation_mail_text_kitchensink(self, appointment_plugin_mock): - config = GlobalConfiguration.get_solo() - config.email_template_netloc_allowlist = ["gemeente.nl"] - config.save() - - conf = deepcopy(NESTED_COMPONENT_CONF) - conf["components"].append( - { - "id": "erttrr", - "key": "file", - "type": "file", - "label": "File", - "showInEmail": True, - } - ) - - submission = SubmissionFactory.from_components( - conf["components"], - { - "name": "Foo", - "lastName": "de Bar & de Baas", - "email": "foo@bar.baz", - "file": [ - { - "url": "http://server/api/v2/submissions/files/62f2ec22-da7d-4385-b719-b8637c1cd483", - "data": { - "url": "http://server/api/v2/submissions/files/62f2ec22-da7d-4385-b719-b8637c1cd483", - "form": "", - "name": "my-image.jpg", - "size": 46114, - "baseUrl": "http://server/form", - "project": "", - }, - "name": "my-image-12305610-2da4-4694-a341-ccb919c3d543.jpg", - "size": 46114, - "type": "image/jpg", - "storage": "url", - "originalName": "my-image.jpg", - } - ], - }, - registration_success=True, - public_registration_reference="xyz123", - form__product__price=Decimal("12.34"), - form__product__information="

info line 1

\r\n

info line 2

\r\n

info line 3

", - form__payment_backend="test", - form_url="http://server/form", - co_sign_data={ - "plugin": "digid", - "identifier": "123456782", - "fields": { - "voornaam": "Tina", - "geslachtsnaam": "Shikari", - }, - "representation": "T. Shikari", - }, - ) - AppointmentInfoFactory.create( - status=AppointmentDetailsStatus.success, - appointment_id="123456789", - submission=submission, - ) - self.assertTrue(submission.payment_required) - self.assertFalse(submission.payment_user_has_paid) - - template = inspect.cleandoc(self.template) - ConfirmationEmailTemplateFactory.create( - form=submission.form, subject="My Subject", content=template - ) - first_step_name = submission.submissionstep_set.all()[ - 0 - ].form_step.form_definition.name - - send_confirmation_email(submission) - - self.assertEqual(len(mail.outbox), 1) - - message = mail.outbox[0] - self.assertEqual(message.subject, "My Subject") - self.assertEqual(message.recipients(), ["foo@bar.baz"]) - self.assertEqual(message.from_email, "foo@sender.com") - - ref = submission.public_registration_reference - - url_exp = r"https?://[a-z0-9:/._-]+" - pay_line = _( - "Payment of EUR %(payment_price)s is required. You can pay using the link below." - ) % {"payment_price": "12,34"} - - with self.subTest("text"): - expected_text = inspect.cleandoc( - f""" - Geachte heer/mevrouw, - - Wij hebben uw inzending, met referentienummer {ref}, in goede orde ontvangen. - - Kijk voor meer informatie op de homepage (#URL#) - - {_("Summary")} - - {first_step_name} - - - A fieldset - - Name: Foo - - Last name: de Bar & de Baas - - File: {_("attachment: %s") % "my-image.jpg"} - - {_("Co-signed by")}: T. Shikari - - {_("Appointment information")} - - {_("Products")}: - - Test product 1 & 2 - - Test product 3 - - {_("Location")}: - Test location - 1234ab Teststad - - {_("Date and time")}: - 1 januari 2021, 12:00 - 12:15 - - {_("Remarks")}: - Remarks - - Some: - Data - - {_("If you want to cancel or change your appointment, you can do so below.")} - {_("Cancel appointment")}: #URL# - {_("Change appointment")}: #URL# - - info line 1 - info line 2 - info line 3 - - {_("Payment information")} - - {pay_line} - {_("Go to the payment page")}: #URL# - - Met vriendelijke groet, - - Open Formulieren - """ - ).lstrip() - - # process to keep tests sane (random tokens) - text = message.body.rstrip() - text = re.sub(url_exp, "#URL#", text) - self.assertEqual(expected_text, text) - self.assertNotIn("', message_html) - - message_html_only_tags = strip_all_attributes(message_html) - # check co-sign data presence - self.assertInHTML( - format_html( - " {label} T. Shikari ", - label=_("Co-signed by"), - ), - message_html_only_tags, - ) - - # fieldset and step containers should be visible - self.assertInHTML( - format_html("

{}

", first_step_name), - message_html_only_tags, - ) - - # renderer should ignore hidden inputs - self.assertNotIn("Hidden input", message_html_only_tags) - self.assertNotIn("A fieldset with hidden children", message_html_only_tags) - self.assertNotIn("Hidden input 2", message_html_only_tags) - - with self.subTest("attachments"): - # file uploads may not be added as attachments, see #1193 - self.assertEqual(message.attachments, []) - - @patch( - "openforms.emails.templatetags.appointments.get_plugin", - return_value=TestAppointmentPlugin("test"), - ) - def test_html_in_subject(self, appointment_plugin_mock): - """Assert that HTML is not escaped in Email subjects""" - - conf = deepcopy(NESTED_COMPONENT_CONF) - - submission = SubmissionFactory.from_components( - conf["components"], - { - "name": "John", - "lastName": "Doe", - "email": "foo@bar.baz", - }, - registration_success=True, - ) - submission.form.name = "Foo's bar" - - template = inspect.cleandoc(self.template) - - ConfirmationEmailTemplateFactory.create( - form=submission.form, subject="Subject: {{ form_name }}", content=template - ) - - send_confirmation_email(submission) - - self.assertEqual(len(mail.outbox), 1) - - message = mail.outbox[0] - self.assertEqual(message.subject, "Subject: Foo's bar") - def test_templatetag_alias(self): submission = SubmissionFactory.from_components( [ diff --git a/src/openforms/js/components/admin/form_design/form-creation-form.js b/src/openforms/js/components/admin/form_design/form-creation-form.js index 4ea54d4aee..3e23c72b93 100644 --- a/src/openforms/js/components/admin/form_design/form-creation-form.js +++ b/src/openforms/js/components/admin/form_design/form-creation-form.js @@ -1,6 +1,5 @@ import {produce} from 'immer'; import cloneDeep from 'lodash/cloneDeep'; -// import getObjectValue from 'lodash/get'; import groupBy from 'lodash/groupBy'; import set from 'lodash/set'; import sortBy from 'lodash/sortBy'; diff --git a/src/openforms/submissions/models/submission.py b/src/openforms/submissions/models/submission.py index 967c381991..969ff8c7b6 100644 --- a/src/openforms/submissions/models/submission.py +++ b/src/openforms/submissions/models/submission.py @@ -17,7 +17,6 @@ import elasticapm from django_jsonform.models.fields import ArrayField from furl import furl -from glom import glom from openforms.config.models import GlobalConfiguration from openforms.formio.datastructures import FormioConfigurationWrapper diff --git a/src/openforms/submissions/query.py b/src/openforms/submissions/query.py index 222e014cc1..0d611447a4 100644 --- a/src/openforms/submissions/query.py +++ b/src/openforms/submissions/query.py @@ -19,7 +19,7 @@ from openforms.config.models import GlobalConfiguration if TYPE_CHECKING: - from .models import Submission + from .models import Submission # noqa class SubmissionQuerySet(models.QuerySet["Submission"]): diff --git a/src/openforms/submissions/tests/test_post_submission_event.py b/src/openforms/submissions/tests/test_post_submission_event.py index 9f3a9ef5dc..e4a975d28b 100644 --- a/src/openforms/submissions/tests/test_post_submission_event.py +++ b/src/openforms/submissions/tests/test_post_submission_event.py @@ -10,13 +10,11 @@ from privates.test import temp_private_root from testfixtures import LogCapture -from openforms.appointments.exceptions import AppointmentRegistrationFailed -from openforms.appointments.tests.utils import setup_jcc from openforms.authentication.service import AuthAttribute from openforms.config.models import GlobalConfiguration from openforms.emails.tests.factories import ConfirmationEmailTemplateFactory from openforms.forms.constants import LogicActionTypes, PropertyTypes -from openforms.forms.tests.factories import FormDefinitionFactory, FormLogicFactory +from openforms.forms.tests.factories import FormLogicFactory from openforms.payments.constants import PaymentStatus from openforms.payments.tests.factories import SubmissionPaymentFactory from openforms.registrations.base import PreRegistrationResult diff --git a/src/openforms/submissions/tests/test_tasks_confirmation_emails.py b/src/openforms/submissions/tests/test_tasks_confirmation_emails.py index 7781098802..2194501216 100644 --- a/src/openforms/submissions/tests/test_tasks_confirmation_emails.py +++ b/src/openforms/submissions/tests/test_tasks_confirmation_emails.py @@ -6,12 +6,10 @@ from django.core import mail from django.db import close_old_connections from django.test import TestCase, TransactionTestCase, override_settings -from django.utils.translation import gettext as _, override as override_language +from django.utils.translation import override as override_language from privates.test import temp_private_root -from openforms.appointments.constants import AppointmentDetailsStatus -from openforms.appointments.tests.factories import AppointmentInfoFactory from openforms.config.models import GlobalConfiguration from openforms.emails.models import ConfirmationEmailTemplate from openforms.emails.tests.factories import ConfirmationEmailTemplateFactory