Skip to content

Commit

Permalink
Merge branch 'booking_additional_fields' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
folix-01 committed Aug 29, 2024
2 parents 7d1ec9d + 4592211 commit 7934ee0
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ Response::
Available types are
-------------------

- **textline**: Text which uses default zope.schema.TextLine validation
- **text**: Text which uses default zope.schema.TextLine validation


Special Views
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ def __call__(self, *args, **kwargs):
"requirements": requirements,
"modification_date": json_compatible(self.prenotazione.modified()),
"creation_date": json_compatible(self.prenotazione.created()),
"additional_fields": self.prenotazione.additional_fields,
"additional_fields": json.loads(
self.prenotazione.additional_fields or "[]"
),
}


Expand Down Expand Up @@ -135,6 +137,9 @@ def __call__(self, *args, **kwargs):
"email": self.prenotazione.email,
"fiscalcode": self.prenotazione.fiscalcode,
"phone": self.prenotazione.phone,
"additional_fields": json.loads(
self.prenotazione.additional_fields or "[]"
),
"staff_notes": self.prenotazione.staff_notes,
"company": self.prenotazione.company,
"vacation": self.prenotazione.isVacation(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def reply(self):
If you pass the `first_available` flag the site will search in all the available time range of the Bookging Folder or in the next year
and obtain the first one if exits, note that this option is only allowed for Booking Managers
"""

# XXX: nocache also for anonymous
self.request.response.setHeader("Cache-Control", "no-cache")

Expand Down
6 changes: 3 additions & 3 deletions src/redturtle/prenotazioni/tests/test_add_booking.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def test_additional_fields_text(self):
self.assertEqual(res.status_code, 200)
self.assertEqual(
res.json()["additional_fields"],
'[{"name": "text line", "value": "text field value"}]',
[{"name": "text line", "value": "text field value"}],
)

# Text wrong field type
Expand Down Expand Up @@ -498,7 +498,7 @@ def test_edit_additional_fields(self):
self.assertEqual(res.status_code, 200)
self.assertEqual(
res.json()["additional_fields"],
'[{"name": "field1", "value": "foo"}]',
[{"name": "field1", "value": "foo"}],
)
booking_url = res.json()["@id"]
res = self.api_session.patch(
Expand All @@ -512,7 +512,7 @@ def test_edit_additional_fields(self):
res = self.api_session.get(booking_url)
self.assertEqual(
res.json()["additional_fields"],
'[{"name": "field1", "value": "bar"}]',
[{"name": "field1", "value": "bar"}],
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def test_serializer_fields(self):
# 'gate': None,
# 'id': 'prenotazione',
"phone": self.prenotazione_fscode.phone,
"additional_fields": [],
"staff_notes": self.prenotazione_fscode.staff_notes,
"company": self.prenotazione_fscode.company,
"vacation": None,
Expand Down
51 changes: 47 additions & 4 deletions src/redturtle/prenotazioni/tests/test_prenotazioni_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import openpyxl
import transaction
from dateutil import parser
from freezegun import freeze_time
from plone import api
from plone.app.testing import SITE_OWNER_NAME
from plone.app.testing import SITE_OWNER_PASSWORD
Expand Down Expand Up @@ -548,7 +549,7 @@ def setUp(self):
type="PrenotazioniFolder",
title="Prenota foo",
description="",
daData=date.today(),
daData=parser.parse("2023-04-01").date(),
gates=["Gate A"],
)
api.content.transition(obj=self.folder_prenotazioni, transition="publish")
Expand All @@ -562,6 +563,14 @@ def setUp(self):
requirements=RichTextValue(
"You need to bring your own food", "text/plain", "text/html"
),
booking_additional_fields_schema=[
{
"name": "foo",
"label": "This is Foo",
"description": "text field description",
"type": "text",
}
],
)
api.content.transition(obj=obj, transition="publish")

Expand Down Expand Up @@ -610,8 +619,8 @@ def tearDown(self):
self.anon_session.close()
self.user_session.close()

@freeze_time("2023-05-14")
def test_search_own_bookings(self):

# booking_date = "{}T09:00:00+00:00".format(
# (date.today() + timedelta(1)).strftime("%Y-%m-%d")
# )
Expand Down Expand Up @@ -691,14 +700,48 @@ def test_search_own_bookings(self):

# TODO: verificare che siano le prenotazioni giuste

# utility methods
@freeze_time("2023-05-14")
def test_additional_fields(self):
res = self.anon_session.get(
f"{self.folder_prenotazioni.absolute_url()}/@available-slots"
)
booking_date = res.json()["items"][0]
res = self.add_booking(
self.anon_session,
booking_date=booking_date,
booking_type="Type A",
fields=[
{"name": "title", "value": "Mario Rossi"},
{"name": "email", "value": "mario.rossi@example"},
{"name": "fiscalcode", "value": "ABCDEF12G34H567I"},
],
additional_fields=[{"name": "foo", "value": "bar"}],
)
self.assertEqual(res.status_code, 200)
self.assertEqual(
res.json()["additional_fields"], [{"name": "foo", "value": "bar"}]
)
booking_code = res.json()["booking_code"]
res = self.api_session.get(
f"{self.portal.absolute_url()}/@bookings?SearchableText={booking_code}"
)
self.assertEqual(res.status_code, 200)
self.assertEqual(res.json()["items_total"], 1)
self.assertEqual(
res.json()["items"][0]["additional_fields"],
[{"name": "foo", "value": "bar"}],
)

def add_booking(self, api_session, booking_date, booking_type, fields):
# utility methods
def add_booking(
self, api_session, booking_date, booking_type, fields, additional_fields=None
):
return api_session.post(
f"{self.folder_prenotazioni.absolute_url()}/@booking",
json={
"booking_date": booking_date,
"booking_type": booking_type,
"fields": fields,
"additional_fields": additional_fields,
},
)

0 comments on commit 7934ee0

Please sign in to comment.