X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=tests%2Ftodos.py;h=8b8099f509a70029b45a24cef229cca162985e73;hb=df81cce527b2084738523a35f49d9c53045af31d;hp=9317c398b255c51b14046f888b3de4a24b70238d;hpb=c5449a0b00f8865b1129ed56bdd16f1cc055bc87;p=plomtask diff --git a/tests/todos.py b/tests/todos.py index 9317c39..8b8099f 100644 --- a/tests/todos.py +++ b/tests/todos.py @@ -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,18 @@ 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_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 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'] def setUp(self) -> None: super().setUp() @@ -24,6 +31,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.""" @@ -45,16 +53,6 @@ class TestsWithDB(TestCaseWithDB): 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) @@ -127,10 +125,11 @@ class TestsWithDB(TestCaseWithDB): 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) @@ -139,7 +138,7 @@ class TestsWithDB(TestCaseWithDB): 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) @@ -147,12 +146,12 @@ class TestsWithDB(TestCaseWithDB): 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.""" @@ -193,14 +192,11 @@ class TestsWithDB(TestCaseWithDB): 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) @@ -228,6 +224,7 @@ 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_