Skip to content

Commit

Permalink
🐛 [#4103] Use the plugin appointment ID instead of our internal DB pk
Browse files Browse the repository at this point in the history
Appointment details were being retrieved using our internal database primary key,
but that looks up records from the appointment system that are unlikely to
match with the actual appointment ID recorded for a given appointment.

Backport-of: #4108
  • Loading branch information
sergei-maertens committed Apr 3, 2024
1 parent cdcaf9b commit b37ebf1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/openforms/appointments/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ def __str__(self) -> SafeString:
)
plugin = get_plugin(plugin=appointment.plugin)

identifier: str = self.submission.appointment_info.appointment_id
ctx = {
"appointment": plugin.get_appointment_details(appointment.pk),
"appointment": plugin.get_appointment_details(identifier),
"contact_details": self.get_children(), # todo: a bit of a wart
}
return render_to_string(template_name, ctx)
20 changes: 19 additions & 1 deletion src/openforms/appointments/tests/test_pdf.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from django.test import RequestFactory, TestCase, override_settings
from unittest.mock import patch

from django.test import RequestFactory, TestCase, override_settings, tag
from django.utils.html import escape

from openforms.accounts.tests.factories import SuperUserFactory
from openforms.submissions.dev_views import SubmissionPDFTestView
from openforms.submissions.tests.factories import SubmissionFactory

from ..contrib.demo.plugin import DemoAppointment
from .factories import AppointmentFactory, AppointmentProductFactory


Expand All @@ -18,6 +21,7 @@ def setUpTestData(cls):
submission__registration_success=True,
submission__with_report=True,
appointment_info__registration_ok=True,
appointment_info__appointment_id="a-remote-id",
location__identifier="1",
)
AppointmentProductFactory.create(
Expand Down Expand Up @@ -59,3 +63,17 @@ def test_submission_without_appointment_shows_no_appointment_info(self):
html = submission.report.generate_submission_report_pdf()

self.assertNotIn("Afspraakinformatie", html)

@tag("gh-4103")
def test_uses_remote_appoinment_id(self):
plugin = DemoAppointment("demo")

with (
patch("openforms.appointments.renderer.get_plugin", return_value=plugin),
patch.object(
plugin, "get_appointment_details", wraps=plugin.get_appointment_details
) as m_get_details,
):
self.submission.report.generate_submission_report_pdf()

m_get_details.assert_called_once_with("a-remote-id")

0 comments on commit b37ebf1

Please sign in to comment.