+ def test_Todo_step_tree(self) -> None:
+ """Test self-configuration of TodoStepsNode tree for Day view."""
+ assert isinstance(self.cond1.id_, int)
+ assert isinstance(self.cond2.id_, int)
+ todo_1 = Todo(None, self.proc, False, self.date1)
+ todo_1.save(self.db_conn)
+ assert isinstance(todo_1.id_, int)
+ # test minimum
+ tree_expected = TodoStepsNode(todo_1, True, [], False)
+ self.assertEqual(todo_1.get_step_tree(set(), set()), tree_expected)
+ # test non_emtpy seen_todo does something
+ tree_expected = TodoStepsNode(todo_1, True, [], True)
+ self.assertEqual(todo_1.get_step_tree({todo_1.id_}, set()),
+ tree_expected)
+ # 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_todo_2 = TodoStepsNode(todo_2, True, [], False)
+ tree_expected = TodoStepsNode(todo_1, True, [node_todo_2], False)
+ self.assertEqual(todo_1.get_step_tree(set(), set()), tree_expected)
+ # 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_todo_3 = TodoStepsNode(todo_3, True, [], False)
+ node_todo_2 = TodoStepsNode(todo_2, True, [node_todo_3], False)
+ tree_expected = TodoStepsNode(todo_1, True, [node_todo_2], False)
+ self.assertEqual(todo_1.get_step_tree(set(), set()), tree_expected)
+ # test same todo can be child-ed multiple times at different locations
+ todo_1.add_child(todo_3)
+ node_todo_4 = TodoStepsNode(todo_3, True, [], True)
+ tree_expected = TodoStepsNode(todo_1, True,
+ [node_todo_2, node_todo_4], False)
+ self.assertEqual(todo_1.get_step_tree(set(), set()), tree_expected)
+ # test condition shows up
+ todo_1.set_conditions(self.db_conn, [self.cond1.id_])
+ node_cond_1 = TodoStepsNode(self.cond1, False, [], False)
+ tree_expected = TodoStepsNode(todo_1, True,
+ [node_todo_2, node_todo_4, node_cond_1],
+ False)
+ self.assertEqual(todo_1.get_step_tree(set(), set()), tree_expected)
+ # test second condition shows up
+ todo_2.set_conditions(self.db_conn, [self.cond2.id_])
+ node_cond_2 = TodoStepsNode(self.cond2, False, [], False)
+ node_todo_2 = TodoStepsNode(todo_2, True,
+ [node_todo_3, node_cond_2], False)
+ tree_expected = TodoStepsNode(todo_1, True,
+ [node_todo_2, node_todo_4, node_cond_1],
+ False)
+ self.assertEqual(todo_1.get_step_tree(set(), set()), tree_expected)
+ # test second condition is not hidden if fulfilled by non-sibling
+ todo_1.set_enables(self.db_conn, [self.cond2.id_])
+ self.assertEqual(todo_1.get_step_tree(set(), set()), tree_expected)
+ # test second condition is hidden if fulfilled by sibling
+ todo_3.set_enables(self.db_conn, [self.cond2.id_])
+ node_todo_2 = TodoStepsNode(todo_2, True, [node_todo_3], False)
+ tree_expected = TodoStepsNode(todo_1, True,
+ [node_todo_2, node_todo_4, node_cond_1],
+ False)
+ self.assertEqual(todo_1.get_step_tree(set(), set()), tree_expected)
+