class TestsWithDB(TestCaseWithDB):
"""Tests requiring DB, but not server setup."""
+ checked_class = Todo
def setUp(self) -> None:
super().setUp()
self.cond2 = Condition(None)
self.cond2.save(self.db_conn)
- def test_Todo_by_id(self) -> None:
- """Test creation and findability of Todos."""
- process_unsaved = Process(None)
+ def test_Todo_init(self) -> None:
+ """Test creation of Todo and what they default to."""
+ process = Process(None)
with self.assertRaises(NotFoundException):
- todo = Todo(None, process_unsaved, False, self.date1)
- process_unsaved.save(self.db_conn)
- todo = Todo(None, process_unsaved, False, self.date1)
+ Todo(None, process, False, self.date1)
+ process.save(self.db_conn)
+ assert isinstance(self.cond1.id_, int)
+ assert isinstance(self.cond2.id_, int)
+ process.set_conditions(self.db_conn, [self.cond1.id_, self.cond2.id_])
+ process.set_enables(self.db_conn, [self.cond1.id_])
+ process.set_disables(self.db_conn, [self.cond2.id_])
+ todo_no_id = Todo(None, process, False, self.date1)
+ self.assertEqual(todo_no_id.conditions, [self.cond1, self.cond2])
+ self.assertEqual(todo_no_id.enables, [self.cond1])
+ self.assertEqual(todo_no_id.disables, [self.cond2])
+ todo_yes_id = Todo(5, process, False, self.date1)
+ self.assertEqual(todo_yes_id.conditions, [])
+ self.assertEqual(todo_yes_id.enables, [])
+ self.assertEqual(todo_yes_id.disables, [])
+
+ def test_Todo_saving_and_caching(self) -> None:
+ """Test .save."""
+ kwargs = {'id_': 1,
+ 'process': self.proc,
+ 'is_done': False,
+ 'date': self.date1}
+ self.check_saving_and_caching(**kwargs)
+ todo = Todo(None, self.proc, False, self.date1)
+ todo.save(self.db_conn)
+ self.assertEqual(todo.id_, 2)
+
+ def test_Todo_by_id(self) -> None:
+ """Test findability of Todos."""
+ todo = Todo(1, self.proc, False, self.date1)
todo.save(self.db_conn)
self.assertEqual(Todo.by_id(self.db_conn, 1), todo)
with self.assertRaises(NotFoundException):
self.assertEqual(Todo.by_date(self.db_conn, self.date2), [])
self.assertEqual(Todo.by_date(self.db_conn, 'foo'), [])
- def test_Todo_from_process(self) -> None:
- """Test spawning of Todo attributes from Process."""
- assert isinstance(self.cond1.id_, int)
- assert isinstance(self.cond2.id_, int)
- self.proc.set_conditions(self.db_conn, [self.cond1.id_])
- todo = Todo(None, self.proc, False, self.date1)
- self.assertEqual(todo.conditions, [self.cond1])
- todo.set_conditions(self.db_conn, [self.cond2.id_])
- self.assertEqual(todo.conditions, [self.cond2])
- self.assertEqual(self.proc.conditions, [self.cond1])
- self.proc.set_enables(self.db_conn, [self.cond1.id_])
- todo = Todo(None, self.proc, False, self.date1)
- self.assertEqual(todo.enables, [self.cond1])
- todo.set_enables(self.db_conn, [self.cond2.id_])
- self.assertEqual(todo.enables, [self.cond2])
- self.assertEqual(self.proc.enables, [self.cond1])
- self.proc.set_disables(self.db_conn, [self.cond1.id_])
- todo = Todo(None, self.proc, False, self.date1)
- self.assertEqual(todo.disables, [self.cond1])
- todo.set_disables(self.db_conn, [self.cond2.id_])
- self.assertEqual(todo.disables, [self.cond2])
- self.assertEqual(self.proc.disables, [self.cond1])
-
def test_Todo_on_conditions(self) -> None:
"""Test effect of Todos on Conditions."""
assert isinstance(self.cond1.id_, int)
def test_Todo_singularity(self) -> None:
"""Test pointers made for single object keep pointing to it."""
- todo = Todo(None, self.proc, False, self.date1)
- todo.save(self.db_conn)
- retrieved_todo = Todo.by_id(self.db_conn, 1)
- todo.is_done = True
- self.assertEqual(retrieved_todo.is_done, True)
- retrieved_todo = Todo.by_date(self.db_conn, self.date1)[0]
- retrieved_todo.is_done = False
- self.assertEqual(todo.is_done, False)
+ self.check_singularity('is_done', True, self.proc, False, self.date1)
def test_Todo_remove(self) -> None:
"""Test removal."""