From 5c0c3713b08b429b1dc70705fd6e21de75d2e5e6 Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Thu, 9 Nov 2023 17:11:04 +0100 Subject: [PATCH] fix test --- setup.py | 1 + .../tests/test_week_table_overrides.py | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 7ec28b8a..2568fe00 100644 --- a/setup.py +++ b/setup.py @@ -78,6 +78,7 @@ "plone.app.contenttypes", "plone.app.robotframework[debug]", "collective.MockMailHost", + "freezegun", ], "app_io": [ "bravado", diff --git a/src/redturtle/prenotazioni/tests/test_week_table_overrides.py b/src/redturtle/prenotazioni/tests/test_week_table_overrides.py index 903a2554..eb90ccce 100644 --- a/src/redturtle/prenotazioni/tests/test_week_table_overrides.py +++ b/src/redturtle/prenotazioni/tests/test_week_table_overrides.py @@ -2,6 +2,7 @@ import json import unittest from datetime import date +from freezegun import freeze_time from plone import api from plone.app.testing import ( @@ -19,7 +20,7 @@ ) -class TestContextState(unittest.TestCase): +class TestWeekTableOverridesContextState(unittest.TestCase): layer = REDTURTLE_PRENOTAZIONI_FUNCTIONAL_TESTING def setUp(self): @@ -93,6 +94,7 @@ def test_if_day_is_in_overrides_use_override_week_table(self): json.loads(self.folder_prenotazioni.week_table_overrides)[0]["week_table"], ) + @freeze_time("2023-05-14") def test_override_between_year(self): self.folder_prenotazioni.week_table_overrides = json.dumps( [ @@ -114,18 +116,27 @@ def test_override_between_year(self): ] ) now = date.today() + + # if in range, return table overrides self.assertEqual( self.view.get_week_table(date(now.year, 12, 25)), json.loads(self.folder_prenotazioni.week_table_overrides)[0]["week_table"], ) + # if in range and next year, return table overrides + self.assertEqual( + self.view.get_week_table(date(now.year + 1, 1, 25)), + json.loads(self.folder_prenotazioni.week_table_overrides)[0]["week_table"], + ) + + # if out of range, return base table self.assertEqual( - self.view.get_week_table(date(now.year, 5, 10)), + self.view.get_week_table(date(now.year, 10, 10)), self.folder_prenotazioni.week_table, ) -class TestApiValidateDataOnPost(unittest.TestCase): +class TestWeekTableOverridesApiValidateDataOnPost(unittest.TestCase): layer = REDTURTLE_PRENOTAZIONI_API_FUNCTIONAL_TESTING def setUp(self):