From cba3d8cbd63e4aa02ec0581c64da30a2e33da0fa Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Wed, 3 Apr 2024 12:57:50 +0200 Subject: [PATCH] :bug: [#4103] Use the plugin appointment ID instead of our internal DB pk 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 --- src/openforms/appointments/renderer.py | 3 ++- src/openforms/appointments/tests/test_pdf.py | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/openforms/appointments/renderer.py b/src/openforms/appointments/renderer.py index 8ffd9e5402..b71f2c3d94 100644 --- a/src/openforms/appointments/renderer.py +++ b/src/openforms/appointments/renderer.py @@ -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) diff --git a/src/openforms/appointments/tests/test_pdf.py b/src/openforms/appointments/tests/test_pdf.py index 5a70234374..a3043ce7b5 100644 --- a/src/openforms/appointments/tests/test_pdf.py +++ b/src/openforms/appointments/tests/test_pdf.py @@ -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 @@ -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( @@ -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")