From: Christian Heller Date: Wed, 17 Jul 2024 21:50:25 +0000 (+0200) Subject: On GET /todo, sort Process candidates. Minor improvements to Todo tests. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/add_task?a=commitdiff_plain;h=b2f17e39ba8352d07e3a428e59c30c9c61143356;p=plomtask On GET /todo, sort Process candidates. Minor improvements to Todo tests. --- diff --git a/plomtask/http.py b/plomtask/http.py index ca4ce67..98242e5 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -440,7 +440,7 @@ class TaskHandler(BaseHTTPRequestHandler): return {'todo': todo, 'steps_todo_to_process': steps_todo_to_process, 'adoption_candidates_for': adoptables, - 'process_candidates': Process.all(self.conn), + 'process_candidates': sorted(Process.all(self.conn)), 'todo_candidates': any_adoptables, 'condition_candidates': Condition.all(self.conn)} diff --git a/tests/todos.py b/tests/todos.py index 1c86db6..42bff44 100644 --- a/tests/todos.py +++ b/tests/todos.py @@ -403,14 +403,14 @@ class TestsWithServer(TestCaseWithServer): """Test creation and adoption via POST /todo with "make_full".""" # pylint: disable=too-many-locals # create chain of Processes - proc_post = {'title': '', 'description': '', 'effort': 0.9} + proc_post = {'title': 'A', 'description': '', 'effort': 1.0} self.post_process(2, proc_post | {'new_top_step': 1}) 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, 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]) + proc2_dict = self.proc_as_dict(2, explicit_steps=[1]) + proc3_dict = self.proc_as_dict(3, explicit_steps=[2]) + proc4_dict = self.proc_as_dict(4, 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), @@ -427,7 +427,6 @@ class TestsWithServer(TestCaseWithServer): step_proc2 = self._step_as_dict(2, [step_proc1], 2, 3, True) step_proc3 = self._step_as_dict(1, [step_proc2], 3, 2, True) expected['steps_todo_to_process'] = [step_proc3] - expected['process_candidates'] = [4, 3, 2, 1] 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) @@ -441,11 +440,52 @@ class TestsWithServer(TestCaseWithServer): 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_POST_todo_make_empty(self) -> None: + """Test creation and adoption via POST /todo with "make_empty".""" + # pylint: disable=too-many-locals + # create chain of Processes + proc_post = {'title': 'A', 'description': '', 'effort': 1.0} + self.post_process(2, proc_post | {'new_top_step': 1}) + 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, explicit_steps=[1]) + proc3_dict = self.proc_as_dict(3, explicit_steps=[2]) + proc4_dict = self.proc_as_dict(4, 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 empty on next in line + self._make_todo_via_day_post(4) + todo1_dict = self.todo_as_dict(1, 4, children=[2]) + todo2_dict = self.todo_as_dict(2, 3, parents=[1]) + todos = [todo1_dict, todo2_dict] + expected = self.GET_todo_dict(1, todos, procs, procsteps) + step_proc1 = self._step_as_dict(3, [], 1, None) + step_proc2 = self._step_as_dict(2, [step_proc1], 2, None, True) + step_proc3 = self._step_as_dict(1, [step_proc2], 3, 2, True) + 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_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') + todo3_dict = self.todo_as_dict(3, 2, parents=[1], children=[]) + todo1_dict['children'] = [2, 3] + todos += [todo3_dict] + step2_proc2 = self._step_as_dict(4, [], None, 3) + expected = self.GET_todo_dict(1, todos, procs, procsteps) + expected['todo_candidates'] = [2, 3] + expected['steps_todo_to_process'] = [step_proc3, step2_proc2] + expected['adoption_candidates_for'] = {'1': [], '2': [3]} + self.check_json_get('/todo?id=1', expected) + def test_do_GET_todo(self) -> None: """Test GET /todo response codes.""" self._make_todo_via_day_post(1)