-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
155 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/redturtle/prenotazioni/restapi/serializers/adapters/prenotazioni_folder.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 -*- | ||
from plone import api | ||
from plone.restapi.interfaces import IFieldSerializer, ISerializeToJson | ||
from plone.restapi.serializer.converters import json_compatible | ||
from zope.component import adapter, getMultiAdapter | ||
from zope.i18n import translate | ||
from zope.interface import implementer | ||
from zope.publisher.interfaces import IRequest | ||
from zope.schema import getFields | ||
from plone.restapi.serializer.dxcontent import SerializeFolderToJson | ||
|
||
from redturtle.prenotazioni import logger | ||
from redturtle.prenotazioni.content.prenotazioni_folder import ( | ||
IPrenotazioniFolder, | ||
) | ||
from redturtle.prenotazioni.interfaces import ( | ||
ISerializeToPrenotazioneSearchableItem, | ||
) | ||
from redturtle.prenotazioni.interfaces import IRedturtlePrenotazioniLayer | ||
|
||
from copy import deepcopy | ||
|
||
|
||
@implementer(ISerializeToJson) | ||
@adapter(IPrenotazioniFolder, IRedturtlePrenotazioniLayer) | ||
class PrenotazioniFolderSerializer(SerializeFolderToJson): | ||
def __call__(self, *args, **kwargs): | ||
res = super().__call__() | ||
|
||
for index, type in enumerate(deepcopy(res.get("booking_types", {}))): | ||
if type.get("hidden"): | ||
del res["booking_types"][index] | ||
|
||
return res |
90 changes: 90 additions & 0 deletions
90
src/redturtle/prenotazioni/tests/test_prenotazioni_folder_serializer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# -*- coding: UTF-8 -*- | ||
import email | ||
import unittest | ||
from datetime import date, datetime, timedelta | ||
|
||
import pytz | ||
from collective.contentrules.mailfromfield.actions.mail import ( | ||
MailFromFieldAction, | ||
) | ||
from plone import api | ||
from plone.app.testing import TEST_USER_ID, setRoles | ||
from plone.contentrules.rule.interfaces import IExecutable | ||
from Products.CMFCore.WorkflowCore import ActionSucceededEvent | ||
from zope.component import getMultiAdapter | ||
from zope.interface import implementer | ||
from zope.interface.interfaces import IObjectEvent | ||
from zope.globalrequest import getRequest | ||
from plone.restapi.interfaces import ISerializeToJson | ||
|
||
from redturtle.prenotazioni.adapters.booker import IBooker | ||
from redturtle.prenotazioni.testing import ( | ||
REDTURTLE_PRENOTAZIONI_FUNCTIONAL_TESTING, | ||
) | ||
|
||
|
||
@implementer(IObjectEvent) | ||
class DummyEvent(object): | ||
def __init__(self, object): | ||
self.object = object | ||
|
||
|
||
class TestEmailToManagers(unittest.TestCase): | ||
layer = REDTURTLE_PRENOTAZIONI_FUNCTIONAL_TESTING | ||
|
||
def setUp(self): | ||
self.app = self.layer["app"] | ||
self.portal = self.layer["portal"] | ||
self.mailhost = self.portal.MailHost | ||
self.hidden_type_name = "Type Hidden" | ||
self.not_hidden_type_name = "Type visible" | ||
|
||
setRoles(self.portal, TEST_USER_ID, ["Manager"]) | ||
|
||
self.folder_prenotazioni = api.content.create( | ||
container=self.portal, | ||
type="PrenotazioniFolder", | ||
title="Prenota foo", | ||
description="", | ||
daData=date.today(), | ||
booking_types=[ | ||
{ | ||
"name": self.hidden_type_name, | ||
"duration": "30", | ||
"hidden": True, | ||
}, | ||
{ | ||
"name": self.not_hidden_type_name, | ||
"duration": "30", | ||
"hidden": False, | ||
}, | ||
], | ||
gates=["Gate A"], | ||
) | ||
week_table = self.folder_prenotazioni.week_table | ||
for data in week_table: | ||
data["morning_start"] = "0700" | ||
data["morning_end"] = "1000" | ||
self.folder_prenotazioni.week_table = week_table | ||
|
||
def test_hidden_type_is_not_shown(self): | ||
self.assertNotIn( | ||
self.hidden_type_name, | ||
[ | ||
i["name"] | ||
for i in getMultiAdapter( | ||
(self.folder_prenotazioni, getRequest()), ISerializeToJson | ||
)()["booking_types"] | ||
], | ||
) | ||
|
||
def test_not_hidden_type_is_being_shown(self): | ||
self.assertIn( | ||
self.not_hidden_type_name, | ||
[ | ||
i["name"] | ||
for i in getMultiAdapter( | ||
(self.folder_prenotazioni, getRequest()), ISerializeToJson | ||
)()["booking_types"] | ||
], | ||
) |