home · contact · privacy
Rename "condition"/"blocker" input names to plurals, like they are everywhere else.
[plomtask] / tests / days.py
index 5c910ecdb9cf639c44ed6e0492aaae1190a20f65..59c9f4911b8d6b649d42cb71a9035c811af7e1df 100644 (file)
@@ -124,7 +124,7 @@ class TestsWithServer(TestCaseWithServer):
              '_library': {'Day': TestsWithServer.as_refs([day])}}
         return d
 
-    def post_day(self, params: str,
+    def post_day(self, params: str = '',
                  form_data: None | dict[str, object] = None,
                  redir_to: str = '',
                  status: int = 302,
@@ -163,35 +163,42 @@ class TestsWithServer(TestCaseWithServer):
         day = expected['_library']['Day'][date]
         day['comment'] = post['day_comment']
         self.check_json_get(f'/day?date={date}', expected)
-        # check GET parameter of a POST does not affect reply to param-free GET
+        # 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)
-        expected['make_type'] = 'bar'
-        self.check_json_get(f'/day?date={date}&make_type=bar', expected)
 
-    def test_do_GET_day_with_todos_flat(self) -> None:
-        """Test GET /day displaying posted Todos (no tree structure)."""
-        # post two Todos of differing processes and check their display
+    def test_do_GET_day_with_processes_and_todos(self) -> None:
+        """Test GET /day displaying Processes and Todos."""
         date = '2024-01-01'
-        self.post_day(f'date={date}')
-        expected = self.get_day_dict(date)
+        # check Processes get displayed in ['processes'] and ['_library']
         post_proc1 = {'title': 'foo', 'description': 'oof', 'effort': 1.1}
         post_proc2 = {'title': 'bar', 'description': 'rab', 'effort': 0.9}
-        procs: list[dict[str, object]] = [{}, {}]
+        procs_expected: list[dict[str, object]] = [{}, {}]
         for i, post in enumerate([post_proc1, post_proc2]):
             self.post_process(i+1, post)
             assert isinstance(post['title'], str)
             assert isinstance(post['description'], str)
             assert isinstance(post['effort'], float)
-            procs[i] = self.proc_as_dict(i+1, post['title'],
-                                         post['description'], post['effort'])
+            procs_expected[i] = self.proc_as_dict(i+1, post['title'],
+                                                  post['description'],
+                                                  post['effort'])
+        self.post_day(f'date={date}')
+        expected = self.get_day_dict(date)
+        expected['processes'] = self.as_id_list(procs_expected)
+        assert isinstance(expected['_library'], dict)
+        expected['_library']['Process'] = self.as_refs(procs_expected)
+        self.check_json_get(f'/day?date={date}', expected)
+        # post Todos of either process and check their display
         post_day: dict[str, object]
         post_day = {'day_comment': '', 'make_type': '', 'new_todo': [1, 2]}
         self.post_day(f'date={date}', post_day)
-        assert isinstance(expected['_library'], dict)
-        expected['_library']['Process'] = self.as_refs(procs)
-        expected['processes'] = self.as_id_list(procs)
         todos = [self.todo_as_dict(1, 1, date), self.todo_as_dict(2, 2, date)]
         expected['_library']['Todo'] = self.as_refs(todos)
         expected['_library']['Day'][date]['todos'] = self.as_id_list(todos)
@@ -228,8 +235,7 @@ class TestsWithServer(TestCaseWithServer):
         post_proc1 = {'title': 'foo', 'description': 'oof', 'effort': 1.1}
         post_proc2 = {'title': 'bar', 'description': 'rab', 'effort': 0.9}
         procs: list[dict[str, object]] = [{}, {}]
-        names_input = ('condition', 'disables', 'blocker', 'enables')
-        names_output = ('conditions', 'disables', 'blockers', 'enables')
+        cond_names = ('conditions', 'disables', 'blockers', 'enables')
         cond_vals = ((1, 1, 2, 2), (2, 2, 1, 1))
         for i, post in enumerate([post_proc1, post_proc2]):
             assert isinstance(post['title'], str)
@@ -237,9 +243,9 @@ class TestsWithServer(TestCaseWithServer):
             assert isinstance(post['effort'], float)
             procs[i] = self.proc_as_dict(i+1, post['title'],
                                          post['description'], post['effort'])
-            for j, name_input in enumerate(names_input):
-                post[name_input] = [cond_vals[i][j]]
-                procs[i][names_output[j]] = [cond_vals[i][j]]
+            for j, cond_name in enumerate(cond_names):
+                post[cond_name] = [cond_vals[i][j]]
+                procs[i][cond_name] = [cond_vals[i][j]]
             self.post_process(i+1, post)
         date = '2024-01-01'
         expected = self.get_day_dict(date)