Skip to content

Commit

Permalink
Fixed some remaining pieces
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vaszig committed Dec 11, 2024
1 parent 2ae95a1 commit 7361e15
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 295 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
2 changes: 1 addition & 1 deletion src/openforms/emails/templatetags/form_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""

Expand Down
283 changes: 1 addition & 282 deletions src/openforms/emails/tests/test_confirmation_email.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand All @@ -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 (
Expand Down Expand Up @@ -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": "<h1>Data</h1>"},
)


@override_settings(DEFAULT_FROM_EMAIL="[email protected]")
class ConfirmationEmailRenderingIntegrationTest(HTMLAssertMixin, TestCase):
template = """
Expand All @@ -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": "[email protected]",
"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="<p>info line 1</p>\r\n<p>info line 2</p>\r\n<p>info line 3</p>",
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(), ["[email protected]"])
self.assertEqual(message.from_email, "[email protected]")

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("<a ", text)
self.assertNotIn("<td ", text)
self.assertNotIn("<p ", text)
self.assertNotIn("<br ", text)

with self.subTest("html"):
# html alternative
self.assertEqual(len(message.alternatives), 1)

message_html = message.alternatives[0][0]

self.assertTagWithTextIn("td", "Name", message_html)
self.assertTagWithTextIn("td", "Foo", message_html)
self.assertIn('<a href="http://gemeente.nl">', message_html)

message_html_only_tags = strip_all_attributes(message_html)
# check co-sign data presence
self.assertInHTML(
format_html(
"<tr> <td>{label}</td> <td>T. Shikari</td> </tr>",
label=_("Co-signed by"),
),
message_html_only_tags,
)

# fieldset and step containers should be visible
self.assertInHTML(
format_html("<h3>{}</h3>", 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": "[email protected]",
},
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(
[
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
1 change: 0 additions & 1 deletion src/openforms/submissions/models/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/openforms/submissions/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7361e15

Please sign in to comment.