Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
folix-01 committed Nov 2, 2023
1 parent ffb198f commit 1126308
Showing 1 changed file with 38 additions and 13 deletions.
51 changes: 38 additions & 13 deletions src/redturtle/prenotazioni/tests/test_available_slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
from plone.restapi.testing import RelativeSession

from redturtle.prenotazioni.adapters.booker import IBooker
from redturtle.prenotazioni.testing import REDTURTLE_PRENOTAZIONI_API_FUNCTIONAL_TESTING
from redturtle.prenotazioni.testing import (
REDTURTLE_PRENOTAZIONI_API_FUNCTIONAL_TESTING,
)


class TestAvailableSlots(unittest.TestCase):
Expand All @@ -25,7 +27,9 @@ class TestAvailableSlots(unittest.TestCase):
timezone = "Europe/Rome"

def dt_local_to_utc(self, value):
return pytz.timezone(self.timezone).localize(value).astimezone(pytz.utc)
return (
pytz.timezone(self.timezone).localize(value).astimezone(pytz.utc)
)

def dt_local_to_json(self, value):
return json_compatible(self.dt_local_to_utc(value))
Expand Down Expand Up @@ -74,7 +78,9 @@ def setUp(self):
type="PrenotazioniYear",
title="Year",
)
week = api.content.create(container=year, type="PrenotazioniWeek", title="Week")
week = api.content.create(
container=year, type="PrenotazioniWeek", title="Week"
)
self.day_folder = api.content.create(
container=week, type="PrenotazioniDay", title="Day"
)
Expand All @@ -94,7 +100,9 @@ def test_month_slots_called_without_params_return_all_available_slots_of_current
self,
):
response = self.api_session.get(
"{}/@available-slots".format(self.folder_prenotazioni.absolute_url())
"{}/@available-slots".format(
self.folder_prenotazioni.absolute_url()
)
)
# get next mondays in current month
now = date.today()
Expand All @@ -108,12 +116,16 @@ def test_month_slots_called_without_params_return_all_available_slots_of_current
for hour in [7, 8, 9]:
expected.append(
json_compatible(
datetime(current_year, current_month, week[0], hour, 0)
datetime(
current_year, current_month, week[0], hour, 0
)
)
)
self.assertEqual(expected, response.json()["items"])

@unittest.skipIf(date.today().day > 20, "issue testing in the last days of a month")
@unittest.skipIf(
date.today().day > 20, "issue testing in the last days of a month"
)
def test_month_slots_called_without_params_return_available_slots_of_current_month_when_some_are_full(
self,
):
Expand Down Expand Up @@ -171,7 +183,9 @@ def test_month_slots_called_without_params_return_available_slots_of_current_mon
)
else:
response = self.api_session.get(
"{}/@available-slots".format(self.folder_prenotazioni.absolute_url())
"{}/@available-slots".format(
self.folder_prenotazioni.absolute_url()
)
)

# first free slot is at 7:30
Expand Down Expand Up @@ -277,7 +291,9 @@ def test_raise_error_if_start_is_greater_than_end(

self.assertEqual(400, response.status_code)

@unittest.skipIf(date.today().day > 20, "issue testing in the last days of a month")
@unittest.skipIf(
date.today().day > 20, "issue testing in the last days of a month"
)
def test_month_slots_notBeforeDays_honored(
self,
):
Expand All @@ -304,12 +320,17 @@ def test_month_slots_notBeforeDays_honored(
description="",
daData=now,
week_table=week_table,
booking_types=[
{"name": "Type A", "duration": "30"},
],
gates=["Gate A"],
)

api.content.create(
type="BookingType",
title="Type A",
duration=30,
container=folder,
gates=["all"],
)

transaction.commit()

response = self.api_session.get(
Expand All @@ -326,10 +347,14 @@ def test_month_slots_notBeforeDays_honored(
folder.notBeforeDays = 0
transaction.commit()

response = self.api_session.get(f"{folder.absolute_url()}/@available-slots")
response = self.api_session.get(
f"{folder.absolute_url()}/@available-slots"
)
self.assertIn(tomorrow_7_0, response.json()["items"])

@unittest.skipIf(date.today().day > 20, "issue testing in the last days of a month")
@unittest.skipIf(
date.today().day > 20, "issue testing in the last days of a month"
)
def test_month_slots_filtered_by_booking_type(self):
# Type A 30 minutes
response = self.api_session.get(
Expand Down

0 comments on commit 1126308

Please sign in to comment.