home · contact · privacy
Slightly improve and re-organize Condition tests.
[plomtask] / tests / todos.py
index b73f5d7fcb7b0a2c53256593e8e9867e86d2b89e..dd57ee4c0c28cfc73d3d9c08dd6c18ab2dd7cd7b 100644 (file)
@@ -10,8 +10,8 @@ from plomtask.exceptions import (NotFoundException, BadFormatException,
 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
+    NB: We subclass TestCaseSansDB too, to pull in its .test_id_validation,
+    which for Todo wouldn't run without a DB being set up due to the need for
     Processes with set IDs.
     """
     checked_class = Todo
@@ -19,7 +19,6 @@ class TestsWithDB(TestCaseWithDB, TestCaseSansDB):
                            '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()
@@ -54,16 +53,6 @@ class TestsWithDB(TestCaseWithDB, TestCaseSansDB):
         self.assertEqual(todo_yes_id.enables, [])
         self.assertEqual(todo_yes_id.disables, [])
 
-    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):
-            Todo.by_id(self.db_conn, 0)
-        with self.assertRaises(NotFoundException):
-            Todo.by_id(self.db_conn, 2)
-
     def test_Todo_by_date(self) -> None:
         """Test findability of Todos by date."""
         t1 = Todo(None, self.proc, False, self.date1)
@@ -136,10 +125,11 @@ class TestsWithDB(TestCaseWithDB, TestCaseSansDB):
         assert isinstance(todo_1.id_, int)
         # test minimum
         node_0 = TodoNode(todo_1, False, [])
-        self.assertEqual(todo_1.get_step_tree(set()), node_0)
+        self.assertEqual(todo_1.get_step_tree(set()).as_dict, node_0.as_dict)
         # test non_emtpy seen_todo does something
         node_0.seen = True
-        self.assertEqual(todo_1.get_step_tree({todo_1.id_}), node_0)
+        self.assertEqual(todo_1.get_step_tree({todo_1.id_}).as_dict,
+                         node_0.as_dict)
         # test child shows up
         todo_2 = Todo(None, self.proc, False, self.date1)
         todo_2.save(self.db_conn)
@@ -148,7 +138,7 @@ class TestsWithDB(TestCaseWithDB, TestCaseSansDB):
         node_2 = TodoNode(todo_2, False, [])
         node_0.children = [node_2]
         node_0.seen = False
-        self.assertEqual(todo_1.get_step_tree(set()), node_0)
+        self.assertEqual(todo_1.get_step_tree(set()).as_dict, node_0.as_dict)
         # test child shows up with child
         todo_3 = Todo(None, self.proc, False, self.date1)
         todo_3.save(self.db_conn)
@@ -156,12 +146,12 @@ class TestsWithDB(TestCaseWithDB, TestCaseSansDB):
         todo_2.add_child(todo_3)
         node_3 = TodoNode(todo_3, False, [])
         node_2.children = [node_3]
-        self.assertEqual(todo_1.get_step_tree(set()), node_0)
+        self.assertEqual(todo_1.get_step_tree(set()).as_dict, node_0.as_dict)
         # test same todo can be child-ed multiple times at different locations
         todo_1.add_child(todo_3)
         node_4 = TodoNode(todo_3, True, [])
         node_0.children += [node_4]
-        self.assertEqual(todo_1.get_step_tree(set()), node_0)
+        self.assertEqual(todo_1.get_step_tree(set()).as_dict, node_0.as_dict)
 
     def test_Todo_create_with_children(self) -> None:
         """Test parenthood guaranteeds of Todo.create_with_children."""
@@ -202,14 +192,11 @@ class TestsWithDB(TestCaseWithDB, TestCaseSansDB):
         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)
@@ -237,6 +224,7 @@ class TestsWithDB(TestCaseWithDB, TestCaseSansDB):
         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_
@@ -257,19 +245,25 @@ class TestsWithServer(TestCaseWithServer):
         form_data = {'day_comment': '', 'make_type': 'full'}
         self.check_post(form_data, '/day?date=2024-01-01&make_type=full', 302)
         self.assertEqual(Todo.by_date(self.db_conn, '2024-01-01'), [])
+        proc = Process.by_id(self.db_conn, 1)
         form_data['new_todo'] = str(proc.id_)
         self.check_post(form_data, '/day?date=2024-01-01&make_type=full', 302)
         todos = Todo.by_date(self.db_conn, '2024-01-01')
         self.assertEqual(1, len(todos))
         todo1 = todos[0]
         self.assertEqual(todo1.id_, 1)
+        proc = Process.by_id(self.db_conn, 1)
         self.assertEqual(todo1.process.id_, proc.id_)
         self.assertEqual(todo1.is_done, False)
+        proc2 = Process.by_id(self.db_conn, 2)
         form_data['new_todo'] = str(proc2.id_)
         self.check_post(form_data, '/day?date=2024-01-01&make_type=full', 302)
         todos = Todo.by_date(self.db_conn, '2024-01-01')
         todo1 = todos[1]
         self.assertEqual(todo1.id_, 2)
+        proc2 = Process.by_id(self.db_conn, 1)
+        todo1 = Todo.by_date(self.db_conn, '2024-01-01')[0]
+        self.assertEqual(todo1.id_, 1)
         self.assertEqual(todo1.process.id_, proc2.id_)
         self.assertEqual(todo1.is_done, False)
 
@@ -286,7 +280,7 @@ class TestsWithServer(TestCaseWithServer):
                         '/day?date=2024-01-01&make_type=full', 302)
         # test posting to bad URLs
         self.check_post({}, '/todo=', 404)
-        self.check_post({}, '/todo?id=', 400)
+        self.check_post({}, '/todo?id=', 404)
         self.check_post({}, '/todo?id=FOO', 400)
         self.check_post({}, '/todo?id=0', 404)
         # test posting naked entity
@@ -412,12 +406,15 @@ class TestsWithServer(TestCaseWithServer):
         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]
-        form_data = {'day_comment': '', 'todo_id': [1], 'make_type': 'full'}
+        form_data = {'day_comment': '', 'todo_id': [1], 'make_type': 'full',
+                     'comment': [''], 'done': [], 'effort': ['']}
         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]
         self.assertEqual(todo.is_done, False)
         form_data = {'day_comment': '', 'todo_id': [1], 'done': [1],
-                     'make_type': 'full'}
+                     'make_type': 'full', 'comment': [''], 'effort': ['']}
         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]
         self.assertEqual(todo.is_done, True)
 
     def test_do_GET_todo(self) -> None:
@@ -425,8 +422,8 @@ class TestsWithServer(TestCaseWithServer):
         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)
-        self.check_get('/todo', 400)
-        self.check_get('/todo?id=', 400)
+        self.check_get('/todo', 404)
+        self.check_get('/todo?id=', 404)
         self.check_get('/todo?id=foo', 400)
         self.check_get('/todo?id=0', 404)
         self.check_get('/todo?id=1', 200)