home · contact · privacy
Re-organize and extend POST/GET /day tests.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 21 Jun 2024 16:50:53 +0000 (18:50 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 21 Jun 2024 16:50:53 +0000 (18:50 +0200)
tests/conditions.py
tests/days.py

index 9fcb68cea14a0956be1e290e4e189d3ddbf0533c..bf04f7b674b84ab2dcad9ebe349400809d449187 100644 (file)
@@ -78,7 +78,7 @@ class TestsWithServer(TestCaseWithServer):
         self.check_post(valid_payload, '/condition?id=foo', 400)
 
     def test_do_POST_condition(self) -> None:
         self.check_post(valid_payload, '/condition?id=foo', 400)
 
     def test_do_POST_condition(self) -> None:
-        """Test POST /condition and its effect on GET /condition[s]."""
+        """Test (valid) POST /condition and its effect on GET /condition[s]."""
         # test valid POST's effect on …
         post = {'title': 'foo', 'description': 'oof', 'is_active': False}
         self.check_post(post, '/condition', 302, '/condition?id=1')
         # test valid POST's effect on …
         post = {'title': 'foo', 'description': 'oof', 'is_active': False}
         self.check_post(post, '/condition', 302, '/condition?id=1')
index 52a3722d56a2e354711253f79b3f25cda0895c1e..0b039bf9ae1212534ff01a02c73e302242f4f82a 100644 (file)
@@ -138,42 +138,6 @@ class TestsWithServer(TestCaseWithServer):
             redir_to = f'{target}&make_type={form_data["make_type"]}'
         self.check_post(form_data, target, status, redir_to)
 
             redir_to = f'{target}&make_type={form_data["make_type"]}'
         self.check_post(form_data, target, status, redir_to)
 
-    def test_do_GET_day_basics(self) -> None:
-        """Test GET /day basics (no Todos)."""
-        # check undefined day
-        date = date_in_n_days(0)
-        expected = self.GET_day_dict(date)
-        self.check_json_get('/day', expected)
-        # check "today", "yesterday", "tomorrow" days
-        self.check_json_get('/day?date=today', expected)
-        expected = self.GET_day_dict(date_in_n_days(1))
-        self.check_json_get('/day?date=tomorrow', expected)
-        expected = self.GET_day_dict(date_in_n_days(-1))
-        self.check_json_get('/day?date=yesterday', expected)
-        # check wrong day strings
-        self.check_get('/day?date=foo', 400)
-        self.check_get('/day?date=2024-02-30', 400)
-        # check defined day
-        date = '2024-01-01'
-        expected = self.GET_day_dict(date)
-        assert isinstance(expected['_library'], dict)
-        self.check_json_get(f'/day?date={date}', expected)
-        # check saved day
-        post: dict[str, object] = {'day_comment': 'foo', 'make_type': ''}
-        self.post_day(f'date={date}', post)
-        expected['_library']['Day'][date]['comment'] = post['day_comment']
-        self.check_json_get(f'/day?date={date}', expected)
-        # check GET parameter to GET requests affects immediate reply, but …
-        expected['make_type'] = 'bar'
-        self.check_json_get(f'/day?date={date}&make_type=bar', expected)
-        # … not any following, …
-        expected['make_type'] = ''
-        self.check_json_get(f'/day?date={date}', expected)
-        # … not even when part of a POST request
-        post['make_type'] = 'foo'
-        self.post_day(f'date={date}', post)
-        self.check_json_get(f'/day?date={date}', expected)
-
     @staticmethod
     def post_batch(list_of_args: list[list[object]],
                    names_of_simples: list[str],
     @staticmethod
     def post_batch(list_of_args: list[list[object]],
                    names_of_simples: list[str],
@@ -279,8 +243,33 @@ class TestsWithServer(TestCaseWithServer):
         self.check_get('/calendar?start=2024-01-01&end=2025-01-01', 200)
         self.check_get('/calendar?start=foo', 400)
 
         self.check_get('/calendar?start=2024-01-01&end=2025-01-01', 200)
         self.check_get('/calendar?start=foo', 400)
 
+    def test_fail_GET_day(self) -> None:
+        """Test malformed/illegal GET /day requests."""
+        self.check_get('/day?date=foo', 400)
+        self.check_get('/day?date=2024-02-30', 400)
+
+    def test_basic_GET_day(self) -> None:
+        """Test basic (no Processes/Conditions/Todos) GET /day basics."""
+        # check undefined day
+        date = date_in_n_days(0)
+        expected = self.GET_day_dict(date)
+        self.check_json_get('/day', expected)
+        # NB: GET ?date="today"/"yesterday"/"tomorrow" in test_basic_POST_day
+        # check 'make_type' GET parameter affects immediate reply, but …
+        date = '2024-01-01'
+        expected = self.GET_day_dict(date)
+        expected['make_type'] = 'bar'
+        self.check_json_get(f'/day?date={date}&make_type=bar', expected)
+        # … not any following, …
+        expected['make_type'] = ''
+        self.check_json_get(f'/day?date={date}', expected)
+        # … not even when part of a POST request
+        post: dict[str, object] = {'day_comment': '', 'make_type': 'foo'}
+        self.post_day(f'date={date}', post)
+        self.check_json_get(f'/day?date={date}', expected)
+
     def test_fail_POST_day(self) -> None:
     def test_fail_POST_day(self) -> None:
-        """Test malformed/illegal POST /condition requests."""
+        """Test malformed/illegal POST /day requests."""
         # check payloads lacking minimum expecteds
         url = '/day?date=2024-01-01'
         self.check_post({}, url, 400)
         # check payloads lacking minimum expecteds
         url = '/day?date=2024-01-01'
         self.check_post({}, url, 400)
@@ -333,3 +322,25 @@ class TestsWithServer(TestCaseWithServer):
         self.check_post(post, '/day', 400)
         self.check_post(post, '/day?date=', 400)
         self.check_post(post, '/day?date=foo', 400)
         self.check_post(post, '/day', 400)
         self.check_post(post, '/day?date=', 400)
         self.check_post(post, '/day?date=foo', 400)
+
+    def test_basic_POST_day(self) -> None:
+        """Test basic (no Todos) POST /day.
+
+        Check POST (& GET!) requests properly parse 'today', 'tomorrow',
+        'yesterday', and actual date strings;
+        preserve 'make_type' setting in redirect even if nonsensical;
+        and store 'day_comment'
+        """
+        for name, dist, test_str in [('2024-01-01', None, 'a'),
+                                     ('today', 0, 'b'),
+                                     ('yesterday', -1, 'c'),
+                                     ('tomorrow', +1, 'd')]:
+            date = name if dist is None else date_in_n_days(dist)
+            post = {'day_comment': test_str, 'make_type': f'x:{test_str}'}
+            post_url = f'/day?date={name}'
+            redir_url = f'{post_url}&make_type={post["make_type"]}'
+            self.check_post(post, post_url, 302, redir_url)
+            expected = self.GET_day_dict(date)
+            assert isinstance(expected['_library'], dict)
+            expected['_library']['Day'][date]['comment'] = test_str
+            self.check_json_get(post_url, expected)