home · contact · privacy
Refactor remaining test.utils helpers into actual tests.
[plomtask] / tests / todos.py
index 1a9eab61c0f77932c11b24ebae15cfc9a982287b..7632f39cf3b75674036452b609c7e90b3f379e34 100644 (file)
@@ -1,5 +1,5 @@
 """Test Todos module."""
-from tests.utils import TestCaseWithDB, TestCaseWithServer
+from tests.utils import TestCaseSansDB, TestCaseWithDB, TestCaseWithServer
 from plomtask.todos import Todo, TodoNode
 from plomtask.processes import Process, ProcessStep
 from plomtask.conditions import Condition
@@ -7,11 +7,19 @@ from plomtask.exceptions import (NotFoundException, BadFormatException,
                                  HandledException)
 
 
-class TestsWithDB(TestCaseWithDB):
-    """Tests requiring DB, but not server setup."""
+class TestsWithDB(TestCaseWithDB, TestCaseSansDB):
+    """Tests requiring DB, but not server setup.
+
+    NB: We subclass TestCaseSansDB too, to pull in its .test_id_setting, which
+    for Todo wouldn't run without a DB being set up due to the need for
+    Processes with set IDs.
+    """
     checked_class = Todo
     default_init_kwargs = {'process': None, 'is_done': False,
                            'date': '2024-01-01'}
+    # solely used for TestCaseSansDB.test_id_setting
+    default_init_args = [None, False, '2024-01-01']
+    do_id_test = True
 
     def setUp(self) -> None:
         super().setUp()
@@ -24,6 +32,7 @@ class TestsWithDB(TestCaseWithDB):
         self.cond2 = Condition(None)
         self.cond2.save(self.db_conn)
         self.default_init_kwargs['process'] = self.proc
+        self.default_init_args[0] = self.proc
 
     def test_Todo_init(self) -> None:
         """Test creation of Todo and what they default to."""
@@ -187,29 +196,27 @@ class TestsWithDB(TestCaseWithDB):
         todo_2 = Todo.create_with_children(self.db_conn, proc2.id_, self.date1)
         self.assertEqual(3, len(todo_2.children))
         self.assertEqual(todo_1, todo_2.children[0])
-        self.assertEqual(self.proc, todo_2.children[1].process)
-        self.assertEqual(proc3, todo_2.children[2].process)
-        todo_3 = todo_2.children[2]
+        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)
 
-    def test_Todo_singularity(self) -> None:
-        """Test pointers made for single object keep pointing to it."""
-        self.check_singularity('is_done', True, self.proc, False, self.date1)
-
     def test_Todo_remove(self) -> None:
         """Test removal."""
         todo_1 = Todo(None, self.proc, False, self.date1)
         todo_1.save(self.db_conn)
+        assert todo_1.id_ is not None
         todo_0 = Todo(None, self.proc, False, self.date1)
         todo_0.save(self.db_conn)
         todo_0.add_child(todo_1)
         todo_2 = Todo(None, self.proc, False, self.date1)
         todo_2.save(self.db_conn)
         todo_1.add_child(todo_2)
+        todo_1_id = todo_1.id_
         todo_1.remove(self.db_conn)
         with self.assertRaises(NotFoundException):
-            Todo.by_id(self.db_conn, todo_1.id_)
+            Todo.by_id(self.db_conn, todo_1_id)
         self.assertEqual(todo_0.children, [])
         self.assertEqual(todo_2.parents, [])
         todo_2.comment = 'foo'
@@ -227,11 +234,13 @@ class TestsWithDB(TestCaseWithDB):
         todo_1.comment = 'foo'
         todo_1.effort = -0.1
         todo_1.save(self.db_conn)
+        assert todo_1.id_ is not None
         Todo.by_id(self.db_conn, todo_1.id_)
         todo_1.comment = ''
+        todo_1_id = todo_1.id_
         todo_1.save(self.db_conn)
         with self.assertRaises(NotFoundException):
-            Todo.by_id(self.db_conn, todo_1.id_)
+            Todo.by_id(self.db_conn, todo_1_id)
 
 
 class TestsWithServer(TestCaseWithServer):
@@ -397,7 +406,7 @@ class TestsWithServer(TestCaseWithServer):
 
     def test_do_POST_day_todo_doneness(self) -> None:
         """Test Todo doneness can be posted to Day view."""
-        form_data = self.post_process()
+        self.post_process()
         form_data = {'day_comment': '', 'new_todo': [1], 'make_type': 'full'}
         self.check_post(form_data, '/day?date=2024-01-01&make_type=full', 302)
         todo = Todo.by_date(self.db_conn, '2024-01-01')[0]