- todo_3.save(self.db_conn)
- todo_1.add_child(todo_3)
- todo_1.save(self.db_conn)
- assert isinstance(todo_1.id_, int)
- todo_retrieved = Todo.by_id(self.db_conn, todo_1.id_)
- self.assertEqual(todo_retrieved.children, [todo_3])
- with self.assertRaises(BadFormatException):
- todo_3.add_child(todo_1)
-
- def test_Todo_conditioning(self) -> None:
- """Test Todo.doability conditions."""
- assert isinstance(self.cond1.id_, int)
- todo_1 = Todo(None, self.proc, False, self.date1)
- todo_1.save(self.db_conn)
- todo_2 = Todo(None, self.proc, False, self.date1)
- todo_2.save(self.db_conn)
- todo_2.add_child(todo_1)
- with self.assertRaises(BadFormatException):
- todo_2.is_done = True
- todo_1.is_done = True
- todo_2.is_done = True
- todo_2.is_done = False
- todo_2.set_condition_relations(
- self.db_conn, [self.cond1.id_], [], [], [])
- with self.assertRaises(BadFormatException):
- todo_2.is_done = True
- self.cond1.is_active = True
- todo_2.is_done = True
-
- def test_Todo_step_tree(self) -> None:
- """Test self-configuration of TodoStepsNode tree for Day view."""
-
- def todo_node_as_dict(node: TodoNode) -> dict[str, object]:
- return {'todo': node.todo.id_, 'seen': node.seen,
- 'children': [todo_node_as_dict(c) for c in node.children]}
-
- todo_1 = Todo(None, self.proc, False, self.date1)
- todo_1.save(self.db_conn)
- assert isinstance(todo_1.id_, int)
- # test minimum
- node_0 = TodoNode(todo_1, False, [])
- cmp_0_dict = todo_node_as_dict(todo_1.get_step_tree(set()))
- cmp_1_dict = todo_node_as_dict(node_0)
- self.assertEqual(cmp_0_dict, cmp_1_dict)
- # test non_emtpy seen_todo does something
- node_0.seen = True
- cmp_0_dict = todo_node_as_dict(todo_1.get_step_tree({todo_1.id_}))
- cmp_1_dict = todo_node_as_dict(node_0)
- self.assertEqual(cmp_0_dict, cmp_1_dict)
- # test child shows up
- todo_2 = Todo(None, self.proc, False, self.date1)
- todo_2.save(self.db_conn)
- assert isinstance(todo_2.id_, int)
- todo_1.add_child(todo_2)
- node_2 = TodoNode(todo_2, False, [])
- node_0.children = [node_2]
- node_0.seen = False
- cmp_0_dict = todo_node_as_dict(todo_1.get_step_tree(set()))
- cmp_1_dict = todo_node_as_dict(node_0)
- self.assertEqual(cmp_0_dict, cmp_1_dict)
- # test child shows up with child
- todo_3 = Todo(None, self.proc, False, self.date1)
- todo_3.save(self.db_conn)
- assert isinstance(todo_3.id_, int)
- todo_2.add_child(todo_3)
- node_3 = TodoNode(todo_3, False, [])
- node_2.children = [node_3]
- cmp_0_dict = todo_node_as_dict(todo_1.get_step_tree(set()))
- cmp_1_dict = todo_node_as_dict(node_0)
- self.assertEqual(cmp_0_dict, cmp_1_dict)
- # test same todo can be child-ed multiple times at different locations
- todo_1.add_child(todo_3)
- node_4 = TodoNode(todo_3, True, [])
- node_0.children += [node_4]
- cmp_0_dict = todo_node_as_dict(todo_1.get_step_tree(set()))
- cmp_1_dict = todo_node_as_dict(node_0)
- self.assertEqual(cmp_0_dict, cmp_1_dict)
-
- def test_Todo_ensure_children(self) -> None:
- """Test parenthood guarantees of Todo.ensure_children."""
- assert isinstance(self.proc.id_, int)
- proc2 = Process(None)
- proc2.save(self.db_conn)
- assert isinstance(proc2.id_, int)
- proc3 = Process(None)
- proc3.save(self.db_conn)
- assert isinstance(proc3.id_, int)
- proc4 = Process(None)
- proc4.save(self.db_conn)
- assert isinstance(proc4.id_, int)
- # 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(None, self.proc, False, self.date1)
- todo_1.save(self.db_conn)
- todo_1.ensure_children(self.db_conn)
- 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(None, proc2, False, self.date1)
- todo_2.save(self.db_conn)
- todo_2.ensure_children(self.db_conn)
- self.assertEqual(3, len(todo_2.children))
- self.assertEqual(todo_1, todo_2.children[0])
- self.assertEqual(self.proc, todo_2.children[2].process)
- self.assertEqual(proc3, todo_2.children[1].process)
- todo_3 = todo_2.children[1]
- self.assertEqual(len(todo_3.children), 1)
- self.assertEqual(todo_3.children[0].process, proc4)