diff --git a/src/open_inwoner/accounts/tests/test_profile_views.py b/src/open_inwoner/accounts/tests/test_profile_views.py index cc80ac8fae..228c311d9f 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,12 +1484,14 @@ 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) cards = response.pyquery(".appointment-info") + # past appointments should not show up self.assertEqual(len(cards), 2) self.assertEqual(PQ(cards[0]).find(".card__heading-2").text(), "Paspoort") diff --git a/src/open_inwoner/cms/plugins/tests/test_appointments.py b/src/open_inwoner/cms/plugins/tests/test_appointments.py index 4473c378ca..20e8e1ceff 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,12 +20,14 @@ 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"] + # past appointments should not show up self.assertEqual(len(appointments), 2) self.assertIn("Paspoort", 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..d83cc8f7c2 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")], + ) 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(