From: Christian Heller Date: Thu, 18 Jul 2024 04:24:41 +0000 (+0200) Subject: Expand POST /todo adoption tests. X-Git-Url: https://plomlompom.com/repos/te"st.html?a=commitdiff_plain;h=a5bbeed740824783e480ee481ffbf0717d05242d;p=plomtask Expand POST /todo adoption tests. --- diff --git a/tests/todos.py b/tests/todos.py index 1fa3a9d..0d778c3 100644 --- a/tests/todos.py +++ b/tests/todos.py @@ -264,12 +264,13 @@ class TestsWithServer(TestCaseWithServer): self.check_post({}, '/todo?id=1', 404) # test malformed values on existing Todo self._make_todo_via_day_post(1) - for name in ['adopt', 'effort', 'make_full', 'make_empty', - 'conditions', 'disables', 'blockers', 'enables']: + for name in [ + 'adopt', 'effort', 'make_full', 'make_empty', 'step_filler', + 'conditions', 'disables', 'blockers', 'enables']: self.check_post({name: 'x'}, '/todo?id=1', 400, '/todo') for prefix in ['make_empty_', 'make_full_']: for suffix in ['', 'x', '1.1']: - self.check_post({'fill_for_1': f'{prefix}{suffix}'}, + self.check_post({'step_filler': f'{prefix}{suffix}'}, '/todo?id=1', 400, '/todo') def test_basic_POST_todo(self) -> None: @@ -339,13 +340,16 @@ class TestsWithServer(TestCaseWithServer): def test_POST_todo_adoption(self) -> None: """Test adoption via POST /todo with "adopt".""" + # pylint: disable=too-many-locals + # pylint: disable=too-many-statements # post two Todos to Day, have first adopt second self._make_todo_via_day_post(1) self._make_todo_via_day_post(1) - proc_dict = self.proc_as_dict(**self._proc1_form_data) + proc1_dict = self.proc_as_dict(**self._proc1_form_data) 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]) + todos = [todo1_dict, todo2_dict] + expected = self.GET_todo_dict(1, todos, [proc1_dict]) expected['todo_candidates'] = [2] expected['steps_todo_to_process'] = [self._step_as_dict(1, [], todo=2)] self.check_post({'adopt': 2}, '/todo?id=1') @@ -365,11 +369,62 @@ class TestsWithServer(TestCaseWithServer): self.check_post({'adopt': 1}, '/todo?id=1', 400) # test cannot do 1-step circular adoption self.check_post({'adopt': 1}, '/todo?id=2') + todo1_dict['parents'] = [2] + todo2_dict['children'] = [1] self.check_post({'adopt': 2}, '/todo?id=1', 400) # test cannot do 2-step circular adoption self._make_todo_via_day_post(1) self.check_post({'adopt': 2}, '/todo?id=3') + todo3_dict = self.todo_as_dict(3, process_id=1, children=[2]) + todo2_dict['parents'] = [3] + todos += [todo3_dict] self.check_post({'adopt': 3}, '/todo?id=1', 400) + # test can adopt Todo into ProcessStep chain via its Process (with key + # 'step_filler' equivalent to single-element 'adopt' if intable) + proc_post = {'title': 'A', 'description': '', 'effort': 1.0} + self.post_process(3, proc_post) + self.post_process(2, proc_post) + self.post_process(1, self._proc1_form_data | {'new_top_step': [2, 3]}) + self._make_todo_via_day_post(2) + self._make_todo_via_day_post(3) + self.check_post({'step_filler': 5, 'adopt': [4]}, '/todo?id=1') + proc3_dict = self.proc_as_dict(3) + proc2_dict = self.proc_as_dict(2) + proc1_dict['explicit_steps'] = [1, 2] + procs = [proc1_dict, proc2_dict, proc3_dict] + procsteps = [self.procstep_as_dict(1, 1, 2), + self.procstep_as_dict(2, 1, 3)] + todo1_dict['children'] = [4, 5] + todo4_dict = self.todo_as_dict(4, process_id=2, parents=[1]) + todo5_dict = self.todo_as_dict(5, process_id=3, parents=[1]) + todos += [todo4_dict, todo5_dict] + expected = self.GET_todo_dict(1, todos, procs, procsteps) + step_proc2 = self._step_as_dict(1, [], 2, 4, True) + step_proc3 = self._step_as_dict(2, [], 3, 5, True) + expected['steps_todo_to_process'] = [step_proc2, step_proc3] + expected['todo_candidates'] = [2, 3, 4, 5] + self.check_json_get('/todo?id=1', expected) + # test cannot adopt into non-top-level elements of chain + self.post_process(4, proc_post) + self.post_process(3, proc_post | {'new_top_step': 4, 'step_of': [1]}) + proc4_dict = self.proc_as_dict(4) + proc3_dict['explicit_steps'] = [3] + procs += [proc4_dict] + procsteps += [self.procstep_as_dict(3, 3, 4)] + step_proc4 = self._step_as_dict(3, [], 4, None, True) + step_proc3['children'] = [step_proc4] + self._make_todo_via_day_post(4) + self.check_post({'adopt': [4, 5, 6]}, '/todo?id=1') + todo6_dict = self.todo_as_dict(6, process_id=4, parents=[1]) + todo1_dict['children'] = [4, 5, 6] + todos += [todo6_dict] + expected = self.GET_todo_dict(1, todos, procs, procsteps) + step2_proc4 = self._step_as_dict(4, [], None, 6, False) + expected['steps_todo_to_process'] = [step_proc2, step_proc3, + step2_proc4] + expected['adoption_candidates_for'] = {'4': [6]} + expected['todo_candidates'] = [2, 3, 4, 5, 6] + self.check_json_get('/todo?id=1', expected) def test_POST_todo_make_full(self) -> None: """Test creation and adoption via POST /todo with "make_full".""" @@ -400,7 +455,7 @@ class TestsWithServer(TestCaseWithServer): step_proc3 = self._step_as_dict(1, [step_proc2], 3, 2, True) expected['steps_todo_to_process'] = [step_proc3] expected['todo_candidates'] = [2, 3, 4] - self.check_post({'fill_for_3': 'make_full_3'}, '/todo?id=1') + self.check_post({'step_filler': '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 @@ -444,7 +499,7 @@ class TestsWithServer(TestCaseWithServer): expected['steps_todo_to_process'] = [step_proc3] expected['todo_candidates'] = [2] expected['adoption_candidates_for'] = {'1': [], '2': []} - self.check_post({'fill_for_3': 'make_empty_3'}, '/todo?id=1') + self.check_post({'step_filler': 'make_empty_3'}, '/todo?id=1') self.check_json_get('/todo?id=1', expected) # make new top-level Todo without chain implied by its Process self.check_post({'make_empty': 2, 'adopt': [2]}, '/todo?id=1')