X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;f=tests%2Ftodos.py;h=b28ebd8cdda37c973cf468daa2683140f855dd39;hb=3bc56075efe4e4409824c7bd99a55593905e960e;hp=4ba5a1c6ee4643ef673653661579740219f80081;hpb=3346c7fab2fda82b290d245798f4537b43abb012;p=plomtask diff --git a/tests/todos.py b/tests/todos.py index 4ba5a1c..b28ebd8 100644 --- a/tests/todos.py +++ b/tests/todos.py @@ -1,7 +1,7 @@ """Test Todos module.""" from tests.utils import TestCaseWithDB, TestCaseWithServer from plomtask.todos import Todo, TodoNode -from plomtask.processes import Process +from plomtask.processes import Process, ProcessStep from plomtask.conditions import Condition from plomtask.exceptions import (NotFoundException, BadFormatException, HandledException) @@ -63,7 +63,8 @@ class TestsWithDB(TestCaseWithDB): t2.save(self.db_conn) self.assertEqual(Todo.by_date(self.db_conn, self.date1), [t1, t2]) self.assertEqual(Todo.by_date(self.db_conn, self.date2), []) - self.assertEqual(Todo.by_date(self.db_conn, 'foo'), []) + with self.assertRaises(BadFormatException): + self.assertEqual(Todo.by_date(self.db_conn, 'foo'), []) def test_Todo_on_conditions(self) -> None: """Test effect of Todos on Conditions.""" @@ -153,11 +154,9 @@ class TestsWithDB(TestCaseWithDB): node_0.children += [node_4] self.assertEqual(todo_1.get_step_tree(set()), node_0) - def test_Todo_unsatisfied_steps(self) -> None: - """Test options of satisfying unfulfilled Process.explicit_steps.""" + def test_Todo_create_with_children(self) -> None: + """Test parenthood guaranteeds of Todo.create_with_children.""" assert isinstance(self.proc.id_, int) - todo_1 = Todo(None, self.proc, False, self.date1) - todo_1.save(self.db_conn) proc2 = Process(None) proc2.save(self.db_conn) assert isinstance(proc2.id_, int) @@ -167,35 +166,32 @@ class TestsWithDB(TestCaseWithDB): proc4 = Process(None) proc4.save(self.db_conn) assert isinstance(proc4.id_, int) - proc3.set_steps(self.db_conn, [(None, proc4.id_, None)]) - proc2.set_steps(self.db_conn, [(None, self.proc.id_, None), - (None, self.proc.id_, None), - (None, proc3.id_, None)]) - todo_2 = Todo(None, proc2, False, self.date1) - todo_2.save(self.db_conn) - # test empty adoption does nothing - todo_2.adopt_from([]) - self.assertEqual(todo_2.children, []) - # test basic adoption - todo_2.adopt_from([todo_1]) - self.assertEqual(todo_2.children, [todo_1]) - self.assertEqual(todo_1.parents, [todo_2]) - # test making missing children - todo_2.make_missing_children(self.db_conn) - todo_3 = Todo.by_id(self.db_conn, 3) - todo_4 = Todo.by_id(self.db_conn, 4) - self.assertEqual(todo_2.children, [todo_1, todo_3, todo_4]) - self.assertEqual(todo_3.process, self.proc) - self.assertEqual(todo_3.parents, [todo_2]) - self.assertEqual(todo_3.children, []) - self.assertEqual(todo_4.process, proc3) - self.assertEqual(todo_4.parents, [todo_2]) - # test .make_missing_children lower down the tree - todo_4.make_missing_children(self.db_conn) - todo_5 = Todo.by_id(self.db_conn, 5) - self.assertEqual(todo_5.process, proc4) - self.assertEqual(todo_4.children, [todo_5]) - self.assertEqual(todo_5.parents, [todo_4]) + # make proc4 step of proc3 + step = ProcessStep(None, proc3.id_, proc4.id_, None) + proc3.set_steps(self.db_conn, [step]) + # give proc2 three steps; 2× proc1, 1× proc3 + step1 = ProcessStep(None, proc2.id_, self.proc.id_, None) + step2 = ProcessStep(None, proc2.id_, self.proc.id_, None) + step3 = ProcessStep(None, proc2.id_, proc3.id_, None) + proc2.set_steps(self.db_conn, [step1, step2, step3]) + # test mere creation does nothing + todo_ignore = Todo(None, proc2, False, self.date1) + todo_ignore.save(self.db_conn) + self.assertEqual(todo_ignore.children, []) + # test create_with_children on step-less does nothing + todo_1 = Todo.create_with_children(self.db_conn, self.proc.id_, + self.date1) + self.assertEqual(todo_1.children, []) + self.assertEqual(len(Todo.all(self.db_conn)), 2) + # test create_with_children adopts and creates, and down tree too + todo_2 = Todo.create_with_children(self.db_conn, proc2.id_, self.date1) + self.assertEqual(3, len(todo_2.children)) + self.assertEqual(todo_1, todo_2.children[0]) + self.assertEqual(self.proc, todo_2.children[1].process) + self.assertEqual(proc3, todo_2.children[2].process) + todo_3 = todo_2.children[2] + self.assertEqual(len(todo_3.children), 1) + self.assertEqual(todo_3.children[0].process, proc4) def test_Todo_singularity(self) -> None: """Test pointers made for single object keep pointing to it.""" @@ -352,8 +348,8 @@ class TestsWithServer(TestCaseWithServer): assert isinstance(t.process.id_, int) return t.process.id_ - def check_adoption(date: str, new_todo: list[int]) -> None: - form_data = {'day_comment': '', 'new_todo': new_todo} + def check_adoption(date: str, new_todos: list[int]) -> None: + form_data = {'day_comment': '', 'new_todo': new_todos} self.check_post(form_data, f'/day?date={date}', 302) day_todos = Todo.by_date(self.db_conn, date) day_todos.sort(key=key_order_func) @@ -366,11 +362,12 @@ class TestsWithServer(TestCaseWithServer): def check_nesting_adoption(process_id: int, date: str, new_top_steps: list[int]) -> None: - result_reversed = new_top_steps[1] < new_top_steps[0] - form_data = self.post_process() - form_data = self.post_process(process_id, - form_data | - {'new_top_step': new_top_steps}) + form_data = {'title': '', 'description': '', 'effort': 1, + 'step_of': [2]} + form_data = self.post_process(1, form_data) + form_data['new_top_step'] = new_top_steps + form_data['step_of'] = [] + form_data = self.post_process(process_id, form_data) form_data = {'day_comment': '', 'new_todo': [process_id]} self.check_post(form_data, f'/day?date={date}', 302) day_todos = Todo.by_date(self.db_conn, date) @@ -379,15 +376,12 @@ class TestsWithServer(TestCaseWithServer): todo1 = day_todos[0] # process of process_id todo2 = day_todos[1] # process 2 todo3 = day_todos[2] # process 1 - if result_reversed: - self.assertEqual(todo1.children, [todo2, todo3]) - else: - self.assertEqual(todo1.children, [todo3, todo2]) + self.assertEqual(sorted(todo1.children), sorted([todo2, todo3])) self.assertEqual(todo1.parents, []) self.assertEqual(todo2.children, [todo3]) self.assertEqual(todo2.parents, [todo1]) self.assertEqual(todo3.children, []) - self.assertEqual(todo3.parents, [todo2, todo1]) + self.assertEqual(sorted(todo3.parents), sorted([todo2, todo1])) form_data = self.post_process() form_data = self.post_process(2, form_data | {'new_top_step': 1})