From: Christian Heller Date: Sat, 20 Jul 2024 09:45:16 +0000 (+0200) Subject: Extend Todo tests. X-Git-Url: https://plomlompom.com/repos/%7Broute%7D?a=commitdiff_plain;h=8488fb960f02bd3af3095eeb586eb88a3f3bda57;p=plomtask Extend Todo tests. --- diff --git a/tests/todos.py b/tests/todos.py index 0d778c3..d96741d 100644 --- a/tests/todos.py +++ b/tests/todos.py @@ -222,18 +222,24 @@ class TestsWithServer(TestCaseWithServer): todos: list[dict[str, object]], processes: list[dict[str, object]], process_steps: list[dict[str, object]] | None = None, + conditions: list[dict[str, object]] | None = None ) -> dict[str, object]: """Return JSON of GET /todo to expect.""" + # pylint: disable=too-many-arguments library = {'Todo': cls.as_refs(todos), 'Process': cls.as_refs(processes)} if process_steps: library['ProcessStep'] = cls.as_refs(process_steps) + conditions = conditions if conditions else [] + if conditions: + library['Condition'] = cls.as_refs(conditions) return {'todo': target_id, 'steps_todo_to_process': [], 'adoption_candidates_for': {}, 'process_candidates': [p['id'] for p in processes], - 'todo_candidates': [], - 'condition_candidates': [], + 'todo_candidates': [t['id'] for t in todos + if t['id'] != target_id], + 'condition_candidates': [c['id'] for c in conditions], '_library': library} @staticmethod @@ -300,6 +306,22 @@ class TestsWithServer(TestCaseWithServer): self.check_post({'effort': ''}, '/todo?id=1') todo_dict['effort'] = None self.check_json_get('/todo?id=1', expected) + # test Condition posts + c1_post = {'title': 'foo', 'description': 'oof', 'is_active': False} + c2_post = {'title': 'bar', 'description': 'rab', 'is_active': True} + self.check_post(c1_post, '/condition', redir='/condition?id=1') + self.check_post(c2_post, '/condition', redir='/condition?id=2') + c1_dict = self.cond_as_dict(1, False, ['foo'], ['oof']) + c2_dict = self.cond_as_dict(2, True, ['bar'], ['rab']) + conditions = [c1_dict, c2_dict] + todo_post = {'conditions': [1], 'disables': [1], + 'blockers': [2], 'enables': [2]} + for k, v in todo_post.items(): + todo_dict[k] = v + self.check_post(todo_post, '/todo?id=1') + expected = self.GET_todo_dict(1, [todo_dict], [proc_dict], + conditions=conditions) + self.check_json_get('/todo?id=1', expected) def test_POST_todo_deletion(self) -> None: """Test deletions via POST /todo.""" @@ -350,7 +372,6 @@ class TestsWithServer(TestCaseWithServer): todo2_dict = self.todo_as_dict(2, process_id=1, parents=[1]) 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') self.check_json_get('/todo?id=1', expected) @@ -402,7 +423,6 @@ class TestsWithServer(TestCaseWithServer): 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) @@ -423,7 +443,6 @@ class TestsWithServer(TestCaseWithServer): 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: @@ -454,7 +473,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['todo_candidates'] = [2, 3, 4] 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, @@ -467,9 +485,10 @@ 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['todo_candidates'] = [2, 3, 4, 5] expected['steps_todo_to_process'] = [step_proc3, step2_proc2] self.check_json_get('/todo?id=1', expected) + # fail on trying to call make_full on non-existing Process + self.check_post({'make_full': 5}, '/todo?id=1', 404) def test_POST_todo_make_empty(self) -> None: """Test creation and adoption via POST /todo with "make_empty".""" @@ -497,7 +516,6 @@ class TestsWithServer(TestCaseWithServer): 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({'step_filler': 'make_empty_3'}, '/todo?id=1') self.check_json_get('/todo?id=1', expected) @@ -508,10 +526,11 @@ class TestsWithServer(TestCaseWithServer): 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) + # fail on trying to call make_empty on non-existing Process + self.check_post({'make_full': 5}, '/todo?id=1', 404) def test_do_GET_todo(self) -> None: """Test GET /todo response codes."""