From: Christian Heller Date: Wed, 17 Jul 2024 20:52:34 +0000 (+0200) Subject: Minor improvements to Todo tests. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/decks/test.html?a=commitdiff_plain;h=82039656bb7bec311326c97878a08bfe136d8829;p=plomtask Minor improvements to Todo tests. --- diff --git a/tests/todos.py b/tests/todos.py index 7e27636..1c86db6 100644 --- a/tests/todos.py +++ b/tests/todos.py @@ -316,7 +316,7 @@ class TestsWithServer(TestCaseWithServer): """Test basic POST /todo manipulations.""" self._make_todo_via_day_post(1) # test posting naked entity at first changes nothing - todo_dict = self.todo_as_dict(1, 1, self._date) + todo_dict = self.todo_as_dict(1, 1) proc_dict = self.proc_as_dict(**self._proc1_form_data) expected = self.GET_todo_dict(1, [todo_dict], [proc_dict]) self.check_json_get('/todo?id=1', expected) @@ -325,15 +325,14 @@ class TestsWithServer(TestCaseWithServer): # test posting doneness, comment, calendarization, effort todo_post = {'done': '', 'calendarize': '', 'comment': 'foo', 'effort': 2.3} - todo_dict = self.todo_as_dict( - 1, 1, self._date, is_done=True, calendarize=True, - comment='foo', effort=2.3) + todo_dict = self.todo_as_dict(1, 1, is_done=True, calendarize=True, + comment='foo', effort=2.3) expected = self.GET_todo_dict(1, [todo_dict], [proc_dict]) self.check_post(todo_post, '/todo?id=1') self.check_json_get('/todo?id=1', expected) # test implicitly un-setting all of those except effort by empty post self.check_post({}, '/todo?id=1') - todo_dict = self.todo_as_dict(1, 1, date=self._date, effort=2.3) + todo_dict = self.todo_as_dict(1, 1, effort=2.3) expected = self.GET_todo_dict(1, [todo_dict], [proc_dict]) self.check_json_get('/todo?id=1', expected) # test empty effort post can be explicitly unset by "" post @@ -344,7 +343,7 @@ class TestsWithServer(TestCaseWithServer): def test_POST_todo_deletion(self) -> None: """Test deletions via POST /todo.""" self._make_todo_via_day_post(1) - todo_dict = self.todo_as_dict(1, process_id=1, date=self._date) + todo_dict = self.todo_as_dict(1, process_id=1) proc_dict = self.proc_as_dict(**self._proc1_form_data) expected = self.GET_todo_dict(1, [todo_dict], [proc_dict]) # test failure of deletion on non-existing Todo @@ -372,10 +371,8 @@ class TestsWithServer(TestCaseWithServer): self._make_todo_via_day_post(1) self._make_todo_via_day_post(1) proc_dict = self.proc_as_dict(**self._proc1_form_data) - todo1_dict = self.todo_as_dict(1, process_id=1, date=self._date) - todo1_dict['children'] = [2] - todo2_dict = self.todo_as_dict(2, process_id=1, date=self._date) - todo2_dict['parents'] = [1] + todo1_dict = self.todo_as_dict(1, process_id=1, children=[2]) + todo2_dict = self.todo_as_dict(2, process_id=1, parents=[1]) expected = self.GET_todo_dict(1, [todo1_dict, todo2_dict], [proc_dict]) expected['todo_candidates'] = [2] expected['steps_todo_to_process'] = [self._step_as_dict(1, [], todo=2)] @@ -411,31 +408,21 @@ class TestsWithServer(TestCaseWithServer): self.post_process(3, proc_post | {'new_top_step': 2}) self.post_process(4, proc_post | {'new_top_step': 3}) proc1_dict = self.proc_as_dict(**self._proc1_form_data) - proc2_dict = self.proc_as_dict(2, '', '', 0.9) - proc2_dict['explicit_steps'] = [1] - proc3_dict = self.proc_as_dict(3, '', '', 0.9) - proc3_dict['explicit_steps'] = [2] - proc4_dict = self.proc_as_dict(4, '', '', 0.9) - proc4_dict['explicit_steps'] = [3] - proc_dicts = [proc1_dict, proc2_dict, proc3_dict, proc4_dict] - procstep_dicts = [self.procstep_as_dict(1, 2, 1), - self.procstep_as_dict(2, 3, 2), - self.procstep_as_dict(3, 4, 3)] + proc2_dict = self.proc_as_dict(2, '', '', 0.9, explicit_steps=[1]) + proc3_dict = self.proc_as_dict(3, '', '', 0.9, explicit_steps=[2]) + proc4_dict = self.proc_as_dict(4, '', '', 0.9, explicit_steps=[3]) + procs = [proc1_dict, proc2_dict, proc3_dict, proc4_dict] + procsteps = [self.procstep_as_dict(1, 2, 1), + self.procstep_as_dict(2, 3, 2), + self.procstep_as_dict(3, 4, 3)] # post (childless) Todo of chain end, then make_full on next in line self._make_todo_via_day_post(4) - todo1_dict = self.todo_as_dict(1, 4, self._date) - todo1_dict['children'] = [2] - todo2_dict = self.todo_as_dict(2, 3, self._date) - todo2_dict['parents'] = [1] - todo2_dict['children'] = [3] - todo3_dict = self.todo_as_dict(3, 2, self._date) - todo3_dict['parents'] = [2] - todo3_dict['children'] = [4] - todo4_dict = self.todo_as_dict(4, 1, self._date) - todo4_dict['parents'] = [3] - todo_dicts = [todo1_dict, todo2_dict, todo3_dict, todo4_dict] - expected = self.GET_todo_dict( - 1, todo_dicts, proc_dicts, procstep_dicts) + todo1_dict = self.todo_as_dict(1, 4, children=[2]) + todo2_dict = self.todo_as_dict(2, 3, children=[3], parents=[1]) + todo3_dict = self.todo_as_dict(3, 2, parents=[2], children=[4]) + todo4_dict = self.todo_as_dict(4, 1, parents=[3]) + todos = [todo1_dict, todo2_dict, todo3_dict, todo4_dict] + expected = self.GET_todo_dict(1, todos, procs, procsteps) step_proc1 = self._step_as_dict(3, [], 1, 4, True) step_proc2 = self._step_as_dict(2, [step_proc1], 2, 3, True) step_proc3 = self._step_as_dict(1, [step_proc2], 3, 2, True) @@ -444,6 +431,20 @@ class TestsWithServer(TestCaseWithServer): expected['todo_candidates'] = [2, 3, 4] self.check_post({'fill_for_3': 'make_full_3'}, '/todo?id=1') self.check_json_get('/todo?id=1', expected) + # make new chain next to expected, find steps_todo_to_process extended, + # expect existing Todo demanded by new chain be adopted into new chain + self.check_post({'make_full': 2, 'adopt': [2]}, '/todo?id=1') + todo5_dict = self.todo_as_dict(5, 2, parents=[1], children=[4]) + todo1_dict['children'] = [2, 5] + todo4_dict['parents'] = [3, 5] + todos += [todo5_dict] + step2_proc1 = self._step_as_dict(5, [], None, 4) + step2_proc2 = self._step_as_dict(4, [step2_proc1], None, 5) + expected = self.GET_todo_dict(1, todos, procs, procsteps) + expected['process_candidates'] = [4, 3, 2, 1] + expected['todo_candidates'] = [2, 3, 4, 5] + expected['steps_todo_to_process'] = [step_proc3, step2_proc2] + self.check_json_get('/todo?id=1', expected) def test_do_GET_todo(self) -> None: """Test GET /todo response codes.""" @@ -455,13 +456,13 @@ class TestsWithServer(TestCaseWithServer): self.check_get('/todo?id=0', 404) self.check_get('/todo?id=2', 404) # test all existing Processes are shown as available - proc_post = {'title': '', 'description': '', 'effort': 0.9} + proc_post = {'title': 'A', 'description': '', 'effort': 1.0} self.post_process(2, proc_post) - todo1_dict = self.todo_as_dict(1, process_id=1, date=self._date) + todo1_dict = self.todo_as_dict(1, process_id=1) proc1_dict = self.proc_as_dict(1, **self._proc1_form_data) - proc2_dict = self.proc_as_dict(2, '', '', 0.9) - proc_dicts = [proc1_dict, proc2_dict] - expected = self.GET_todo_dict(1, [todo1_dict], proc_dicts) + proc2_dict = self.proc_as_dict(2) + procs = [proc1_dict, proc2_dict] + expected = self.GET_todo_dict(1, [todo1_dict], procs) self.check_json_get('/todo?id=1', expected) # test chain of Processes shown as potential step nodes self.post_process(2, proc_post) @@ -472,14 +473,13 @@ class TestsWithServer(TestCaseWithServer): self.post_process(3, proc_post | {'new_top_step': 4, 'step_of': [2]}) proc1_dict['explicit_steps'] = [1] proc2_dict['explicit_steps'] = [2] - proc3_dict = self.proc_as_dict(3, '', '', 0.9, explicit_steps=[3]) - proc4_dict = self.proc_as_dict(4, '', '', 0.9) - proc_dicts = [proc1_dict, proc2_dict, proc3_dict, proc4_dict] - procstep_dicts = [self.procstep_as_dict(1, 1, 2, None), - self.procstep_as_dict(2, 2, 3, None), - self.procstep_as_dict(3, 3, 4, None)] - expected = self.GET_todo_dict( - 1, [todo1_dict], proc_dicts, procstep_dicts) + proc3_dict = self.proc_as_dict(3, explicit_steps=[3]) + proc4_dict = self.proc_as_dict(4) + procs += [proc3_dict, proc4_dict] + procsteps = [self.procstep_as_dict(1, 1, 2, None), + self.procstep_as_dict(2, 2, 3, None), + self.procstep_as_dict(3, 3, 4, None)] + expected = self.GET_todo_dict(1, [todo1_dict], procs, procsteps) step_proc4 = self._step_as_dict(3, [], 4) step_proc3 = self._step_as_dict(2, [step_proc4], 3) step_proc2 = self._step_as_dict(1, [step_proc3], 2, fillable=True) @@ -487,14 +487,13 @@ class TestsWithServer(TestCaseWithServer): expected['adoption_candidates_for'] = {'2': [], '3': [], '4': []} self.check_json_get('/todo?id=1', expected) # test display of parallel chains - steps_d = {'new_top_step': 4, 'keep_step': [1], - 'step_1_process_id': 2, 'steps': [1, 4]} - self.post_process(1, self._proc1_form_data | steps_d) + proc_steps_post = {'new_top_step': 4, 'keep_step': [1], + 'step_1_process_id': 2, 'steps': [1, 4]} + self.post_process(1, self._proc1_form_data | proc_steps_post) proc1_dict['explicit_steps'] = [1, 4] step2_proc4 = self._step_as_dict(4, [], 4, fillable=True) - procstep_dicts += [self.procstep_as_dict(4, 1, 4, None)] - expected = self.GET_todo_dict( - 1, [todo1_dict], proc_dicts, procstep_dicts) + procsteps += [self.procstep_as_dict(4, 1, 4, None)] + expected = self.GET_todo_dict(1, [todo1_dict], procs, procsteps) expected['steps_todo_to_process'] = [step_proc2, step2_proc4] expected['adoption_candidates_for'] = {'2': [], '3': [], '4': []} self.check_json_get('/todo?id=1', expected) diff --git a/tests/utils.py b/tests/utils.py index dc78c15..c428f4c 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -599,6 +599,8 @@ class TestCaseWithServer(TestCaseWithDB): comment: str = '', is_done: bool = False, effort: float | None = None, + children: list[int] | None = None, + parents: list[int] | None = None, ) -> dict[str, object]: """Return JSON of Todo to expect.""" # pylint: disable=too-many-arguments @@ -608,8 +610,8 @@ class TestCaseWithServer(TestCaseWithDB): 'is_done': is_done, 'calendarize': calendarize, 'comment': comment, - 'children': [], - 'parents': [], + 'children': children if children else [], + 'parents': parents if parents else [], 'effort': effort, 'conditions': conditions if conditions else [], 'disables': disables if disables else [],