From 13bbb2c0456d661deb3294740ebb7904a860f731 Mon Sep 17 00:00:00 2001 From: Alex de Landgraaf Date: Fri, 27 Dec 2024 11:56:39 +0100 Subject: [PATCH] [#2935] Mijn Afspraken: Don't show appoinments from the past --- .../accounts/tests/test_profile_views.py | 6 +++++- .../cms/plugins/tests/test_appointments.py | 9 ++++++--- src/open_inwoner/qmatic/client.py | 6 +++++- src/open_inwoner/qmatic/tests/data.py | 15 +++++++++++++++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/open_inwoner/accounts/tests/test_profile_views.py b/src/open_inwoner/accounts/tests/test_profile_views.py index cc80ac8fae..70edc94070 100644 --- a/src/open_inwoner/accounts/tests/test_profile_views.py +++ b/src/open_inwoner/accounts/tests/test_profile_views.py @@ -11,6 +11,7 @@ import requests_mock from django_webtest import WebTest +from freezegun import freeze_time from pyquery import PyQuery as PQ from webtest import Upload @@ -1483,7 +1484,8 @@ def test_do_not_render_list_if_email_not_verified(self, m): def test_render_list_if_appointments_are_found(self, m): self.data.setUpMocks(m) - response = self.app.get(self.appointments_url, user=self.data.user) + with freeze_time("2020-01-01 00:00"): + response = self.app.get(self.appointments_url, user=self.data.user) self.assertIn(_("Een overzicht van uw afspraken"), response.text) @@ -1491,6 +1493,8 @@ def test_render_list_if_appointments_are_found(self, m): self.assertEqual(len(cards), 2) + self.assertNotIn("Old appointment", response.text) + self.assertEqual(PQ(cards[0]).find(".card__heading-2").text(), "Paspoort") passport_appointment = PQ(cards[0]).find("ul").children() diff --git a/src/open_inwoner/cms/plugins/tests/test_appointments.py b/src/open_inwoner/cms/plugins/tests/test_appointments.py index 4473c378ca..737926bb6a 100644 --- a/src/open_inwoner/cms/plugins/tests/test_appointments.py +++ b/src/open_inwoner/cms/plugins/tests/test_appointments.py @@ -2,6 +2,7 @@ from django.urls import reverse import requests_mock +from freezegun import freeze_time from pyquery import PyQuery as PQ from open_inwoner.cms.tests import cms_tools @@ -19,9 +20,10 @@ def test_plugin(self, m): self.assertTrue(data.user.has_verified_email()) - html, context = cms_tools.render_plugin( - UserAppointmentsPlugin, plugin_data={}, user=data.user - ) + with freeze_time("2020-01-01 00:00"): + html, context = cms_tools.render_plugin( + UserAppointmentsPlugin, plugin_data={}, user=data.user + ) appointments = context["appointments"] @@ -29,6 +31,7 @@ def test_plugin(self, m): self.assertIn("Paspoort", html) self.assertIn("ID kaart", html) + self.assertNotIn("Old appointment", html) pyquery = PQ(html) diff --git a/src/open_inwoner/qmatic/client.py b/src/open_inwoner/qmatic/client.py index 4832551c4d..31620ff578 100644 --- a/src/open_inwoner/qmatic/client.py +++ b/src/open_inwoner/qmatic/client.py @@ -1,5 +1,5 @@ import logging -from datetime import datetime +from datetime import date, datetime from urllib.parse import quote from ape_pie.client import APIClient @@ -144,10 +144,14 @@ def list_appointments_for_customer(self, email: str) -> list[Appointment]: return [] response.raise_for_status() config = QmaticConfig.get_solo() + today = date.today() try: appointments = [ Appointment(**entry) for entry in response.json()["appointmentList"] ] + appointments = [ + entry for entry in appointments if entry.start.date() >= today + ] for appointment in appointments: appointment.url = ( f"{config.booking_base_url}{quote(appointment.publicId)}" diff --git a/src/open_inwoner/qmatic/tests/data.py b/src/open_inwoner/qmatic/tests/data.py index 9d508abb7a..756f0f10f7 100644 --- a/src/open_inwoner/qmatic/tests/data.py +++ b/src/open_inwoner/qmatic/tests/data.py @@ -61,6 +61,20 @@ def __init__(self): ), services=[QmaticServiceFactory.build(name="ID kaart")], ) + self.appointment_old = AppointmentFactory.build( + title="Qmatic web booking old", + start="1990-03-06T16:30:00+00:00", + notes="bar", + branch=BranchDetailFactory.build( + name="Hoofdkantoor", + timeZone="America/New_York", + addressCity="New York", + addressLine1="Hoofdkantoor", + addressLine2="Wall Street 1", + addressZip="1111 AA", + ), + services=[QmaticServiceFactory.build(name="Old appointment")], + ) def setUpMocks(self, m): customer_data = [ @@ -107,6 +121,7 @@ def setUpMocks(self, m): "appointmentList": [ self.appointment_idcard.dict(), self.appointment_passport.dict(), + self.appointment_old.dict(), ], } m.get(