From a9cfe45bb05035ee5a08d601cd82bd9a5500f5bb Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Fri, 19 Jan 2024 15:11:18 +0100 Subject: [PATCH] fix serializer tz and add test for move event --- .../serializers/adapters/prenotazione.py | 5 +-- .../tests/test_move_booking_api.py | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/redturtle/prenotazioni/restapi/serializers/adapters/prenotazione.py b/src/redturtle/prenotazioni/restapi/serializers/adapters/prenotazione.py index b02d007e..d1e7779c 100644 --- a/src/redturtle/prenotazioni/restapi/serializers/adapters/prenotazione.py +++ b/src/redturtle/prenotazioni/restapi/serializers/adapters/prenotazione.py @@ -59,7 +59,6 @@ def __call__(self, *args, **kwargs): booking_expiration_date = booking_expiration_date.replace( booking_date.year, booking_date.month, booking_date.day ) - return { "UID": self.prenotazione.UID(), "@type": self.prenotazione.portal_type, @@ -85,8 +84,8 @@ def __call__(self, *args, **kwargs): "notify_on_confirm": booking_folder.notify_on_confirm, "cosa_serve": requirements, # BBB "requirements": requirements, - "modification_date": self.prenotazione.ModificationDate(), - "creation_date": self.prenotazione.CreationDate(), + "modification_date": json_compatible(self.prenotazione.modified()), + "creation_date": json_compatible(self.prenotazione.created()), } diff --git a/src/redturtle/prenotazioni/tests/test_move_booking_api.py b/src/redturtle/prenotazioni/tests/test_move_booking_api.py index 3634500a..56cd56d4 100644 --- a/src/redturtle/prenotazioni/tests/test_move_booking_api.py +++ b/src/redturtle/prenotazioni/tests/test_move_booking_api.py @@ -3,6 +3,7 @@ from datetime import date from datetime import datetime from datetime import timedelta +from DateTime import DateTime import pytz import transaction @@ -11,6 +12,7 @@ from plone.app.testing import SITE_OWNER_PASSWORD from plone.app.testing import TEST_USER_ID from plone.app.testing import setRoles +from plone.restapi.serializer.converters import json_compatible from plone.restapi.testing import RelativeSession from redturtle.prenotazioni.adapters.booker import IBooker @@ -130,3 +132,42 @@ def test_move_booking_to_used_slot(self): response.json()["message"], "Sorry, this slot is not available or does not fit your booking.", ) + + def test_move_booking_update_modification_date(self): + booking = self.booker.book( + { + "booking_date": self.today, + "booking_type": "Type A", + "title": "foo", + } + ) + booking.setModificationDate(booking.modified() - 1) + booking.reindexObject(idxs=["modified"]) + + uid = booking.UID() + old_modified = json_compatible(booking.modified()) + transaction.commit() + + # check that modification_date is right + response = self.api_session_admin.get( + f"{self.folder_prenotazioni.absolute_url()}/@booking/{uid}" + ).json() + + self.assertEqual(old_modified, response["modification_date"]) + + # now move the booking + tomorrow = self.today + timedelta(1) + now = json_compatible(DateTime()) + response = self.api_session_admin.post( + f"{self.folder_prenotazioni.absolute_url()}/@booking-move", + json={ + "booking_id": uid, + "booking_date": tomorrow.isoformat(), # tomorrow + }, + ) + response = self.api_session_admin.get( + f"{self.folder_prenotazioni.absolute_url()}/@booking/{uid}", + ).json() + + self.assertNotEqual(old_modified, response["modification_date"]) + self.assertEqual(now, response["modification_date"])