Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#2935] Mijn Afspraken: Don't show appoinments from the past #1538

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/open_inwoner/accounts/tests/test_profile_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -1483,14 +1484,17 @@ 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")

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()
Expand Down
9 changes: 6 additions & 3 deletions src/open_inwoner/cms/plugins/tests/test_appointments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,16 +20,18 @@ 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"]

self.assertEqual(len(appointments), 2)
pi-sigma marked this conversation as resolved.
Show resolved Hide resolved

self.assertIn("Paspoort", html)
self.assertIn("ID kaart", html)
self.assertNotIn("Old appointment", html)

pyquery = PQ(html)

Expand Down
6 changes: 5 additions & 1 deletion src/open_inwoner/qmatic/client.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)}"
Expand Down
15 changes: 15 additions & 0 deletions src/open_inwoner/qmatic/tests/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -107,6 +121,7 @@ def setUpMocks(self, m):
"appointmentList": [
self.appointment_idcard.dict(),
self.appointment_passport.dict(),
self.appointment_old.dict(),
],
}
m.get(
Expand Down
Loading