From 011defa537a21a590a64a2b06d2c39523b6c8f11 Mon Sep 17 00:00:00 2001 From: vasileios Date: Mon, 2 Dec 2024 16:03:10 +0100 Subject: [PATCH] [#3283] Fixed/removed/updated tests --- .../contrib/demo/tests/test_endpoints.py | 2 +- .../contrib/jcc/tests/test_api_endpoints.py | 16 +- .../contrib/jcc/tests/test_plugin.py | 23 +- .../qmatic/tests/test_api_endpoints.py | 16 +- .../contrib/qmatic/tests/test_plugin.py | 23 +- .../management/commands/appointment.py | 1 + .../appointments/tests/test_admin.py | 31 +- .../appointments/tests/test_api_products.py | 5 +- src/openforms/appointments/tests/test_base.py | 17 - .../tests/test_booking_appointment.py | 53 +- .../tests/test_confirmation_emails.py | 5 +- .../tests/test_tasks_appointments.py | 148 ---- .../appointments/tests/test_utils.py | 638 +----------------- .../appointments/tests/test_views.py | 556 +-------------- .../emails/tests/test_confirmation_email.py | 7 - .../formatters/tests/test_kitchensink.py | 30 +- .../submissions/tests/test_models.py | 107 --- .../tests/test_post_submission_event.py | 15 - .../tests/test_tasks_confirmation_emails.py | 41 -- 19 files changed, 85 insertions(+), 1649 deletions(-) delete mode 100644 src/openforms/appointments/tests/test_tasks_appointments.py diff --git a/src/openforms/appointments/contrib/demo/tests/test_endpoints.py b/src/openforms/appointments/contrib/demo/tests/test_endpoints.py index 8cd8063aaa..dab878cce6 100644 --- a/src/openforms/appointments/contrib/demo/tests/test_endpoints.py +++ b/src/openforms/appointments/contrib/demo/tests/test_endpoints.py @@ -71,7 +71,7 @@ def test_times_list(self): self.assertEqual(response.status_code, status.HTTP_200_OK) times = response.json() - self.assertEqual(len(times), 3) + self.assertEqual(len(times), 4) def test_required_customer_fields_list(self): endpoint = reverse("api:appointments-customer-fields") diff --git a/src/openforms/appointments/contrib/jcc/tests/test_api_endpoints.py b/src/openforms/appointments/contrib/jcc/tests/test_api_endpoints.py index c013d116eb..0aafab55a1 100644 --- a/src/openforms/appointments/contrib/jcc/tests/test_api_endpoints.py +++ b/src/openforms/appointments/contrib/jcc/tests/test_api_endpoints.py @@ -93,8 +93,8 @@ def test_get_locations_multiple_products(self, m): def test_get_locations_returns_400_when_no_product_id_is_given(self): response = self.client.get(self.endpoint) - self.assertEqual(response.status_code, 200) - self.assertEqual(response.json(), []) + self.assertEqual(response.status_code, 400) + self.assertEqual(response.json()["invalidParams"][0]["code"], "required") def test_get_locations_returns_403_when_no_active_sessions(self): self._clear_session() @@ -165,8 +165,10 @@ def test_get_dates_returns_400_when_missing_query_params(self): for query_param in [{}, {"product_id": 79}, {"location_id": 1}]: with self.subTest(query_param=query_param): response = self.client.get(self.endpoint, query_param) - self.assertEqual(response.status_code, 200) - self.assertEqual(response.json(), []) + self.assertEqual(response.status_code, 400) + self.assertEqual( + response.json()["invalidParams"][0]["code"], "required" + ) def test_get_dates_returns_403_when_no_active_sessions(self): self._clear_session() @@ -242,8 +244,10 @@ def test_get_times_returns_400_when_missing_query_params(self): ]: with self.subTest(query_param=query_param): response = self.client.get(self.endpoint, query_param) - self.assertEqual(response.status_code, 200) - self.assertEqual(response.json(), []) + self.assertEqual(response.status_code, 400) + self.assertEqual( + response.json()["invalidParams"][0]["code"], "required" + ) def test_get_times_returns_403_when_no_active_sessions(self): self._clear_session() diff --git a/src/openforms/appointments/contrib/jcc/tests/test_plugin.py b/src/openforms/appointments/contrib/jcc/tests/test_plugin.py index 18b91eb21a..5153b45b81 100644 --- a/src/openforms/appointments/contrib/jcc/tests/test_plugin.py +++ b/src/openforms/appointments/contrib/jcc/tests/test_plugin.py @@ -15,7 +15,7 @@ from openforms.utils.xml import fromstring from soap.tests.factories import SoapServiceFactory -from ....base import AppointmentDetails, Customer, CustomerDetails, Location, Product +from ....base import AppointmentDetails, CustomerDetails, Location, Product from ....core import book from ....exceptions import ( AppointmentCreateFailed, @@ -251,7 +251,12 @@ def test_get_required_customer_fields(self, m): def test_create_appointment(self, m): product = Product(identifier="1", code="PASAAN", name="Paspoort aanvraag") location = Location(identifier="1", name="Maykin Media") - client = Customer(last_name="Doe", birthdate=date(1980, 1, 1)) + client = CustomerDetails( + details={ + CustomerFields.last_name: "Doe", + CustomerFields.birthday: "1980-01-01", + } + ) m.post( "http://example.com/soap11", @@ -665,7 +670,12 @@ def test_get_times_unexpected_exception(self, m): def test_create_appointment_failure(self, m): product = Product(identifier="1", code="PASAAN", name="Paspoort aanvraag") location = Location(identifier="1", name="Maykin Media") - client = Customer(last_name="Doe", birthdate=date(1980, 1, 1)) + client = CustomerDetails( + details={ + CustomerFields.last_name: "Doe", + CustomerFields.birthday: "1980-01-01", + } + ) start_at = datetime(2021, 8, 23, 6, 0, 0).replace(tzinfo=timezone.utc) m.post( "http://example.com/soap11", @@ -681,7 +691,12 @@ def test_create_appointment_failure(self, m): def test_create_appointment_unexpected_exception(self, m): product = Product(identifier="1", code="PASAAN", name="Paspoort aanvraag") location = Location(identifier="1", name="Maykin Media") - client = Customer(last_name="Doe", birthdate=date(1980, 1, 1)) + client = CustomerDetails( + details={ + CustomerFields.last_name: "Doe", + CustomerFields.birthday: "1980-01-01", + } + ) start_at = datetime(2021, 8, 23, 6, 0, 0).replace(tzinfo=timezone.utc) m.post(requests_mock.ANY, exc=IOError("tubes are closed")) diff --git a/src/openforms/appointments/contrib/qmatic/tests/test_api_endpoints.py b/src/openforms/appointments/contrib/qmatic/tests/test_api_endpoints.py index 25494c48f6..74577a85ac 100644 --- a/src/openforms/appointments/contrib/qmatic/tests/test_api_endpoints.py +++ b/src/openforms/appointments/contrib/qmatic/tests/test_api_endpoints.py @@ -84,8 +84,8 @@ def test_get_locations_returns_all_locations_for_a_product(self, m): def test_get_locations_returns_400_when_no_product_id_is_given(self): response = self.client.get(self.endpoint) - self.assertEqual(response.status_code, 200) - self.assertEqual(response.json(), []) + self.assertEqual(response.status_code, 400) + self.assertEqual(response.json()["invalidParams"][0]["code"], "required") def test_get_locations_returns_403_when_no_active_sessions(self): self._clear_session() @@ -156,8 +156,10 @@ def test_get_dates_returns_400_when_missing_query_params(self): for query_param in [{}, {"product_id": 79}, {"location_id": 1}]: with self.subTest(query_param=query_param): response = self.client.get(self.endpoint, query_param) - self.assertEqual(response.status_code, 200) - self.assertEqual(response.json(), []) + self.assertEqual(response.status_code, 400) + self.assertEqual( + response.json()["invalidParams"][0]["code"], "required" + ) def test_get_dates_returns_403_when_no_active_sessions(self): self._clear_session() @@ -232,8 +234,10 @@ def test_get_times_returns_400_when_missing_query_params(self): ]: with self.subTest(query_param=query_param): response = self.client.get(self.endpoint, query_param) - self.assertEqual(response.status_code, 200) - self.assertEqual(response.json(), []) + self.assertEqual(response.status_code, 400) + self.assertEqual( + response.json()["invalidParams"][0]["code"], "required" + ) def test_get_times_returns_403_when_no_active_sessions(self): self._clear_session() diff --git a/src/openforms/appointments/contrib/qmatic/tests/test_plugin.py b/src/openforms/appointments/contrib/qmatic/tests/test_plugin.py index ec98262675..5e94a00b21 100644 --- a/src/openforms/appointments/contrib/qmatic/tests/test_plugin.py +++ b/src/openforms/appointments/contrib/qmatic/tests/test_plugin.py @@ -15,7 +15,7 @@ ) from openforms.utils.tests.logging import disable_logging -from ....base import AppointmentDetails, Customer, Location, Product +from ....base import AppointmentDetails, CustomerDetails, Location, Product from ....core import book from ....exceptions import ( AppointmentCreateFailed, @@ -247,7 +247,12 @@ def test_create_appointment(self, m): location = Location( identifier="f364d92b7fa07a48c4ecc862de30c47", name="Branch 1" ) - client = Customer(last_name="Doe", birthdate=date(1980, 1, 1)) + client = CustomerDetails( + details={ + CustomerFields.last_name: "Doe", + CustomerFields.birthday: "1980-01-01", + } + ) day = datetime(2016, 12, 6, 9, 0, 0) m.get( @@ -529,7 +534,12 @@ def test_get_times_unexpected_exception(self, m): def test_create_appointment_failure(self, m): product = Product(identifier="1", code="PASAAN", name="Paspoort aanvraag") location = Location(identifier="1", name="Maykin Media") - client = Customer(last_name="Doe", birthdate=date(1980, 1, 1)) + client = CustomerDetails( + details={ + CustomerFields.last_name: "Doe", + CustomerFields.birthday: "1980-01-01", + } + ) start_at = timezone.make_aware(datetime(2021, 8, 23, 6, 0, 0)) m.get( f"{self.api_root}v1/branches/1", @@ -576,7 +586,12 @@ def test_create_appointment_failure(self, m): def test_create_appointment_unexpected_exception(self, m): product = Product(identifier="1", code="PASAAN", name="Paspoort aanvraag") location = Location(identifier="1", name="Maykin Media") - client = Customer(last_name="Doe", birthdate=date(1980, 1, 1)) + client = CustomerDetails( + details={ + CustomerFields.last_name: "Doe", + CustomerFields.birthday: "1980-01-01", + } + ) start_at = datetime(2021, 8, 23, 6, 0, 0).replace(tzinfo=timezone.utc) m.get( f"{self.api_root}v1/branches/1", diff --git a/src/openforms/appointments/management/commands/appointment.py b/src/openforms/appointments/management/commands/appointment.py index c602f50fbb..abe5dac58a 100644 --- a/src/openforms/appointments/management/commands/appointment.py +++ b/src/openforms/appointments/management/commands/appointment.py @@ -5,6 +5,7 @@ from django.core.management.base import CommandError from django.db.models import Q +from openforms.appointments.base import CustomerDetails from openforms.submissions.models import Submission from ...base import CustomerDetails diff --git a/src/openforms/appointments/tests/test_admin.py b/src/openforms/appointments/tests/test_admin.py index b01a871218..62fc10a9cd 100644 --- a/src/openforms/appointments/tests/test_admin.py +++ b/src/openforms/appointments/tests/test_admin.py @@ -52,7 +52,7 @@ class TestPlugin(DemoAppointment): @disable_admin_mfa() class AppointmentInfoAdminTests(WebTest): @freeze_time("2021-11-26T17:00:00+01:00") - def test_cancel_and_change_links_only_for_superuser(self): + def test_cancel_link_only_for_superuser(self): normal, staff = [ UserFactory.create(user_permissions=["view_appointmentinfo"]), StaffUserFactory.create(user_permissions=["view_appointmentinfo"]), @@ -84,34 +84,7 @@ def test_cancel_and_change_links_only_for_superuser(self): self.assertFalse(object_actions_col) @freeze_time("2021-11-26T17:00:00+01:00") - def test_cancel_and_change_links_legacy(self): - user = SuperUserFactory.create() - # appointment in the past - AppointmentInfoFactory.create( - registration_ok=True, start_time="2021-11-01T17:00:00+01:00" - ) - # appointment in the future - AppointmentInfoFactory.create( - registration_ok=True, start_time="2021-11-30T17:00:00+01:00" - ) - - changelist = self.app.get( - reverse("admin:appointments_appointmentinfo_changelist"), user=user - ) - - self.assertEqual(changelist.status_code, 200) - object_actions_col = changelist.pyquery(".field-get_object_actions") - - # future appointment - app1_links = object_actions_col.eq(0).find("a") - self.assertEqual(len(app1_links), 2) - - # past appointment - app2_links = object_actions_col.eq(1).find("a") - self.assertEqual(len(app2_links), 0) - - @freeze_time("2021-11-26T17:00:00+01:00") - def test_cancel_and_change_links(self): + def test_cancel_link(self): user = SuperUserFactory.create() # appointment in the past diff --git a/src/openforms/appointments/tests/test_api_products.py b/src/openforms/appointments/tests/test_api_products.py index 9863111f99..0f0eb05a83 100644 --- a/src/openforms/appointments/tests/test_api_products.py +++ b/src/openforms/appointments/tests/test_api_products.py @@ -65,6 +65,5 @@ def test_list_products_with_existing_product_invalid_query_param(self): response = self.client.get(self.endpoint, {"product_id": [""]}) - # XXX in 3.0, this will become HTTP 400 - self.assertEqual(response.status_code, 200) - self.assertEqual(response.json(), []) + self.assertEqual(response.status_code, 400) + self.assertEqual(response.json()["invalidParams"][0]["code"], "blank") diff --git a/src/openforms/appointments/tests/test_base.py b/src/openforms/appointments/tests/test_base.py index c3d208250a..bbb069c61f 100644 --- a/src/openforms/appointments/tests/test_base.py +++ b/src/openforms/appointments/tests/test_base.py @@ -32,20 +32,3 @@ def test_get_cancel_link(self): ) cancel_url = f"https://example.com{cancel_path}" self.assertEqual(cancel_url, result) - - @override_settings(BASE_URL="https://example.com/") - def test_get_change_link(self): - submission = SubmissionFactory.create(completed=True) - AppointmentInfoFactory.create(submission=submission, registration_ok=True) - - result = self.plugin.get_change_link(submission) - - change_path = reverse( - "appointments:appointments-verify-change-appointment-link", - kwargs={ - "token": submission_appointment_token_generator.make_token(submission), - "submission_uuid": submission.uuid, - }, - ) - change_url = f"https://example.com{change_path}" - self.assertEqual(change_url, result) diff --git a/src/openforms/appointments/tests/test_booking_appointment.py b/src/openforms/appointments/tests/test_booking_appointment.py index b3c474aacb..c6efb77af4 100644 --- a/src/openforms/appointments/tests/test_booking_appointment.py +++ b/src/openforms/appointments/tests/test_booking_appointment.py @@ -1,6 +1,6 @@ import os import sys -from datetime import datetime, timedelta +from datetime import datetime from unittest.mock import patch from django.test import TestCase @@ -21,11 +21,7 @@ ) from ..models import AppointmentInfo from ..registry import Registry -from .factories import ( - AppointmentFactory, - AppointmentInfoFactory, - AppointmentProductFactory, -) +from .factories import AppointmentFactory, AppointmentProductFactory register = Registry() register("demo")(DemoAppointment) @@ -155,48 +151,3 @@ def test_plugin_invocation(self): ), remarks="", ) - - def test_cancels_previous_appointment(self): - new_completed_on = timezone.now() - timedelta(hours=1) - # new submission, to replace the previous one - submission = SubmissionFactory.create( - form__is_appointment_form=True, - has_previous_submission=True, - previous_submission__completed=True, - previous_submission__completed_on=new_completed_on - timedelta(hours=12), - ) - AppointmentFactory.create(submission=submission, plugin="demo") - # set the data of the previous submission - AppointmentFactory.create( - submission=submission.previous_submission, plugin="demo" - ) - AppointmentInfoFactory.create( - submission=submission.previous_submission, - registration_ok=True, - appointment_id="98765", - ) - - with patch("openforms.appointments.core.register", new=register): - with supress_output(sys.stdout, os.devnull): - book_for_submission(submission) - - info_by_id = { - info.appointment_id: info for info in AppointmentInfo.objects.all() - } - with self.subTest("New submissions/appointment"): - self.assertIn("test 1", info_by_id) - self.assertEqual( - info_by_id["test 1"].status, AppointmentDetailsStatus.success - ) - - with self.subTest("Cancelled submission/appointment"): - self.assertIn("98765", info_by_id) - self.assertEqual( - info_by_id["98765"].status, AppointmentDetailsStatus.cancelled - ) - - with self.subTest("Audit logging"): - log_records = TimelineLogProxy.objects.all() - events = {lr.event for lr in log_records} - self.assertIn("appointment_cancel_start", events) - self.assertIn("appointment_cancel_success", events) diff --git a/src/openforms/appointments/tests/test_confirmation_emails.py b/src/openforms/appointments/tests/test_confirmation_emails.py index 260fb818c8..85a2cf0024 100644 --- a/src/openforms/appointments/tests/test_confirmation_emails.py +++ b/src/openforms/appointments/tests/test_confirmation_emails.py @@ -270,7 +270,7 @@ def test_appointment_data_present_in_confirmation_email(self): self.assertTagWithTextIn("td", "Email", message_html) self.assertTagWithTextIn("td", "austin@powers.net", message_html) - def test_cancel_and_change_instructions(self): + def test_cancel_instructions(self): appointment = AppointmentFactory.create( plugin="with-email", submission__language_code="nl", @@ -293,12 +293,9 @@ def test_cancel_and_change_instructions(self): plugin = register["with-email"] cancel_link = plugin.get_cancel_link(appointment.submission) - change_link = plugin.get_change_link(appointment.submission) with self.subTest(type="HTML"): self.assertIn(cancel_link, message_html) - self.assertNotIn(change_link, message_html) with self.subTest(type="plain text"): self.assertIn(cancel_link, message_text) - self.assertNotIn(change_link, message_text) diff --git a/src/openforms/appointments/tests/test_tasks_appointments.py b/src/openforms/appointments/tests/test_tasks_appointments.py deleted file mode 100644 index 60d1e3bb16..0000000000 --- a/src/openforms/appointments/tests/test_tasks_appointments.py +++ /dev/null @@ -1,148 +0,0 @@ -from unittest.mock import patch - -from django.test import TestCase - -from ..exceptions import AppointmentRegistrationFailed -from ..tasks import maybe_register_appointment -from .factories import AppointmentInfoFactory, SubmissionFactory - - -class LegacyAppointmentRegistrationTaskTests(TestCase): - def test_happy_flow(self): - submission = SubmissionFactory.create(completed=True) - - with patch( - "openforms.appointments.tasks.book_appointment_for_submission" - ) as mock_book: - maybe_register_appointment(submission.id) - - mock_book.assert_called_once() - - submission.refresh_from_db() - self.assertFalse(submission.needs_on_completion_retry) - - def test_appointment_registration_fails(self): - submission = SubmissionFactory.create(completed=True) - - with patch( - "openforms.appointments.tasks.book_appointment_for_submission" - ) as mock_book: - mock_book.side_effect = AppointmentRegistrationFailed("Failed") - with self.assertRaises(AppointmentRegistrationFailed): - maybe_register_appointment(submission.id) - - mock_book.assert_called_once() - - submission.refresh_from_db() - # NO automatic retry - user gets feedback and needs to correct/retry - self.assertFalse(submission.needs_on_completion_retry) - - def test_no_appointment_registered_yet(self): - submission = SubmissionFactory.create(completed=True) - - with patch( - "openforms.appointments.tasks.book_appointment_for_submission" - ) as mock_book: - maybe_register_appointment(submission.id) - - mock_book.assert_called_once_with(submission) - - def test_appointment_was_already_registered(self): - appointment_info = AppointmentInfoFactory.create( - submission__completed=True, - registration_ok=True, - ) - - with patch( - "openforms.appointments.tasks.book_appointment_for_submission" - ) as mock_book: - maybe_register_appointment(appointment_info.submission.id) - - mock_book.assert_not_called() - - def test_previous_registration_failed(self): - appointment_info = AppointmentInfoFactory.create( - submission__completed=True, - registration_failed=True, - ) - - with patch( - "openforms.appointments.tasks.book_appointment_for_submission" - ) as mock_book: - maybe_register_appointment(appointment_info.submission.id) - - mock_book.assert_called_once_with(appointment_info.submission) - - -class AppointmentRegistrationTaskTests(TestCase): - def test_happy_flow(self): - submission = SubmissionFactory.create( - completed=True, form__is_appointment_form=True - ) - - with patch("openforms.appointments.tasks.book_for_submission") as mock_book: - maybe_register_appointment(submission.id) - - mock_book.assert_called_once() - - submission.refresh_from_db() - self.assertFalse(submission.needs_on_completion_retry) - - def test_form_not_marked_as_appointment_form(self): - submission = SubmissionFactory.create( - completed=True, form__is_appointment_form=False - ) - with patch( - "openforms.appointments.tasks.book_appointment_for_submission" - ) as mock_legacy_book: - maybe_register_appointment(submission.id) - - mock_legacy_book.assert_called_once_with(submission) - - def test_appointment_registration_fails(self): - submission = SubmissionFactory.create( - completed=True, form__is_appointment_form=True - ) - - with patch("openforms.appointments.tasks.book_for_submission") as mock_book: - mock_book.side_effect = AppointmentRegistrationFailed("Failed") - with self.assertRaises(AppointmentRegistrationFailed): - maybe_register_appointment(submission.id) - - mock_book.assert_called_once() - - submission.refresh_from_db() - # NO automatic retry - user gets feedback and needs to correct/retry - self.assertFalse(submission.needs_on_completion_retry) - - def test_no_appointment_registered_yet(self): - submission = SubmissionFactory.create( - completed=True, form__is_appointment_form=True - ) - - with patch("openforms.appointments.tasks.book_for_submission") as mock_book: - maybe_register_appointment(submission.id) - - mock_book.assert_called_once_with(submission=submission) - - def test_appointment_was_already_registered(self): - appointment_info = AppointmentInfoFactory.create( - submission__completed=True, - registration_ok=True, - ) - - with patch("openforms.appointments.tasks.book_for_submission") as mock_book: - maybe_register_appointment(appointment_info.submission.id) - - mock_book.assert_not_called() - - def test_previous_registration_failed(self): - appointment_info = AppointmentInfoFactory.create( - submission__completed=True, - registration_failed=True, - ) - - with patch("openforms.appointments.tasks.book_for_submission") as mock_book: - maybe_register_appointment(appointment_info.submission.id) - - mock_book.assert_called_once_with(submission=appointment_info.submission) diff --git a/src/openforms/appointments/tests/test_utils.py b/src/openforms/appointments/tests/test_utils.py index 775c8213b2..478482b410 100644 --- a/src/openforms/appointments/tests/test_utils.py +++ b/src/openforms/appointments/tests/test_utils.py @@ -1,605 +1,6 @@ -from datetime import timedelta - from django.test import TestCase -from django.utils import timezone -from django.utils.translation import gettext as _ - -import requests_mock -from freezegun import freeze_time - -from openforms.forms.tests.factories import ( - FormDefinitionFactory, - FormFactory, - FormStepFactory, -) -from openforms.logging.models import TimelineLogProxy -from openforms.submissions.tests.factories import ( - SubmissionFactory, - SubmissionStepFactory, -) - -from ..constants import AppointmentDetailsStatus -from ..contrib.jcc.tests.test_plugin import mock_response -from ..exceptions import AppointmentCreateFailed, AppointmentRegistrationFailed -from ..models import AppointmentInfo -from ..utils import ( - book_appointment_for_submission, - cancel_previous_submission_appointment, - create_base64_qrcode, - find_first_appointment_step, - get_formatted_phone_number, -) -from .factories import AppointmentInfoFactory -from .utils import setup_jcc - - -# Deprecated/legacy tests -class BookAppointmentForSubmissionTest(TestCase): - @classmethod - def setUpTestData(cls): - super().setUpTestData() - - setup_jcc() - - def test_creating_appointment_with_no_appointment_information_does_nothing(self): - submission = SubmissionFactory.create() - book_appointment_for_submission(submission) - submission.refresh_from_db() - self.assertFalse(AppointmentInfo.objects.exists()) - self.assertFalse(TimelineLogProxy.objects.exists()) - - def test_appointment_step_not_applicable(self): - form = FormFactory.create() - step = FormStepFactory.create( - form=form, - form_definition__configuration={ - "display": "form", - "components": [ - { - "key": "product", - "type": "textfield", - "appointments": {"showProducts": True}, - "label": "Product", - }, - { - "key": "location", - "type": "textfield", - "appointments": {"showLocations": True}, - "label": "Location", - }, - { - "key": "time", - "type": "textfield", - "appointments": {"showTimes": True}, - "label": "Time", - }, - ], - }, - ) - submission = SubmissionFactory.create(form=form) - SubmissionStepFactory.create( - submission=submission, - data={}, - form_step=step, - ) - - book_appointment_for_submission(submission) - self.assertFalse(AppointmentInfo.objects.exists()) - self.assertFalse(TimelineLogProxy.objects.exists()) - - def test_creating_appointment_with_missing_or_not_filled_in_appointment_information_adds_error_message( - self, - ): - form = FormFactory.create() - form_definition_1 = FormDefinitionFactory.create( - configuration={ - "display": "form", - "components": [ - { - "key": "product", - "type": "textfield", - "appointments": {"showProducts": True}, - "label": "Product", - }, - { - "key": "time", - "type": "textfield", - "appointments": {"showTimes": True}, - "label": "Time", - }, - ], - } - ) - form_definition_2 = FormDefinitionFactory.create( - configuration={ - "display": "form", - "components": [ - { - "key": "lastName", - "type": "textfield", - "appointments": {"lastName": True}, - "label": "Last Name", - }, - { - "key": "birthDate", - "type": "textfield", - "appointments": {"birthDate": True}, - "label": "Date of Birth", - }, - ], - } - ) - form_step_1 = FormStepFactory.create( - form=form, form_definition=form_definition_1 - ) - form_step_2 = FormStepFactory.create( - form=form, form_definition=form_definition_2 - ) - submission = SubmissionFactory.create(form=form) - SubmissionStepFactory.create( - submission=submission, - data={ - "product": {"identifier": "79", "name": "Paspoort"}, - "time": "2021-08-25T17:00:00", - }, - form_step=form_step_1, - ) - SubmissionStepFactory.create( - submission=submission, - data={ - "lastName": "Maykin", - "birthDate": "", - }, - form_step=form_step_2, - ) - - with self.assertRaises(AppointmentRegistrationFailed): - book_appointment_for_submission(submission) - - info = AppointmentInfo.objects.filter( - submission=submission, - status=AppointmentDetailsStatus.missing_info, - ).get() - - self.assertEqual( - info.error_information, - _("The following appointment fields should be filled out: {fields}").format( - fields="Date of Birth, locationIDAndName" - ), - ) - self.assertEqual( - TimelineLogProxy.objects.filter( - template="logging/events/appointment_register_skip.txt" - ).count(), - 1, - ) - - @requests_mock.Mocker() - def test_creating_appointment_properly_creates_appointment_and_adds_appointment_information( - self, m - ): - form = FormFactory.create() - form_definition_1 = FormDefinitionFactory.create( - configuration={ - "display": "form", - "components": [ - { - "key": "product", - "type": "textfield", - "appointments": {"showProducts": True}, - "label": "Product", - }, - { - "key": "location", - "type": "textfield", - "appointments": {"showLocations": True}, - "label": "Location", - }, - { - "key": "time", - "type": "textfield", - "appointments": {"showTimes": True}, - "label": "Time", - }, - ], - } - ) - form_definition_2 = FormDefinitionFactory.create( - configuration={ - "display": "form", - "components": [ - { - "key": "lastName", - "type": "textfield", - "appointments": {"lastName": True}, - "label": "Last Name", - }, - { - "key": "birthDate", - "type": "textfield", - "appointments": {"birthDate": True}, - "label": "Date of Birth", - }, - ], - } - ) - form_step_1 = FormStepFactory.create( - form=form, form_definition=form_definition_1 - ) - form_step_2 = FormStepFactory.create( - form=form, form_definition=form_definition_2 - ) - submission = SubmissionFactory.create(form=form) - SubmissionStepFactory.create( - submission=submission, - data={ - "product": {"identifier": "79", "name": "Paspoort"}, - "location": {"identifier": "1", "name": "Amsterdam"}, - "time": "2021-08-25T17:00:00+02:00", - }, - form_step=form_step_1, - ) - SubmissionStepFactory.create( - submission=submission, - data={ - "lastName": "Maykin", - "birthDate": "1990-08-01", - }, - form_step=form_step_2, - ) - - m.post( - "http://example.com/soap11", - text=mock_response("bookGovAppointmentResponse.xml"), - ) - - book_appointment_for_submission(submission) - self.assertTrue( - AppointmentInfo.objects.filter( - appointment_id="1234567890", - submission=submission, - status=AppointmentDetailsStatus.success, - ).exists() - ) - self.assertEqual( - TimelineLogProxy.objects.filter( - template="logging/events/appointment_register_start.txt" - ).count(), - 1, - ) - self.assertEqual( - TimelineLogProxy.objects.filter( - template="logging/events/appointment_register_success.txt" - ).count(), - 1, - ) - - @freeze_time("2021-08-21T18:00:00+02:00") - @requests_mock.Mocker() - def test_creating_appointment_deletes_previous_appointment_when_one_exists(self, m): - new_completed_on = timezone.now() - timedelta(hours=1) - base_data = { - "product": {"identifier": "79", "name": "Paspoort"}, - "location": {"identifier": "1", "name": "Amsterdam"}, - "lastName": "Maykin", - "birthDate": "1990-08-01", - } - submission = SubmissionFactory.from_components( - completed=True, - completed_on=new_completed_on, - components_list=[ - { - "key": "product", - "type": "textfield", - "appointments": {"showProducts": True}, - "label": "Product", - }, - { - "key": "location", - "type": "textfield", - "appointments": {"showLocations": True}, - "label": "Location", - }, - { - "key": "time", - "type": "textfield", - "appointments": {"showTimes": True}, - "label": "Time", - }, - { - "key": "lastName", - "type": "textfield", - "appointments": {"lastName": True}, - "label": "Last Name", - }, - { - "key": "birthDate", - "type": "textfield", - "appointments": {"birthDate": True}, - "label": "Date of Birth", - }, - ], - submitted_data={**base_data, "time": "2021-08-26T17:00:00+02:00"}, - has_previous_submission=True, - previous_submission__completed=True, - previous_submission__completed_on=new_completed_on - timedelta(hours=12), - ) - - # set the data of the previous submission - appointment_info = AppointmentInfoFactory.create( - submission=submission.previous_submission, - registration_ok=True, - appointment_id="98765", - ) - SubmissionStepFactory.create( - submission=submission.previous_submission, - form_step=submission.form.formstep_set.get(), - data={**base_data, "time": "2021-08-25T17:00:00+02:00"}, - ) - m.post( - "http://example.com/soap11", - [ - {"text": mock_response("bookGovAppointmentResponse.xml")}, - {"text": mock_response("deleteGovAppointmentResponse.xml")}, - ], - ) - - book_appointment_for_submission(submission) - - self.assertTrue( - AppointmentInfo.objects.filter( - appointment_id="1234567890", - submission=submission, - status=AppointmentDetailsStatus.success, - ).exists() - ) - - appointment_info.refresh_from_db() - self.assertEqual(appointment_info.status, AppointmentDetailsStatus.cancelled) - self.assertEqual( - TimelineLogProxy.objects.filter( - template="logging/events/appointment_register_start.txt" - ).count(), - 1, - ) - self.assertEqual( - TimelineLogProxy.objects.filter( - template="logging/events/appointment_register_success.txt" - ).count(), - 1, - ) - - @requests_mock.Mocker() - def test_failed_creating_appointment_adds_error_message_to_submission(self, m): - form = FormFactory.create() - form_definition_1 = FormDefinitionFactory.create( - configuration={ - "display": "form", - "components": [ - { - "key": "product", - "type": "textfield", - "appointments": {"showProducts": True}, - "label": "Product", - }, - { - "key": "location", - "type": "textfield", - "appointments": {"showLocations": True}, - "label": "Location", - }, - { - "key": "time", - "type": "textfield", - "appointments": {"showTimes": True}, - "label": "Time", - }, - ], - } - ) - form_definition_2 = FormDefinitionFactory.create( - configuration={ - "display": "form", - "components": [ - { - "key": "lastName", - "type": "textfield", - "appointments": {"lastName": True}, - "label": "Last Name", - }, - { - "key": "birthDate", - "type": "textfield", - "appointments": {"birthDate": True}, - "label": "Date of Birth", - }, - ], - } - ) - form_step_1 = FormStepFactory.create( - form=form, form_definition=form_definition_1 - ) - form_step_2 = FormStepFactory.create( - form=form, form_definition=form_definition_2 - ) - submission = SubmissionFactory.create(form=form) - SubmissionStepFactory.create( - submission=submission, - data={ - "product": {"identifier": "79", "name": "Paspoort"}, - "location": {"identifier": "1", "name": "Amsterdam"}, - "time": "2021-08-25T17:00:00+02:00", - }, - form_step=form_step_1, - ) - SubmissionStepFactory.create( - submission=submission, - data={ - "lastName": "Maykin", - "birthDate": "1990-08-01", - }, - form_step=form_step_2, - ) - - m.post( - "http://example.com/soap11", - exc=AppointmentCreateFailed, - ) - - with self.assertRaises(AppointmentRegistrationFailed): - book_appointment_for_submission(submission) - - self.assertTrue( - AppointmentInfo.objects.filter( - submission=submission, - status=AppointmentDetailsStatus.failed, - ).exists() - ) - self.assertEqual( - TimelineLogProxy.objects.filter( - template="logging/events/appointment_register_start.txt" - ).count(), - 1, - ) - self.assertEqual( - TimelineLogProxy.objects.filter( - template="logging/events/appointment_register_failure.txt" - ).count(), - 1, - ) - - @requests_mock.Mocker() - def test_failed_creating_appointment_when_submission_previously_failed(self, m): - form = FormFactory.create() - form_definition_1 = FormDefinitionFactory.create( - configuration={ - "display": "form", - "components": [ - { - "key": "product", - "type": "textfield", - "appointments": {"showProducts": True}, - "label": "Product", - }, - { - "key": "location", - "type": "textfield", - "appointments": {"showLocations": True}, - "label": "Location", - }, - { - "key": "time", - "type": "textfield", - "appointments": {"showTimes": True}, - "label": "Time", - }, - ], - } - ) - form_definition_2 = FormDefinitionFactory.create( - configuration={ - "display": "form", - "components": [ - { - "key": "lastName", - "type": "textfield", - "appointments": {"lastName": True}, - "label": "Last Name", - }, - { - "key": "birthDate", - "type": "textfield", - "appointments": {"birthDate": True}, - "label": "Date of Birth", - }, - ], - } - ) - form_step_1 = FormStepFactory.create( - form=form, form_definition=form_definition_1 - ) - form_step_2 = FormStepFactory.create( - form=form, form_definition=form_definition_2 - ) - submission = SubmissionFactory.create(form=form) - first_appointment_info = AppointmentInfoFactory.create( - status=AppointmentDetailsStatus.failed, - error_information="Failed to make appointment", - submission=submission, - ) - SubmissionStepFactory.create( - submission=submission, - data={ - "product": {"identifier": "79", "name": "Paspoort"}, - "location": {"identifier": "1", "name": "Amsterdam"}, - "time": "2021-08-25T17:00:00+02:00", - }, - form_step=form_step_1, - ) - SubmissionStepFactory.create( - submission=submission, - data={ - "lastName": "Maykin", - "birthDate": "1990-08-01", - }, - form_step=form_step_2, - ) - - m.post( - "http://example.com/soap11", - exc=AppointmentCreateFailed, - ) - - with self.assertRaises(AppointmentRegistrationFailed): - book_appointment_for_submission(submission) - - submission.refresh_from_db() - second_appointment_info = submission.appointment_info - - self.assertNotEqual(first_appointment_info.pk, second_appointment_info.pk) - - self.assertEqual( - TimelineLogProxy.objects.filter( - template="logging/events/appointment_register_start.txt" - ).count(), - 1, - ) - self.assertEqual( - TimelineLogProxy.objects.filter( - template="logging/events/appointment_register_failure.txt" - ).count(), - 1, - ) - - def test_cancelling_previous_appointments_nothing_to_cancel(self): - submission1 = SubmissionFactory.create(has_previous_submission=True) - AppointmentInfoFactory.create( - submission=submission1.previous_submission, - registration_failed=True, - ) - submission2 = SubmissionFactory.create(has_previous_submission=True) - AppointmentInfoFactory.create( - submission=submission2.previous_submission, - registration_ok=True, - appointment_id="", - ) - submissions = [ - ("no previous", SubmissionFactory.create(has_previous_submission=False)), - ( - "no appointment info", - SubmissionFactory.create(has_previous_submission=True), - ), - ("failed registration", submission1), - ("succeeded registration but no id", submission2), - ] - - for label, submission in submissions: - with self.subTest(type=label): - with requests_mock.Mocker() as m: - cancel_previous_submission_appointment(submission) - - self.assertFalse(m.called) +from ..utils import create_base64_qrcode, get_formatted_phone_number class UtilsTests(TestCase): @@ -626,43 +27,6 @@ def test_create_base64_qrcode(self): self.assertEqual(result, expected) - def test_find_first_appointment_step_returns_None_for_no_appointment_data(self): - submission = SubmissionFactory.from_components( - components_list=[ - { - "type": "textfield", - "key": "placeholder", - } - ] - ) - - step = find_first_appointment_step(submission.form) - - self.assertIsNone(step) - - def test_find_first_appointment_step_finds_correct_step(self): - submission = SubmissionFactory.from_components( - components_list=[ - { - "key": "product", - "type": "textfield", - "appointments": {"showProducts": True}, - "label": "Product", - }, - { - "key": "time", - "type": "textfield", - "appointments": {"showTimes": True}, - "label": "Time", - }, - ] - ) - - step = find_first_appointment_step(submission.form) - - self.assertIsNotNone(step) - self.assertEqual(step, submission.submissionstep_set.get().form_step) - class GetFormattedPhoneNumberTest(TestCase): def test_get_formatted_phone_number_returns_expected_format(self): diff --git a/src/openforms/appointments/tests/test_views.py b/src/openforms/appointments/tests/test_views.py index f14b713419..926e5e0d43 100644 --- a/src/openforms/appointments/tests/test_views.py +++ b/src/openforms/appointments/tests/test_views.py @@ -1,6 +1,5 @@ import uuid from datetime import datetime, timezone -from decimal import Decimal from django.test import TestCase from django.urls import reverse @@ -10,20 +9,12 @@ from openforms.authentication.contrib.digid.constants import DIGID_DEFAULT_LOA from openforms.authentication.service import FORM_AUTH_SESSION_KEY, AuthAttribute -from openforms.forms.tests.factories import FormFactory from openforms.frontend.tests import FrontendRedirectMixin -from openforms.logging.models import TimelineLogProxy -from openforms.payments.constants import PaymentStatus -from openforms.payments.tests.factories import SubmissionPaymentFactory from openforms.submissions.constants import SUBMISSIONS_SESSION_KEY -from openforms.submissions.models import Submission -from openforms.submissions.tests.factories import ( - SubmissionFactory, - SubmissionStepFactory, -) +from openforms.submissions.tests.factories import SubmissionFactory from ..tokens import submission_appointment_token_generator -from .factories import AppointmentFactory, AppointmentInfoFactory +from .factories import AppointmentInfoFactory @freeze_time("2021-07-15T21:15:00Z") @@ -338,546 +329,3 @@ def test_invalid_auth_value_raises_exception(self): self.assertEqual(403, response.status_code) self.assertNotIn(SUBMISSIONS_SESSION_KEY, self.client.session) - - -@freeze_time("2021-07-15T21:15:00Z") -class VerifyChangeAppointmentLinkViewTests(FrontendRedirectMixin, TestCase): - def test_good_token_and_submission_redirect_and_add_submission_to_session(self): - submission = SubmissionFactory.from_components( - completed=True, - components_list=[ - { - "key": "product", - "appointments": {"showProducts": True}, - "label": "Product", - }, - { - "key": "time", - "appointments": {"showTimes": True}, - "label": "Time", - }, - ], - submitted_data={ - "product": {"identifier": "79", "name": "Paspoort"}, - "time": "2021-08-25T17:00:00", - }, - form_url="http://maykinmedia.nl/myform/", - bsn="000000000", - ) - form_definition = submission.form.formstep_set.get().form_definition - AppointmentInfoFactory.create( - submission=submission, - registration_ok=True, - start_time=datetime(2021, 7, 21, 12, 00, 00, tzinfo=timezone.utc), - ) - - endpoint = reverse( - "appointments:appointments-verify-change-appointment-link", - kwargs={ - "token": submission_appointment_token_generator.make_token(submission), - "submission_uuid": submission.uuid, - }, - ) - # Add form_auth to session, as the authentication plugin would do it - session = self.client.session - session[FORM_AUTH_SESSION_KEY] = { - "plugin": "digid", - "attribute": AuthAttribute.bsn, - "value": "000000000", - "loa": DIGID_DEFAULT_LOA, - } - session.save() - - # one day after token generation - with freeze_time("2021-07-16T21:15:00Z"): - response = self.client.get(endpoint) - - new_submission = Submission.objects.exclude(id=submission.id).get() - # after initiating change, we expect the bsn to be stored in plain text (again) - self.assertEqual(new_submission.auth_info.value, "000000000") - - self.assertRedirectsToFrontend( - response, - frontend_base_url=submission.form_url, - action="resume", - action_params={ - "step_slug": form_definition.slug, - "submission_uuid": str(new_submission.uuid), - }, - fetch_redirect_response=False, - ) - - # Assert new submission was created - self.assertEqual(Submission.objects.count(), 2) - # Assert old submission not stored in session - self.assertNotIn( - str(submission.uuid), self.client.session[SUBMISSIONS_SESSION_KEY] - ) - # Assert new submission is stored in session - self.assertIn( - str(new_submission.uuid), self.client.session[SUBMISSIONS_SESSION_KEY] - ) - - def test_403_response_with_unfound_submission(self): - endpoint = reverse( - "appointments:appointments-verify-change-appointment-link", - kwargs={ - "token": "irrelevant", - "submission_uuid": uuid.uuid4(), - }, - ) - - response = self.client.get(endpoint) - - self.assertEqual(response.status_code, 403) - - def test_403_response_with_bad_token(self): - submission = SubmissionFactory.create(completed=True) - AppointmentInfoFactory.create( - submission=submission, - registration_ok=True, - start_time=datetime(2021, 7, 21, 12, 00, 00, tzinfo=timezone.utc), - ) - - endpoint = reverse( - "appointments:appointments-verify-change-appointment-link", - kwargs={ - "token": "bad", - "submission_uuid": submission.uuid, - }, - ) - - response = self.client.get(endpoint) - - self.assertEqual(response.status_code, 403) - - def test_token_invalid_after_appointment_time(self): - submission = SubmissionFactory.create(completed=True) - AppointmentInfoFactory.create( - submission=submission, - registration_ok=True, - start_time=datetime(2021, 7, 21, 12, 00, 00, tzinfo=timezone.utc), - ) - - endpoint = reverse( - "appointments:appointments-verify-change-appointment-link", - kwargs={ - "token": submission_appointment_token_generator.make_token(submission), - "submission_uuid": submission.uuid, - }, - ) - - with freeze_time("2021-07-22T12:00:00Z"): - response = self.client.get(endpoint) - - self.assertEqual(response.status_code, 403) - - def test_token_valid_on_same_day_appointment(self): - submission = SubmissionFactory.from_components( - completed=True, - components_list=[ - { - "key": "product", - "appointments": {"showProducts": True}, - "label": "Product", - }, - { - "key": "time", - "appointments": {"showTimes": True}, - "label": "Time", - }, - ], - submitted_data={ - "product": {"identifier": "79", "name": "Paspoort"}, - "time": "2021-08-25T17:00:00", - }, - form_url="http://maykinmedia.nl/myform/", - ) - AppointmentInfoFactory.create( - submission=submission, - registration_ok=True, - start_time=datetime(2021, 7, 21, 12, 00, 00, tzinfo=timezone.utc), - ) - - endpoint = reverse( - "appointments:appointments-verify-change-appointment-link", - kwargs={ - "token": submission_appointment_token_generator.make_token(submission), - "submission_uuid": submission.uuid, - }, - ) - - with freeze_time("2021-07-21T11:59:59Z"): - response = self.client.get(endpoint) - - self.assertEqual(response.status_code, 302) - - def test_redirect_to_first_step_when_appointment_form_definition_can_not_be_found( - self, - ): - form = FormFactory.create() - submission = SubmissionFactory.create( - form=form, completed=True, form_url="http://maykinmedia.nl/myform/" - ) - SubmissionStepFactory.create( - form_step__form=form, - form_step__form_definition__slug="step-1", - form_step__form_definition__configuration={ - "display": "form", - "components": [ - { - "key": "name", - "label": "Name", - "type": "textfield", - }, - ], - }, - submission=submission, - data={ - "Name": "Maykin", - }, - ) - SubmissionStepFactory.create( - submission=submission, - form_step__form=form, - form_step__form_definition__slug="step-2", - form_step__form_definition__configuration={ - "display": "form", - "components": [ - { - "key": "product", - "appointments": {"showProducts": False}, - "label": "Product", - "type": "select", - }, - { - "key": "time", - "appointments": {"showTimes": False}, - "label": "Time", - "type": "select", - }, - ], - }, - data={ - "product": {"identifier": "79", "name": "Paspoort"}, - "time": "2021-08-25T17:00:00", - }, - ) - AppointmentInfoFactory.create( - submission=submission, - registration_ok=True, - start_time=datetime(2021, 7, 21, 12, 00, 00, tzinfo=timezone.utc), - ) - - endpoint = reverse( - "appointments:appointments-verify-change-appointment-link", - kwargs={ - "token": submission_appointment_token_generator.make_token(submission), - "submission_uuid": submission.uuid, - }, - ) - - # one day after token generation - with freeze_time("2021-07-16T21:15:00Z"): - response = self.client.get(endpoint) - - new_submission = Submission.objects.exclude(id=submission.id).get() - - self.assertRedirectsToFrontend( - response, - frontend_base_url=submission.form_url, - action="resume", - action_params={ - "step_slug": "step-1", - "submission_uuid": str(new_submission.uuid), - }, - fetch_redirect_response=False, - ) - - def test_redirects_to_auth_if_form_requires_login(self): - submission = SubmissionFactory.create( - form__generate_minimal_setup=True, - form__formstep__form_definition__login_required=True, - auth_info__plugin="digid", - completed=True, - ) - AppointmentInfoFactory.create( - submission=submission, - registration_ok=True, - start_time=datetime(2021, 7, 21, 12, 00, 00, tzinfo=timezone.utc), - ) - - endpoint = reverse( - "appointments:appointments-verify-change-appointment-link", - kwargs={ - "token": submission_appointment_token_generator.make_token(submission), - "submission_uuid": submission.uuid, - }, - ) - expected_redirect_url = furl( - f"http://testserver/auth/{submission.form.slug}/digid/start" - ) - expected_redirect_url.args["next"] = f"http://testserver{endpoint}" - - response = self.client.get(endpoint) - - self.assertRedirects( - response, expected_redirect_url.url, fetch_redirect_response=False - ) - self.assertNotIn(SUBMISSIONS_SESSION_KEY, self.client.session) - - def test_after_successful_auth_redirects_to_form(self): - submission = SubmissionFactory.create( - form__generate_minimal_setup=True, - form__formstep__form_definition__login_required=True, - form__formstep__form_definition__slug="test-step", - auth_info__plugin="digid", - form_url="http://testserver/myform/", - completed=True, - auth_info__value="123456782", - ) - AppointmentInfoFactory.create( - submission=submission, - registration_ok=True, - start_time=datetime(2021, 7, 21, 12, 00, 00, tzinfo=timezone.utc), - ) - - endpoint = reverse( - "appointments:appointments-verify-change-appointment-link", - kwargs={ - "token": submission_appointment_token_generator.make_token(submission), - "submission_uuid": submission.uuid, - }, - ) - - # Add form_auth to session, as the authentication plugin would do it - session = self.client.session - session[FORM_AUTH_SESSION_KEY] = { - "plugin": "digid", - "attribute": AuthAttribute.bsn, - "value": "123456782", - "loa": DIGID_DEFAULT_LOA, - } - session.save() - - response = self.client.get(endpoint) - new_submission = Submission.objects.filter( - previous_submission=submission - ).first() - - self.assertIsNotNone(new_submission) - - self.assertRedirectsToFrontend( - response, - frontend_base_url=submission.form_url, - action="resume", - action_params={ - "step_slug": "test-step", - "submission_uuid": str(new_submission.uuid), - }, - fetch_redirect_response=False, - ) - - self.assertIn(SUBMISSIONS_SESSION_KEY, self.client.session) - self.assertIn( - str(new_submission.uuid), self.client.session[SUBMISSIONS_SESSION_KEY] - ) - - def test_invalid_auth_plugin_raises_exception(self): - submission = SubmissionFactory.create( - form__generate_minimal_setup=True, - form__formstep__form_definition__login_required=True, - form__formstep__form_definition__slug="test-step", - auth_info__plugin="wrong-plugin", - form_url="http://testserver/myform/", - completed=True, - auth_info__value="123456782", - ) - AppointmentInfoFactory.create( - submission=submission, - registration_ok=True, - start_time=datetime(2021, 7, 21, 12, 00, 00, tzinfo=timezone.utc), - ) - - endpoint = reverse( - "appointments:appointments-verify-change-appointment-link", - kwargs={ - "token": submission_appointment_token_generator.make_token(submission), - "submission_uuid": submission.uuid, - }, - ) - - # Add form_auth to session, as the authentication plugin would do it - session = self.client.session - session[FORM_AUTH_SESSION_KEY] = { - "plugin": "digid", - "attribute": AuthAttribute.bsn, - "value": "123456782", - "loa": DIGID_DEFAULT_LOA, - } - session.save() - - response = self.client.get(endpoint) - - self.assertEqual(403, response.status_code) - self.assertNotIn(SUBMISSIONS_SESSION_KEY, self.client.session) - - def test_invalid_auth_attribute_raises_exception(self): - submission = SubmissionFactory.create( - form__generate_minimal_setup=True, - form__formstep__form_definition__login_required=True, - form__formstep__form_definition__slug="test-step", - auth_info__plugin="digid", - form_url="http://testserver/myform/", - completed=True, - auth_info__value="123456782", - auth_info__attribute=AuthAttribute.kvk, - ) - AppointmentInfoFactory.create( - submission=submission, - registration_ok=True, - start_time=datetime(2021, 7, 21, 12, 00, 00, tzinfo=timezone.utc), - ) - - endpoint = reverse( - "appointments:appointments-verify-change-appointment-link", - kwargs={ - "token": submission_appointment_token_generator.make_token(submission), - "submission_uuid": submission.uuid, - }, - ) - - # Add form_auth to session, as the authentication plugin would do it - session = self.client.session - session[FORM_AUTH_SESSION_KEY] = { - "plugin": "digid", - "attribute": AuthAttribute.bsn, - "value": "123456782", - "loa": DIGID_DEFAULT_LOA, - } - session.save() - - response = self.client.get(endpoint) - - self.assertEqual(403, response.status_code) - self.assertNotIn(SUBMISSIONS_SESSION_KEY, self.client.session) - - def test_invalid_auth_value_raises_exception(self): - submission = SubmissionFactory.create( - form__generate_minimal_setup=True, - form__formstep__form_definition__login_required=True, - form__formstep__form_definition__slug="test-step", - auth_info__plugin="digid", - form_url="http://testserver/myform/", - completed=True, - auth_info__value="wrong-bsn", - ) - AppointmentInfoFactory.create( - submission=submission, - registration_ok=True, - start_time=datetime(2021, 7, 21, 12, 00, 00, tzinfo=timezone.utc), - ) - - endpoint = reverse( - "appointments:appointments-verify-change-appointment-link", - kwargs={ - "token": submission_appointment_token_generator.make_token(submission), - "submission_uuid": submission.uuid, - }, - ) - - # Add form_auth to session, as the authentication plugin would do it - session = self.client.session - session[FORM_AUTH_SESSION_KEY] = { - "plugin": "digid", - "attribute": AuthAttribute.bsn, - "value": "123456782", - "loa": DIGID_DEFAULT_LOA, - } - session.save() - - response = self.client.get(endpoint) - - self.assertEqual(403, response.status_code) - self.assertNotIn(SUBMISSIONS_SESSION_KEY, self.client.session) - - def test_change_appointment_details_after_payment(self): - submission = SubmissionFactory.from_components( - with_public_registration_reference=True, - components_list=[ - { - "key": "product", - "appointments": {"showProducts": True}, - "label": "Product", - }, - { - "key": "time", - "appointments": {"showTimes": True}, - "label": "Time", - }, - ], - submitted_data={ - "product": {"identifier": "79", "name": "Paspoort"}, - "time": "2021-08-25T17:00:00", - }, - form_url="http://maykinmedia.nl/myform/", - form__product__price=Decimal("12.34"), - form__payment_backend="test", - ) - submission_payment = SubmissionPaymentFactory.for_submission( - submission, status=PaymentStatus.completed - ) - AppointmentInfoFactory.create( - submission=submission, - registration_ok=True, - start_time=datetime(2021, 7, 21, 12, 00, 00, tzinfo=timezone.utc), - ) - - endpoint = reverse( - "appointments:appointments-verify-change-appointment-link", - kwargs={ - "token": submission_appointment_token_generator.make_token(submission), - "submission_uuid": submission.uuid, - }, - ) - - self.assertTrue(submission.payment_required) - self.assertTrue(submission.payment_user_has_paid) - - # one day after token generation - with freeze_time("2021-07-16T21:15:00Z"): - self.client.get(endpoint) - - new_submission = Submission.objects.exclude(id=submission.id).get() - submission_payment.refresh_from_db() - - self.assertTrue(new_submission.payment_required) - self.assertTrue(new_submission.payment_user_has_paid) - self.assertEqual(submission_payment.submission, new_submission) - self.assertEqual( - TimelineLogProxy.objects.filter( - template="logging/events/transfer_payment_to_submission_copy.txt" - ).count(), - 1, - ) - - def test_change_new_style_appointment(self): - appointment = AppointmentFactory.create( - appointment_info__registration_ok=True, - appointment_info__start_time=datetime( - 2021, 7, 21, 12, 00, 00, tzinfo=timezone.utc - ), - ) - submission = appointment.submission - url = reverse( - "appointments:appointments-verify-change-appointment-link", - kwargs={ - "token": submission_appointment_token_generator.make_token(submission), - "submission_uuid": submission.uuid, - }, - ) - - # one day after token generation - with freeze_time("2021-07-16T21:15:00Z"): - with self.assertRaises(RuntimeError): - self.client.get(url) diff --git a/src/openforms/emails/tests/test_confirmation_email.py b/src/openforms/emails/tests/test_confirmation_email.py index d252905456..4d0b2ee124 100644 --- a/src/openforms/emails/tests/test_confirmation_email.py +++ b/src/openforms/emails/tests/test_confirmation_email.py @@ -274,13 +274,6 @@ def test_appointment_information(self, get_plugin_mock): rendered_content, ) - self.assertInHTML( - '' - + _("Change appointment") - + "", - rendered_content, - ) - def test_appointment_information_with_no_appointment_id(self): submission = SubmissionFactory.create() AppointmentInfoFactory.create( diff --git a/src/openforms/formio/formatters/tests/test_kitchensink.py b/src/openforms/formio/formatters/tests/test_kitchensink.py index 82029675b1..392bc0e4ad 100644 --- a/src/openforms/formio/formatters/tests/test_kitchensink.py +++ b/src/openforms/formio/formatters/tests/test_kitchensink.py @@ -107,23 +107,23 @@ def run_kitchensink_test(self, name_data, name_printable): with self.subTest(f"{label} -> '{value}'"): self.assertEqual(value, text_values[label]) - def test_appointments_formio(self): - configuration = load_json("appointments_components.json") - data = load_json("appointments_data.json") - text_printed = load_json("appointments_printable_text.json") + # def test_appointments_formio(self): + # configuration = load_json("appointments_components.json") + # data = load_json("appointments_data.json") + # text_printed = load_json("appointments_printable_text.json") - # for sanity - self.assertFlatConfiguration(configuration) + # # for sanity + # self.assertFlatConfiguration(configuration) - self.assertEqual(len(text_printed), len(data)) + # self.assertEqual(len(text_printed), len(data)) - submission = SubmissionFactory.from_components( - configuration["components"], submitted_data=data, completed=True - ) + # submission = SubmissionFactory.from_components( + # configuration["components"], submitted_data=data, completed=True + # ) - printable_data = _get_printable_data(submission) - text_values = dict(printable_data) + # printable_data = _get_printable_data(submission) + # text_values = dict(printable_data) - for label, value in text_printed.items(): - with self.subTest(f"{label} -> '{value}'"): - self.assertEqual(value, text_values[label]) + # for label, value in text_printed.items(): + # with self.subTest(f"{label} -> '{value}'"): + # self.assertEqual(value, text_values[label]) diff --git a/src/openforms/submissions/tests/test_models.py b/src/openforms/submissions/tests/test_models.py index 04ccadf8bc..75ab93b98a 100644 --- a/src/openforms/submissions/tests/test_models.py +++ b/src/openforms/submissions/tests/test_models.py @@ -225,112 +225,6 @@ def test_submission_delete_file_uploads_cascade_file_already_gone(self): ) self.assertFalse(attachment.content.storage.exists(attachment.content.path)) - def test_get_merged_appointment_data(self): - form = FormFactory.create() - form_definition_1 = FormDefinitionFactory.create( - configuration={ - "display": "form", - "components": [ - { - "key": "product", - "type": "textfield", - "appointments": {"showProducts": True}, - "label": "Product", - }, - { - "key": "location", - "type": "textfield", - "appointments": {"showLocations": True}, - "label": "Location", - }, - { - "key": "time", - "type": "textfield", - "appointments": {"showTimes": True}, - "label": "Time", - }, - ], - } - ) - form_definition_2 = FormDefinitionFactory.create( - configuration={ - "display": "form", - "components": [ - { - "key": "lastName", - "type": "textfield", - "appointments": {"lastName": True}, - "label": "Last Name", - }, - { - "key": "birthDate", - "type": "date", - "appointments": {"birthDate": True}, - "label": "Date of Birth", - }, - { - "key": "phoneNumber", - "type": "textfield", - "appointments": {"phoneNumber": True}, - "label": "Phone Number", - }, - { - "key": "randomAttribute", - "type": "textfield", - "appointments": {"birthDate": False}, - "label": "Random attribute", - }, - ], - } - ) - form_step_1 = FormStepFactory.create( - form=form, form_definition=form_definition_1 - ) - form_step_2 = FormStepFactory.create( - form=form, form_definition=form_definition_2 - ) - submission = SubmissionFactory.create(form=form) - SubmissionStepFactory.create( - submission=submission, - data={ - "product": {"identifier": "79", "name": "Paspoort"}, - "location": {"identifier": "1", "name": "Amsterdam"}, - "time": "2021-08-25T17:00:00", - }, - form_step=form_step_1, - ) - SubmissionStepFactory.create( - submission=submission, - data={ - "lastName": "Maykin", - "birthDate": "1990-08-01", - "phoneNumber": "+31 20 753 05 23", - "randomAttribute": "This is some random stuff", - }, - form_step=form_step_2, - ) - - self.assertEqual( - submission.get_merged_appointment_data(), - { - "productIDAndName": { - "label": "Product", - "value": {"identifier": "79", "name": "Paspoort"}, - }, - "locationIDAndName": { - "label": "Location", - "value": {"identifier": "1", "name": "Amsterdam"}, - }, - "appStartTime": {"label": "Time", "value": "2021-08-25T17:00:00"}, - "clientLastName": {"label": "Last Name", "value": "Maykin"}, - "clientDateOfBirth": {"label": "Date of Birth", "value": "1990-08-01"}, - "clientPhoneNumber": { - "label": "Phone Number", - "value": "+31 20 753 05 23", - }, - }, - ) - def test_copy_submission(self): submission = SubmissionFactory.create(auth_info__value="bsn1") SubmissionStepFactory.create( @@ -348,7 +242,6 @@ def test_copy_submission(self): self.assertEqual(new_submission.form, submission.form) self.assertEqual(new_submission.form_url, submission.form_url) - self.assertEqual(new_submission.previous_submission, submission) self.assertEqual(new_submission.data, submission.data) self.assertEqual(new_submission.auth_info.value, "bsn1") self.assertEqual(new_submission.auth_info.plugin, "digid") diff --git a/src/openforms/submissions/tests/test_post_submission_event.py b/src/openforms/submissions/tests/test_post_submission_event.py index bcbc50d8ad..499d129c12 100644 --- a/src/openforms/submissions/tests/test_post_submission_event.py +++ b/src/openforms/submissions/tests/test_post_submission_event.py @@ -848,21 +848,6 @@ def test_payment_status_update_retry_flow(self): self.assertEqual(len(mails), 0) self.assertNotEqual(submission.auth_info.value, "111222333") - def test_submission_completed_incomplete_appointment(self): - setup_jcc() - components = FormDefinitionFactory.build(is_appointment=True).configuration[ - "components" - ] - submission = SubmissionFactory.from_components( - completed=True, - form__registration_backend="", - components_list=components, - submitted_data={"product": {"identifier": "79", "name": "Paspoort"}}, - ) - - with self.assertRaises(AppointmentRegistrationFailed): - on_post_submission_event(submission.id, PostSubmissionEvents.on_completion) - def test_cosign_not_required_and_not_filled_in_proceeds_with_registration(self): submission = SubmissionFactory.from_components( components_list=[ diff --git a/src/openforms/submissions/tests/test_tasks_confirmation_emails.py b/src/openforms/submissions/tests/test_tasks_confirmation_emails.py index f386508816..f8c27dd489 100644 --- a/src/openforms/submissions/tests/test_tasks_confirmation_emails.py +++ b/src/openforms/submissions/tests/test_tasks_confirmation_emails.py @@ -477,47 +477,6 @@ def test_completed_submission_after_timeout_with_confirmation_email_when_already # assert that no e-mail was sent self.assertEqual(len(mail.outbox), 0) - @override_settings(DEFAULT_FROM_EMAIL="info@open-forms.nl") - def test_send_confirmation_email_when_appointment_is_changed(self): - submission = SubmissionFactory.from_components( - completed=True, - components_list=[ - { - "key": "email", - "type": "email", - "label": "Email", - "confirmationRecipient": True, - }, - ], - submitted_data={"email": "test@test.nl"}, - has_previous_submission=True, - ) - AppointmentInfoFactory.create( - submission=submission.previous_submission, - status=AppointmentDetailsStatus.cancelled, - ) - # add a second step - SubmissionStepFactory.create( - submission=submission, - form_step__form=submission.form, - data={"foo": "bar"}, - ) - ConfirmationEmailTemplateFactory.create( - form=submission.form, - subject="Confirmation mail", - content="Information filled in: {{foo}}", - ) - - # "execute" the celery task - with override_settings(CELERY_TASK_ALWAYS_EAGER=True): - schedule_emails(submission.id) - - # Verify that email was sent - self.assertEqual(len(mail.outbox), 1) - - message = mail.outbox[0] - self.assertEqual(message.subject, f"Confirmation mail {_('(updated)')}") - def test_template_is_rendered_in_submission_language(self): """ Assert a subset of the components with particularly weird APIs is translated correctly.