+ def test_Todo_from_process(self) -> None:
+ """Test spawning of Todo attributes from Process."""
+ day = Day('2024-01-01')
+ process = Process(None)
+ c1 = Condition(None, False)
+ c1.save(self.db_conn)
+ assert c1.id_ is not None
+ c2 = Condition(None, True)
+ c2.save(self.db_conn)
+ assert c2.id_ is not None
+ process.set_conditions(self.db_conn, [c1.id_])
+ todo = Todo(None, process, False, day)
+ self.assertEqual(todo.conditions, [c1])
+ todo.set_conditions(self.db_conn, [c2.id_])
+ self.assertEqual(todo.conditions, [c2])
+ self.assertEqual(process.conditions, [c1])
+ process.set_fulfills(self.db_conn, [c1.id_])
+ todo = Todo(None, process, False, day)
+ self.assertEqual(todo.fulfills, [c1])
+ todo.set_fulfills(self.db_conn, [c2.id_])
+ self.assertEqual(todo.fulfills, [c2])
+ self.assertEqual(process.fulfills, [c1])
+ process.set_undoes(self.db_conn, [c1.id_])
+ todo = Todo(None, process, False, day)
+ self.assertEqual(todo.undoes, [c1])
+ todo.set_undoes(self.db_conn, [c2.id_])
+ self.assertEqual(todo.undoes, [c2])
+ self.assertEqual(process.undoes, [c1])
+
+ def test_Todo_on_conditions(self) -> None:
+ """Test effect of Todos on Conditions."""
+ day = Day('2024-01-01')
+ process = Process(None)
+ process.save_without_steps(self.db_conn)
+ c1 = Condition(None, False)
+ c2 = Condition(None, True)
+ c1.save(self.db_conn)
+ c2.save(self.db_conn)
+ assert c1.id_ is not None
+ assert c2.id_ is not None
+ todo = Todo(None, process, False, day)
+ todo.save(self.db_conn)
+ todo.set_fulfills(self.db_conn, [c1.id_])
+ todo.set_undoes(self.db_conn, [c2.id_])
+ todo.is_done = True
+ self.assertEqual(c1.is_active, True)
+ self.assertEqual(c2.is_active, False)
+ todo.is_done = False
+ self.assertEqual(c1.is_active, True)
+ self.assertEqual(c2.is_active, False)
+
+ def test_Todo_enablers_disablers(self) -> None:
+ """Test Todo.enablers_for_at/disablers_for_at."""
+ day1 = Day('2024-01-01')
+ day2 = Day('2024-01-02')
+ process = Process(None)
+ process.save_without_steps(self.db_conn)
+ c1 = Condition(None, False)
+ c2 = Condition(None, True)
+ c1.save(self.db_conn)
+ c2.save(self.db_conn)
+ todo1 = Todo(None, process, False, day1)
+ todo1.save(self.db_conn)
+ assert c1.id_ is not None
+ assert c2.id_ is not None
+ todo1.set_fulfills(self.db_conn, [c1.id_])
+ todo1.set_undoes(self.db_conn, [c2.id_])
+ todo1.save(self.db_conn)
+ assert todo1.id_ is not None
+ todo2 = Todo(None, process, False, day1)
+ todo2.save(self.db_conn)
+ assert todo2.id_ is not None
+ todo2.set_fulfills(self.db_conn, [c2.id_])
+ todo2.save(self.db_conn)
+ todo3 = Todo(None, process, False, day2)
+ todo3.save(self.db_conn)
+ assert todo3.id_ is not None
+ todo3.set_fulfills(self.db_conn, [c2.id_])
+ todo3.save(self.db_conn)
+ self.assertEqual(Todo.enablers_for_at(self.db_conn, c1, day1.date),
+ [todo1])
+ self.assertEqual(Todo.enablers_for_at(self.db_conn, c1, day2.date),
+ [])
+ self.assertEqual(Todo.disablers_for_at(self.db_conn, c1, day1.date),
+ [])
+ self.assertEqual(Todo.disablers_for_at(self.db_conn, c1, day2.date),
+ [])
+ self.assertEqual(Todo.enablers_for_at(self.db_conn, c2, day1.date),
+ [todo2])
+ self.assertEqual(Todo.enablers_for_at(self.db_conn, c2, day2.date),
+ [todo3])
+ self.assertEqual(Todo.disablers_for_at(self.db_conn, c2, day1.date),
+ [todo1])
+ self.assertEqual(Todo.disablers_for_at(self.db_conn, c2, day2.date),
+ [])
+