Skip to content

Commit

Permalink
fix serializer tz and add test for move event
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Jan 19, 2024
1 parent 16b75e0 commit a9cfe45
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()),
}


Expand Down
41 changes: 41 additions & 0 deletions src/redturtle/prenotazioni/tests/test_move_booking_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import date
from datetime import datetime
from datetime import timedelta
from DateTime import DateTime

import pytz
import transaction
Expand All @@ -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
Expand Down Expand Up @@ -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"])

0 comments on commit a9cfe45

Please sign in to comment.