From: Christian Heller Date: Thu, 20 Jun 2024 21:29:25 +0000 (+0200) Subject: Some tests refactoring. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bdb.prefix%7D%7D/%7B%7Bprefix%7D%7D/copy_structured?a=commitdiff_plain;h=7720fa6076fe3fa37597f1aee4cb7399390e6b2c;p=plomtask Some tests refactoring. --- diff --git a/tests/days.py b/tests/days.py index 4e70e09..e310180 100644 --- a/tests/days.py +++ b/tests/days.py @@ -110,9 +110,8 @@ class TestsWithServer(TestCaseWithServer): """Return JSON of TodoNode to expect.""" return {'children': [], 'seen': False, 'todo': todo_id} - def test_do_GET_day(self) -> None: + def test_do_GET_day_basics(self) -> None: """Test GET /day basics.""" - # pylint: disable=too-many-statements # check undefined day date = date_in_n_days(0) day = self.day_dict(date) @@ -159,23 +158,38 @@ class TestsWithServer(TestCaseWithServer): self.check_json_get(f'/day?date={date}', expected) expected['make_type'] = 'bar' self.check_json_get(f'/day?date={date}&make_type=bar', expected) + + def test_do_GET_day_with_todos(self) -> None: + """Test GET /day displaying posted Todos (no tree structure).""" # check GET with two Todos and Processes - expected['make_type'] = '' - form_data = self.post_process(1) - form_data['title'] = 'bar' - form_data['description'] = 'rab' - form_data['effort'] = 0.9 - self.post_process(2, form_data) + date = '2024-01-01' + day = self.day_dict(date) + post_day: dict[str, object] = {'day_comment': '', 'make_type': ''} + self.check_post(post_day, f'/day?date={date}', 302, + f'/day?date={date}&make_type=') + library: dict[str, object] + library = {'Day': self.as_refs([day]), 'Process': {}, 'Todo': {}} + expected: dict[str, object] = {'day': date, + 'top_nodes': [], + 'make_type': '', + 'enablers_for': {}, + 'disablers_for': {}, + 'conditions_present': [], + 'processes': [], + '_library': library} + self.post_process(1) + post_proc2 = {'title': 'bar', 'description': 'rab', 'effort': 0.9} + self.post_process(2, post_proc2) post_day['new_todo'] = [1, 2] self.check_post(post_day, f'/day?date={date}', 302, - f'/day?date={date}&make_type=foo') + f'/day?date={date}&make_type=') proc1 = self.proc_as_dict(1, 'foo', 'foo', 1.1) proc2 = self.proc_as_dict(2, 'bar', 'rab', 0.9) - expected['_library']['Process'] = self.as_refs([proc1, proc2]) + library['Process'] = self.as_refs([proc1, proc2]) expected['processes'] = self.as_id_list([proc1, proc2]) t1 = self.todo_as_dict(1, 1, date) t2 = self.todo_as_dict(2, 2, date) - expected['_library']['Todo'] = self.as_refs([t1, t2]) + library['Todo'] = self.as_refs([t1, t2]) day['todos'] = self.as_id_list([t1, t2]) n1 = self.todo_node_as_dict(1) n2 = self.todo_node_as_dict(2) diff --git a/tests/utils.py b/tests/utils.py index 3b259b2..b115793 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -357,6 +357,7 @@ class TestCaseWithServer(TestCaseWithDB): ) -> dict[str, object]: """Return JSON of Process to expect.""" # pylint: disable=too-many-arguments + as_id_list = TestCaseWithServer.as_id_list d = {'id': id_, 'calendarize': False, 'suppressed_steps': [], @@ -364,12 +365,11 @@ class TestCaseWithServer(TestCaseWithDB): '_versioned': { 'title': {0: title}, 'description': {0: description}, - 'effort': {0: effort} - }, - 'conditions': [c['id'] for c in conditions] if conditions else [], - 'disables': [c['id'] for c in disables] if disables else [], - 'enables': [c['id'] for c in enables] if enables else [], - 'blockers': [c['id'] for c in blockers] if blockers else []} + 'effort': {0: effort}}, + 'conditions': as_id_list(conditions) if conditions else [], + 'disables': as_id_list(disables) if disables else [], + 'enables': as_id_list(enables) if enables else [], + 'blockers': as_id_list(blockers) if blockers else []} return d def check_redirect(self, target: str) -> None: