-
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.
Merge pull request #83 from RedTurtle/out_of_office_checks
Only users with permission can add out of office bookings in @booking…
- Loading branch information
Showing
5 changed files
with
141 additions
and
12 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
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,84 @@ | ||
# -*- coding: utf-8 -*- | ||
from datetime import date | ||
from datetime import timedelta | ||
from plone import api | ||
from plone.app.testing import setRoles | ||
from plone.app.testing import SITE_OWNER_NAME | ||
from plone.app.testing import SITE_OWNER_PASSWORD | ||
from plone.app.testing import TEST_USER_ID | ||
from plone.restapi.testing import RelativeSession | ||
from redturtle.prenotazioni.content.prenotazione import VACATION_TYPE | ||
from redturtle.prenotazioni.testing import ( | ||
REDTURTLE_PRENOTAZIONI_API_FUNCTIONAL_TESTING, | ||
) | ||
from redturtle.prenotazioni.tests.helpers import WEEK_TABLE_SCHEMA | ||
|
||
import transaction | ||
import unittest | ||
|
||
|
||
class TestBookingRestAPIAddBlock(unittest.TestCase): | ||
layer = REDTURTLE_PRENOTAZIONI_API_FUNCTIONAL_TESTING | ||
|
||
def setUp(self): | ||
self.app = self.layer["app"] | ||
self.portal = self.layer["portal"] | ||
setRoles(self.portal, TEST_USER_ID, ["Manager"]) | ||
self.portal_url = self.portal.absolute_url() | ||
self.folder_prenotazioni = api.content.create( | ||
container=self.portal, | ||
type="PrenotazioniFolder", | ||
title="Prenota foo", | ||
description="", | ||
daData=date.today(), | ||
booking_types=[ | ||
{"name": "Type A", "duration": "30"}, | ||
], | ||
gates=["Gate A", "Gate B"], | ||
week_table=WEEK_TABLE_SCHEMA, | ||
required_booking_fields=["email"], | ||
) | ||
api.content.transition(obj=self.folder_prenotazioni, transition="publish") | ||
transaction.commit() | ||
|
||
self.api_session = RelativeSession(self.portal_url) | ||
self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) | ||
self.api_session.headers.update({"Accept": "application/json"}) | ||
|
||
def test_anonymous_cant_add_block(self): | ||
self.api_session.auth = None | ||
booking_date = "{}T09:00:00+00:00".format( | ||
(date.today() + timedelta(1)).strftime("%Y-%m-%d") | ||
) | ||
res = self.api_session.post( | ||
self.folder_prenotazioni.absolute_url() + "/@booking", | ||
json={ | ||
"booking_date": booking_date, | ||
"booking_type": VACATION_TYPE, | ||
"fields": [ | ||
{"name": "title", "value": "Mario Rossi"}, | ||
], | ||
}, | ||
) | ||
self.assertEqual(res.status_code, 400) | ||
self.assertEqual( | ||
res.json()["message"], | ||
f"You can't add a booking with type '{VACATION_TYPE}'.", | ||
) | ||
|
||
def test_manager_can_add_block_skipping_required_fields(self): | ||
booking_date = "{}T09:00:00+00:00".format( | ||
(date.today() + timedelta(1)).strftime("%Y-%m-%d") | ||
) | ||
res = self.api_session.post( | ||
self.folder_prenotazioni.absolute_url() + "/@booking", | ||
json={ | ||
"booking_date": booking_date, | ||
"booking_type": VACATION_TYPE, | ||
"fields": [ | ||
{"name": "title", "value": "Mario Rossi"}, | ||
# email is a required field from self.folder_prenotazioni schema | ||
], | ||
}, | ||
) | ||
self.assertEqual(res.status_code, 200) |
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