From: Christian Heller Date: Wed, 17 Jul 2024 00:50:53 +0000 (+0200) Subject: Extend Todo tests. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/static/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/balance?a=commitdiff_plain;h=2e238e4398052899fc1f294414ec51a78e23a434;p=plomtask Extend Todo tests. --- diff --git a/tests/todos.py b/tests/todos.py index 0851bb5..aec7366 100644 --- a/tests/todos.py +++ b/tests/todos.py @@ -289,11 +289,8 @@ class TestsWithServer(TestCaseWithServer): for suffix in ['', 'x', '1.1']: self.check_post({'fill_for_1': f'{prefix}{suffix}'}, '/todo?id=1', 400, '/todo') - # test we cannot POST adoption of self or non-existing Todo - self.check_post({'adopt': 1}, '/todo?id=1', 400) - self.check_post({'adopt': 2}, '/todo?id=1', 404) - def test_do_POST_todo(self) -> None: + def test_basic_POST_todo(self) -> None: """Test POST /todo.""" date = '2024-01-01' day_post = {'day_comment': '', 'new_todo': 1, 'make_type': 'full'} @@ -305,41 +302,83 @@ class TestsWithServer(TestCaseWithServer): self.check_json_get('/todo?id=1', expected) self.check_post({}, '/todo?id=1') self.check_json_get('/todo?id=1', expected) - # test posting doneness - todo_dict['is_done'] = True - self.check_post({'done': ''}, '/todo?id=1') + # test posting doneness, comment, calendarization, effort + todo_post = {'done': '', 'calendarize': '', 'comment': 'foo', + 'effort': 2.3} + todo_dict = self.todo_as_dict( + 1, process_id=1, date=date, 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 posting non-doneness + # test implicitly un-setting all of those except effort by empty post self.check_post({}, '/todo?id=1') - todo_dict['is_done'] = False + todo_dict = self.todo_as_dict(1, process_id=1, date=date, 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 + self.check_post({'effort': ''}, '/todo?id=1') + todo_dict['effort'] = None + self.check_json_get('/todo?id=1', expected) + # test failure of deletion on non-existing Todo + self.check_post({'delete': ''}, '/todo?id=2', 404, '/') + # test deletion of existing Todo + self.check_post({'delete': ''}, '/todo?id=1', 302, '/') + self.check_get('/todo?id=1', 404) + # test deletion of adopted Todo + self.check_post(day_post, f'/day?date={date}&make_type=full') + self.check_post(day_post, f'/day?date={date}&make_type=full') + self.check_post({'adopt': 2}, '/todo?id=1') + self.check_post({'delete': ''}, '/todo?id=2', 302, '/') self.check_json_get('/todo?id=1', expected) - # post new Todo to Day and adopt it + # test deletion of adopting Todo self.check_post(day_post, f'/day?date={date}&make_type=full') + self.check_post({'adopt': 2}, '/todo?id=1') + self.check_post({'delete': ''}, '/todo?id=1', 302, '/') + todo_dict['id'] = 2 + expected = self.GET_todo_dict(2, [todo_dict], [proc_dict]) + self.check_json_get('/todo?id=2', expected) + + def test_POST_todo_adoption(self) -> None: + """Test POST /todo.""" + date = '2024-01-01' + # post two Todos to Day, have first adopt second + proc_dict = self.proc_as_dict(**self._proc1_form_data) + day_post = {'day_comment': '', 'new_todo': 1, 'make_type': 'full'} + self.check_post(day_post, f'/day?date={date}&make_type=full') + self.check_post(day_post, f'/day?date={date}&make_type=full') + todo1_dict = self.todo_as_dict(1, process_id=1, date=date) + todo1_dict['children'] = [2] todo2_dict = self.todo_as_dict(2, process_id=1, date=date) + todo2_dict['parents'] = [1] + expected = self.GET_todo_dict(1, [todo1_dict, todo2_dict], [proc_dict]) expected['todo_candidates'] = [2] - assert isinstance(expected['_library'], dict) - expected['_library']['Todo']['2'] = todo2_dict - expected['_library']['Todo']['2']['parents'] = [1] - expected['_library']['Todo']['1']['children'] = [2] expected['steps_todo_to_process'] = [{ 'children': [], 'fillable': False, 'node_id': 1, 'process': None, 'todo': 2}] self.check_post({'adopt': 2}, '/todo?id=1') self.check_json_get('/todo?id=1', expected) - # # test todo1 cannot be set done with todo2 not done yet + # test Todo cannot be set done with adopted Todo not done yet self.check_post({'adopt': 2, 'done': ''}, '/todo?id=1', 400) self.check_json_get('/todo?id=1', expected) - # # test todo1 un-adopting todo 2 by just not sending an adopt + # test Todo un-adopting by just not sending an adopt self.check_post({}, '/todo?id=1') - expected['_library']['Todo']['2']['parents'] = [] - expected['_library']['Todo']['1']['children'] = [] + todo1_dict['children'] = [] + todo2_dict['parents'] = [] expected['steps_todo_to_process'] = [] self.check_json_get('/todo?id=1', expected) - # test todo2 deletion - self.check_post({'delete': ''}, '/todo?id=2', 302, '/') - del expected['_library']['Todo']['2'] - expected['todo_candidates'] = [] - self.check_json_get('/todo?id=1', expected) + # test fail on trying to adopt non-existing Todo + self.check_post({'adopt': 3}, '/todo?id=1', 404) + # test cannot self-adopt + self.check_post({'adopt': 1}, '/todo?id=1', 400) + # test cannot do 1-step circular adoption + self.check_post({'adopt': 1}, '/todo?id=2') + self.check_post({'adopt': 2}, '/todo?id=1', 400) + # test cannot do 2-step circular adoption + day_post = {'day_comment': '', 'new_todo': 1, 'make_type': 'full'} + self.check_post(day_post, f'/day?date={date}&make_type=full') + self.check_post({'adopt': 2}, '/todo?id=3') + self.check_post({'adopt': 3}, '/todo?id=1', 400) def test_do_GET_todo(self) -> None: """Test GET /todo response codes.""" @@ -361,13 +400,6 @@ class TestsWithServer(TestCaseWithServer): expected = self.GET_todo_dict(1, [todo1_dict], [proc1_dict, proc2_dict]) self.check_json_get('/todo?id=1', expected) - # post new Todo to Day and expect visibility as candidate - self.check_post(day_post, f'/day?date={date}&make_type=full') - todo2_dict = self.todo_as_dict(2, process_id=1, date=date) - assert isinstance(expected['_library'], dict) - expected['_library']['Todo']['2'] = todo2_dict - expected['todo_candidates'] = [2] - self.check_json_get('/todo?id=1', expected) def test_do_POST_day(self) -> None: """Test Todo posting of POST /day.""" diff --git a/tests/utils.py b/tests/utils.py index b987bc3..19bcc59 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -582,19 +582,23 @@ class TestCaseWithServer(TestCaseWithDB): conditions: None | list[int] = None, disables: None | list[int] = None, blockers: None | list[int] = None, - enables: None | list[int] = None + enables: None | list[int] = None, + calendarize: bool = False, + comment: str = '', + is_done: bool = False, + effort: float | None = None, ) -> dict[str, object]: """Return JSON of Todo to expect.""" # pylint: disable=too-many-arguments d = {'id': id_, 'date': date, 'process_id': process_id, - 'is_done': False, - 'calendarize': False, - 'comment': '', + 'is_done': is_done, + 'calendarize': calendarize, + 'comment': comment, 'children': [], 'parents': [], - 'effort': None, + 'effort': effort, 'conditions': conditions if conditions else [], 'disables': disables if disables else [], 'blockers': blockers if blockers else [],