home · contact · privacy
Some tests refactoring.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 20 Jun 2024 21:29:25 +0000 (23:29 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 20 Jun 2024 21:29:25 +0000 (23:29 +0200)
tests/days.py
tests/utils.py

index 4e70e097b5d1c53c709d43fb1b42462fe186c248..e3101808274d865227fbf65e4a275750ef0969fe 100644 (file)
@@ -110,9 +110,8 @@ class TestsWithServer(TestCaseWithServer):
         """Return JSON of TodoNode to expect."""
         return {'children': [], 'seen': False, 'todo': todo_id}
 
-    def test_do_GET_day(self) -> None:
+    def test_do_GET_day_basics(self) -> None:
         """Test GET /day basics."""
-        # pylint: disable=too-many-statements
         # check undefined day
         date = date_in_n_days(0)
         day = self.day_dict(date)
@@ -159,23 +158,38 @@ class TestsWithServer(TestCaseWithServer):
         self.check_json_get(f'/day?date={date}', expected)
         expected['make_type'] = 'bar'
         self.check_json_get(f'/day?date={date}&make_type=bar', expected)
+
+    def test_do_GET_day_with_todos(self) -> None:
+        """Test GET /day displaying posted Todos (no tree structure)."""
         # check GET with two Todos and Processes
-        expected['make_type'] = ''
-        form_data = self.post_process(1)
-        form_data['title'] = 'bar'
-        form_data['description'] = 'rab'
-        form_data['effort'] = 0.9
-        self.post_process(2, form_data)
+        date = '2024-01-01'
+        day = self.day_dict(date)
+        post_day: dict[str, object] = {'day_comment': '', 'make_type': ''}
+        self.check_post(post_day, f'/day?date={date}', 302,
+                        f'/day?date={date}&make_type=')
+        library: dict[str, object]
+        library = {'Day': self.as_refs([day]), 'Process': {}, 'Todo': {}}
+        expected: dict[str, object] = {'day': date,
+                                       'top_nodes': [],
+                                       'make_type': '',
+                                       'enablers_for': {},
+                                       'disablers_for': {},
+                                       'conditions_present': [],
+                                       'processes': [],
+                                       '_library': library}
+        self.post_process(1)
+        post_proc2 = {'title': 'bar', 'description': 'rab', 'effort': 0.9}
+        self.post_process(2, post_proc2)
         post_day['new_todo'] = [1, 2]
         self.check_post(post_day, f'/day?date={date}', 302,
-                        f'/day?date={date}&make_type=foo')
+                        f'/day?date={date}&make_type=')
         proc1 = self.proc_as_dict(1, 'foo', 'foo', 1.1)
         proc2 = self.proc_as_dict(2, 'bar', 'rab', 0.9)
-        expected['_library']['Process'] = self.as_refs([proc1, proc2])
+        library['Process'] = self.as_refs([proc1, proc2])
         expected['processes'] = self.as_id_list([proc1, proc2])
         t1 = self.todo_as_dict(1, 1, date)
         t2 = self.todo_as_dict(2, 2, date)
-        expected['_library']['Todo'] = self.as_refs([t1, t2])
+        library['Todo'] = self.as_refs([t1, t2])
         day['todos'] = self.as_id_list([t1, t2])
         n1 = self.todo_node_as_dict(1)
         n2 = self.todo_node_as_dict(2)
index 3b259b2e3aaa7c202f8b581b6b9167d1e04f1128..b115793341bac427e1df1ec71ce4412c353e4f95 100644 (file)
@@ -357,6 +357,7 @@ class TestCaseWithServer(TestCaseWithDB):
                      ) -> dict[str, object]:
         """Return JSON of Process to expect."""
         # pylint: disable=too-many-arguments
+        as_id_list = TestCaseWithServer.as_id_list
         d = {'id': id_,
              'calendarize': False,
              'suppressed_steps': [],
@@ -364,12 +365,11 @@ class TestCaseWithServer(TestCaseWithDB):
              '_versioned': {
                  'title': {0: title},
                  'description': {0: description},
-                 'effort': {0: effort}
-                 },
-             'conditions': [c['id'] for c in conditions] if conditions else [],
-             'disables': [c['id'] for c in disables] if disables else [],
-             'enables': [c['id'] for c in enables] if enables else [],
-             'blockers': [c['id'] for c in blockers] if blockers else []}
+                 'effort': {0: effort}},
+             'conditions': as_id_list(conditions) if conditions else [],
+             'disables': as_id_list(disables) if disables else [],
+             'enables': as_id_list(enables) if enables else [],
+             'blockers': as_id_list(blockers) if blockers else []}
         return d
 
     def check_redirect(self, target: str) -> None: