From: Christian Heller Date: Sun, 5 May 2024 04:00:43 +0000 (+0200) Subject: Improve Todo tests. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/decks/static/git-logo.png?a=commitdiff_plain;h=5104eb7b33c386b6df7508405917408855e1468c;p=plomtask Improve Todo tests. --- diff --git a/tests/__pycache__/__init__.cpython-311.pyc b/tests/__pycache__/__init__.cpython-311.pyc deleted file mode 100644 index 61bbc59..0000000 Binary files a/tests/__pycache__/__init__.cpython-311.pyc and /dev/null differ diff --git a/tests/__pycache__/conditions.cpython-311.pyc b/tests/__pycache__/conditions.cpython-311.pyc deleted file mode 100644 index d671a08..0000000 Binary files a/tests/__pycache__/conditions.cpython-311.pyc and /dev/null differ diff --git a/tests/__pycache__/days.cpython-311.pyc b/tests/__pycache__/days.cpython-311.pyc deleted file mode 100644 index fcbd24a..0000000 Binary files a/tests/__pycache__/days.cpython-311.pyc and /dev/null differ diff --git a/tests/__pycache__/misc.cpython-311.pyc b/tests/__pycache__/misc.cpython-311.pyc deleted file mode 100644 index edb0671..0000000 Binary files a/tests/__pycache__/misc.cpython-311.pyc and /dev/null differ diff --git a/tests/__pycache__/processes.cpython-311.pyc b/tests/__pycache__/processes.cpython-311.pyc deleted file mode 100644 index 4f4c7f1..0000000 Binary files a/tests/__pycache__/processes.cpython-311.pyc and /dev/null differ diff --git a/tests/__pycache__/test_days.cpython-311.pyc b/tests/__pycache__/test_days.cpython-311.pyc deleted file mode 100644 index 61f606c..0000000 Binary files a/tests/__pycache__/test_days.cpython-311.pyc and /dev/null differ diff --git a/tests/__pycache__/todos.cpython-311.pyc b/tests/__pycache__/todos.cpython-311.pyc deleted file mode 100644 index 6aa0815..0000000 Binary files a/tests/__pycache__/todos.cpython-311.pyc and /dev/null differ diff --git a/tests/__pycache__/utils.cpython-311.pyc b/tests/__pycache__/utils.cpython-311.pyc deleted file mode 100644 index 5c85fd8..0000000 Binary files a/tests/__pycache__/utils.cpython-311.pyc and /dev/null differ diff --git a/tests/__pycache__/versioned_attributes.cpython-311.pyc b/tests/__pycache__/versioned_attributes.cpython-311.pyc deleted file mode 100644 index 7a33722..0000000 Binary files a/tests/__pycache__/versioned_attributes.cpython-311.pyc and /dev/null differ diff --git a/tests/todos.py b/tests/todos.py index 7fabfdb..7471565 100644 --- a/tests/todos.py +++ b/tests/todos.py @@ -9,6 +9,7 @@ from plomtask.exceptions import (NotFoundException, BadFormatException, class TestsWithDB(TestCaseWithDB): """Tests requiring DB, but not server setup.""" + checked_class = Todo def setUp(self) -> None: super().setUp() @@ -21,13 +22,40 @@ class TestsWithDB(TestCaseWithDB): 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): @@ -45,29 +73,6 @@ class TestsWithDB(TestCaseWithDB): 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) @@ -257,14 +262,7 @@ class TestsWithDB(TestCaseWithDB): 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.""" diff --git a/tests/utils.py b/tests/utils.py index bb37270..fb7e227 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -68,7 +68,7 @@ class TestCaseWithDB(TestCase): row)] self.assertEqual(sorted(content), sorted(db_found)) - def check_saving_and_caching(self, **kwargs: Any) -> Any: + def check_saving_and_caching(self, **kwargs: Any) -> None: """Test instance.save in its core without relations.""" obj = self.checked_class(**kwargs) # pylint: disable=not-callable # check object init itself doesn't store anything yet