From: Christian Heller Date: Tue, 16 Apr 2024 02:29:43 +0000 (+0200) Subject: Some test refactoring. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/static/%7B%7Byoutube_prefix%7D%7D%7B%7Bvideo_data.id_%7D%7D?a=commitdiff_plain;h=b8207d9912e195d4693457060244cde37c8c53cd;p=plomtask Some test refactoring. --- diff --git a/tests/days.py b/tests/days.py index 2e2ef50..3524a66 100644 --- a/tests/days.py +++ b/tests/days.py @@ -49,32 +49,36 @@ class TestsWithDB(TestCaseWithDB): def test_Day_all(self) -> None: """Test Day.all(), especially in regards to date range filtering.""" - day1 = Day('2024-01-01') - day2 = Day('2024-01-02') - day3 = Day('2024-01-03') + date1 = '2024-01-01' + date2 = '2024-01-02' + date3 = '2024-01-03' + day1 = Day(date1) + day2 = Day(date2) + day3 = Day(date3) day1.save(self.db_conn) day2.save(self.db_conn) day3.save(self.db_conn) - self.assertEqual(Day.all(self.db_conn), [day1, day2, day3]) + self.assertEqual(Day.all(self.db_conn), + [day1, day2, day3]) self.assertEqual(Day.all(self.db_conn, ('', '')), [day1, day2, day3]) - self.assertEqual(Day.all(self.db_conn, ('2024-01-01', '2024-01-03')), + self.assertEqual(Day.all(self.db_conn, (date1, date3)), [day1, day2, day3]) - self.assertEqual(Day.all(self.db_conn, ('2024-01-02', '2024-01-03')), + self.assertEqual(Day.all(self.db_conn, (date2, date3)), [day2, day3]) - self.assertEqual(Day.all(self.db_conn, ('2024-01-03', '')), + self.assertEqual(Day.all(self.db_conn, (date3, '')), [day3]) - self.assertEqual(Day.all(self.db_conn, ('2024-01-01', '')), + self.assertEqual(Day.all(self.db_conn, (date1, '')), [day1, day2, day3]) - self.assertEqual(Day.all(self.db_conn, ('', '2024-01-02')), + self.assertEqual(Day.all(self.db_conn, ('', date2)), [day1, day2]) - self.assertEqual(Day.all(self.db_conn, ('2024-01-03', '2024-01-01')), + self.assertEqual(Day.all(self.db_conn, (date3, date1)), []) day4 = Day('2024-01-04') day5 = Day('2024-01-05') day6 = Day('2024-01-06') day6.save(self.db_conn) - self.assertEqual(Day.all(self.db_conn, ('2024-01-02', '2024-01-07'), + self.assertEqual(Day.all(self.db_conn, (date2, '2024-01-07'), fill_gaps=True), [day2, day3, day4, day5, day6]) today = Day(todays_date()) diff --git a/tests/processes.py b/tests/processes.py index 539d86f..390b130 100644 --- a/tests/processes.py +++ b/tests/processes.py @@ -25,131 +25,94 @@ class TestsSansDB(TestCase): class TestsWithDB(TestCaseWithDB): """Mdule tests not requiring DB setup.""" + def setUp(self) -> None: + super().setUp() + self.proc1 = Process(None) + self.proc1.save_without_steps(self.db_conn) + self.proc2 = Process(None) + self.proc2.save_without_steps(self.db_conn) + self.proc3 = Process(None) + self.proc3.save_without_steps(self.db_conn) + def test_Process_ids(self) -> None: """Test Process.save_without_steps() re Process.id_.""" - p = Process(None) - p.save_without_steps(self.db_conn) - self.assertEqual(p.id_, + self.assertEqual(self.proc1.id_, Process.by_id(self.db_conn, 1, create=False).id_) - p = Process(None) - p.save_without_steps(self.db_conn) - self.assertEqual(p.id_, + self.assertEqual(self.proc2.id_, Process.by_id(self.db_conn, 2, create=False).id_) - p = Process(5) - p.save_without_steps(self.db_conn) - self.assertEqual(p.id_, + proc5 = Process(5) + proc5.save_without_steps(self.db_conn) + self.assertEqual(proc5.id_, Process.by_id(self.db_conn, 5, create=False).id_) def test_Process_steps(self) -> None: """Test addition, nesting, and non-recursion of ProcessSteps""" - p_1 = Process(1) - p_1.save_without_steps(self.db_conn) - assert p_1.id_ is not None - p_2 = Process(2) - p_2.save_without_steps(self.db_conn) - assert p_2.id_ is not None - p_3 = Process(3) - p_3.save_without_steps(self.db_conn) - assert p_3.id_ is not None - p_1.add_step(self.db_conn, None, p_2.id_, None) + assert self.proc2.id_ is not None + assert self.proc3.id_ is not None + self.proc1.add_step(self.db_conn, None, self.proc2.id_, None) p_1_dict: dict[int, dict[str, Any]] = {1: { - 'process': p_2, 'parent_id': None, + 'process': self.proc2, 'parent_id': None, 'is_explicit': True, 'steps': {}, 'seen': False }} - self.assertEqual(p_1.get_steps(self.db_conn, None), p_1_dict) - s_b = p_1.add_step(self.db_conn, None, p_3.id_, None) + self.assertEqual(self.proc1.get_steps(self.db_conn, None), p_1_dict) + s_b = self.proc1.add_step(self.db_conn, None, self.proc3.id_, None) p_1_dict[2] = { - 'process': p_3, 'parent_id': None, + 'process': self.proc3, 'parent_id': None, 'is_explicit': True, 'steps': {}, 'seen': False } - self.assertEqual(p_1.get_steps(self.db_conn, None), p_1_dict) - s_c = p_2.add_step(self.db_conn, None, p_3.id_, None) + self.assertEqual(self.proc1.get_steps(self.db_conn, None), p_1_dict) + s_c = self.proc2.add_step(self.db_conn, None, self.proc3.id_, None) assert s_c.id_ is not None p_1_dict[1]['steps'] = {3: { - 'process': p_3, 'parent_id': None, + 'process': self.proc3, 'parent_id': None, 'is_explicit': False, 'steps': {}, 'seen': False }} - self.assertEqual(p_1.get_steps(self.db_conn, None), p_1_dict) - p_1.add_step(self.db_conn, None, p_2.id_, s_b.id_) + self.assertEqual(self.proc1.get_steps(self.db_conn, None), p_1_dict) + self.proc1.add_step(self.db_conn, None, self.proc2.id_, s_b.id_) p_1_dict[2]['steps'][4] = { - 'process': p_2, 'parent_id': s_b.id_, 'seen': False, + 'process': self.proc2, 'parent_id': s_b.id_, 'seen': False, 'is_explicit': True, 'steps': {3: { - 'process': p_3, 'parent_id': None, + 'process': self.proc3, 'parent_id': None, 'is_explicit': False, 'steps': {}, 'seen': True }}} - self.assertEqual(p_1.get_steps(self.db_conn, None), p_1_dict) - p_1.add_step(self.db_conn, None, p_3.id_, 999) + self.assertEqual(self.proc1.get_steps(self.db_conn, None), p_1_dict) + self.proc1.add_step(self.db_conn, None, self.proc3.id_, 999) p_1_dict[5] = { - 'process': p_3, 'parent_id': None, + 'process': self.proc3, 'parent_id': None, 'is_explicit': True, 'steps': {}, 'seen': False } - self.assertEqual(p_1.get_steps(self.db_conn, None), p_1_dict) - p_1.add_step(self.db_conn, None, p_3.id_, 3) + self.assertEqual(self.proc1.get_steps(self.db_conn, None), p_1_dict) + self.proc1.add_step(self.db_conn, None, self.proc3.id_, 3) p_1_dict[6] = { - 'process': p_3, 'parent_id': None, + 'process': self.proc3, 'parent_id': None, 'is_explicit': True, 'steps': {}, 'seen': False } - self.assertEqual(p_1.get_steps(self.db_conn, None), p_1_dict) - self.assertEqual(p_1.used_as_step_by(self.db_conn), []) - self.assertEqual(p_2.used_as_step_by(self.db_conn), [p_1]) - self.assertEqual(p_3.used_as_step_by(self.db_conn), [p_1, p_2]) - - def test_Process_undoes(self) -> None: - """Test setting Process.undoes""" - p = Process(None) - p.set_undoes(self.db_conn, []) - p.set_undoes(self.db_conn, []) - self.assertEqual(p.undoes, []) - c1 = Condition(None, False) - c1.save(self.db_conn) - assert c1.id_ is not None - p.set_undoes(self.db_conn, [c1.id_]) - self.assertEqual(p.undoes, [c1]) - c2 = Condition(None, False) - c2.save(self.db_conn) - assert c2.id_ is not None - p.set_undoes(self.db_conn, [c2.id_]) - self.assertEqual(p.undoes, [c2]) - p.set_undoes(self.db_conn, [c1.id_, c2.id_]) - self.assertEqual(p.undoes, [c1, c2]) - - def test_Process_fulfills(self) -> None: - """Test setting Process.fulfills""" - p = Process(None) - p.set_fulfills(self.db_conn, []) - p.set_fulfills(self.db_conn, []) - self.assertEqual(p.fulfills, []) - c1 = Condition(None, False) - c1.save(self.db_conn) - assert c1.id_ is not None - p.set_fulfills(self.db_conn, [c1.id_]) - self.assertEqual(p.fulfills, [c1]) - c2 = Condition(None, False) - c2.save(self.db_conn) - assert c2.id_ is not None - p.set_fulfills(self.db_conn, [c2.id_]) - self.assertEqual(p.fulfills, [c2]) - p.set_fulfills(self.db_conn, [c1.id_, c2.id_]) - self.assertEqual(p.fulfills, [c1, c2]) + self.assertEqual(self.proc1.get_steps(self.db_conn, None), + p_1_dict) + self.assertEqual(self.proc1.used_as_step_by(self.db_conn), + []) + self.assertEqual(self.proc2.used_as_step_by(self.db_conn), + [self.proc1]) + self.assertEqual(self.proc3.used_as_step_by(self.db_conn), + [self.proc1, self.proc2]) def test_Process_conditions(self) -> None: - """Test setting Process.conditions""" - p = Process(None) - p.set_conditions(self.db_conn, []) - p.set_conditions(self.db_conn, []) - self.assertEqual(p.conditions, []) - c1 = Condition(None, False) - c1.save(self.db_conn) - assert c1.id_ is not None - p.set_conditions(self.db_conn, [c1.id_]) - self.assertEqual(p.conditions, [c1]) - c2 = Condition(None, False) - c2.save(self.db_conn) - assert c2.id_ is not None - p.set_conditions(self.db_conn, [c2.id_]) - self.assertEqual(p.conditions, [c2]) - p.set_conditions(self.db_conn, [c1.id_, c2.id_]) - self.assertEqual(p.conditions, [c1, c2]) + """Test setting Process.conditions/fulfills/undoes.""" + for target in ('conditions', 'fulfills', 'undoes'): + c1 = Condition(None, False) + c1.save(self.db_conn) + assert c1.id_ is not None + c2 = Condition(None, False) + c2.save(self.db_conn) + assert c2.id_ is not None + self.proc1.set_conditions(self.db_conn, [], target) + self.assertEqual(getattr(self.proc1, target), []) + self.proc1.set_conditions(self.db_conn, [c1.id_], target) + self.assertEqual(getattr(self.proc1, target), [c1]) + self.proc1.set_conditions(self.db_conn, [c2.id_], target) + self.assertEqual(getattr(self.proc1, target), [c2]) + self.proc1.set_conditions(self.db_conn, [c1.id_, c2.id_], target) + self.assertEqual(getattr(self.proc1, target), [c1, c2]) def test_Process_by_id(self) -> None: """Test Process.by_id().""" @@ -157,32 +120,20 @@ class TestsWithDB(TestCaseWithDB): Process.by_id(self.db_conn, None, create=False) with self.assertRaises(NotFoundException): Process.by_id(self.db_conn, 0, create=False) - with self.assertRaises(NotFoundException): - Process.by_id(self.db_conn, 1, create=False) - self.assertNotEqual(Process(1).id_, + self.assertNotEqual(self.proc1.id_, Process.by_id(self.db_conn, None, create=True).id_) - self.assertEqual(Process(1).id_, - Process.by_id(self.db_conn, 1, create=True).id_) self.assertEqual(Process(2).id_, Process.by_id(self.db_conn, 2, create=True).id_) def test_Process_all(self) -> None: """Test Process.all().""" - p_1 = Process(None) - p_1.save_without_steps(self.db_conn) - p_2 = Process(None) - p_2.save_without_steps(self.db_conn) - self.assertEqual({p_1.id_, p_2.id_}, + self.assertEqual({self.proc1.id_, self.proc2.id_, self.proc3.id_}, set(p.id_ for p in Process.all(self.db_conn))) def test_ProcessStep_singularity(self) -> None: """Test pointers made for single object keep pointing to it.""" - p_1 = Process(None) - p_1.save_without_steps(self.db_conn) - p_2 = Process(None) - p_2.save_without_steps(self.db_conn) - assert p_2.id_ is not None - step = p_1.add_step(self.db_conn, None, p_2.id_, None) + assert self.proc2.id_ is not None + step = self.proc1.add_step(self.db_conn, None, self.proc2.id_, None) assert step.id_ is not None step_retrieved = ProcessStep.by_id(self.db_conn, step.id_) step.parent_step_id = 99 @@ -190,22 +141,16 @@ class TestsWithDB(TestCaseWithDB): def test_Process_singularity(self) -> None: """Test pointers made for single object keep pointing to it.""" - p_1 = Process(None) - p_1.save_without_steps(self.db_conn) - p_2 = Process(None) - p_2.save_without_steps(self.db_conn) - assert p_2.id_ is not None - p_1.add_step(self.db_conn, None, p_2.id_, None) - p_retrieved = Process.by_id(self.db_conn, p_1.id_) - self.assertEqual(p_1.explicit_steps, p_retrieved.explicit_steps) + assert self.proc2.id_ is not None + self.proc1.add_step(self.db_conn, None, self.proc2.id_, None) + p_retrieved = Process.by_id(self.db_conn, self.proc1.id_) + self.assertEqual(self.proc1.explicit_steps, p_retrieved.explicit_steps) def test_Process_versioned_attributes_singularity(self) -> None: """Test behavior of VersionedAttributes on saving (with .title).""" - p = Process(None) - p.save_without_steps(self.db_conn) - p.title.set('named') - p_loaded = Process.by_id(self.db_conn, p.id_) - self.assertEqual(p.title.history, p_loaded.title.history) + self.proc1.title.set('named') + p_loaded = Process.by_id(self.db_conn, self.proc1.id_) + self.assertEqual(self.proc1.title.history, p_loaded.title.history) class TestsWithServer(TestCaseWithServer): diff --git a/tests/todos.py b/tests/todos.py index 98c2aaf..f33534d 100644 --- a/tests/todos.py +++ b/tests/todos.py @@ -11,14 +11,26 @@ from plomtask.exceptions import (NotFoundException, BadFormatException, class TestsWithDB(TestCaseWithDB): """Tests requiring DB, but not server setup.""" + def setUp(self) -> None: + super().setUp() + self.day1 = Day('2024-01-01') + self.day1.save(self.db_conn) + self.day2 = Day('2024-01-02') + self.day2.save(self.db_conn) + self.proc = Process(None) + self.proc.save_without_steps(self.db_conn) + self.cond1 = Condition(None) + self.cond1.save(self.db_conn) + self.cond2 = Condition(None) + self.cond2.save(self.db_conn) + def test_Todo_by_id(self) -> None: """Test creation and findability of Todos.""" - day = Day('2024-01-01') - process = Process(None) - todo = Todo(None, process, False, day) + process_unsaved = Process(None) + todo = Todo(None, process_unsaved, False, self.day1) with self.assertRaises(NotFoundException): todo.save(self.db_conn) - process.save_without_steps(self.db_conn) + process_unsaved.save_without_steps(self.db_conn) todo.save(self.db_conn) self.assertEqual(Todo.by_id(self.db_conn, 1), todo) with self.assertRaises(NotFoundException): @@ -28,121 +40,92 @@ class TestsWithDB(TestCaseWithDB): def test_Todo_by_date(self) -> None: """Test findability of Todos by date.""" - day1 = Day('2024-01-01') - day2 = Day('2024-01-02') - process = Process(None) - process.save_without_steps(self.db_conn) - todo1 = Todo(None, process, False, day1) - todo1.save(self.db_conn) - todo2 = Todo(None, process, False, day1) - todo2.save(self.db_conn) - self.assertEqual(Todo.by_date(self.db_conn, day1.date), [todo1, todo2]) - self.assertEqual(Todo.by_date(self.db_conn, day2.date), []) + t1 = Todo(None, self.proc, False, self.day1) + t1.save(self.db_conn) + t2 = Todo(None, self.proc, False, self.day1) + t2.save(self.db_conn) + self.assertEqual(Todo.by_date(self.db_conn, self.day1.date), [t1, t2]) + self.assertEqual(Todo.by_date(self.db_conn, self.day2.date), []) self.assertEqual(Todo.by_date(self.db_conn, 'foo'), []) def test_Todo_from_process(self) -> None: """Test spawning of Todo attributes from Process.""" - day = Day('2024-01-01') - process = Process(None) - c1 = Condition(None, False) - c1.save(self.db_conn) - assert c1.id_ is not None - c2 = Condition(None, True) - c2.save(self.db_conn) - assert c2.id_ is not None - process.set_conditions(self.db_conn, [c1.id_]) - todo = Todo(None, process, False, day) - self.assertEqual(todo.conditions, [c1]) - todo.set_conditions(self.db_conn, [c2.id_]) - self.assertEqual(todo.conditions, [c2]) - self.assertEqual(process.conditions, [c1]) - process.set_fulfills(self.db_conn, [c1.id_]) - todo = Todo(None, process, False, day) - self.assertEqual(todo.fulfills, [c1]) - todo.set_fulfills(self.db_conn, [c2.id_]) - self.assertEqual(todo.fulfills, [c2]) - self.assertEqual(process.fulfills, [c1]) - process.set_undoes(self.db_conn, [c1.id_]) - todo = Todo(None, process, False, day) - self.assertEqual(todo.undoes, [c1]) - todo.set_undoes(self.db_conn, [c2.id_]) - self.assertEqual(todo.undoes, [c2]) - self.assertEqual(process.undoes, [c1]) + assert self.cond1.id_ is not None + assert self.cond2.id_ is not None + self.proc.set_conditions(self.db_conn, [self.cond1.id_]) + todo = Todo(None, self.proc, False, self.day1) + 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_fulfills(self.db_conn, [self.cond1.id_]) + todo = Todo(None, self.proc, False, self.day1) + self.assertEqual(todo.fulfills, [self.cond1]) + todo.set_fulfills(self.db_conn, [self.cond2.id_]) + self.assertEqual(todo.fulfills, [self.cond2]) + self.assertEqual(self.proc.fulfills, [self.cond1]) + self.proc.set_undoes(self.db_conn, [self.cond1.id_]) + todo = Todo(None, self.proc, False, self.day1) + self.assertEqual(todo.undoes, [self.cond1]) + todo.set_undoes(self.db_conn, [self.cond2.id_]) + self.assertEqual(todo.undoes, [self.cond2]) + self.assertEqual(self.proc.undoes, [self.cond1]) def test_Todo_on_conditions(self) -> None: """Test effect of Todos on Conditions.""" - day = Day('2024-01-01') - process = Process(None) - process.save_without_steps(self.db_conn) - c1 = Condition(None, False) - c2 = Condition(None, True) - c1.save(self.db_conn) - c2.save(self.db_conn) - assert c1.id_ is not None - assert c2.id_ is not None - todo = Todo(None, process, False, day) + assert self.cond1.id_ is not None + assert self.cond2.id_ is not None + todo = Todo(None, self.proc, False, self.day1) todo.save(self.db_conn) - todo.set_fulfills(self.db_conn, [c1.id_]) - todo.set_undoes(self.db_conn, [c2.id_]) + todo.set_fulfills(self.db_conn, [self.cond1.id_]) + todo.set_undoes(self.db_conn, [self.cond2.id_]) todo.is_done = True - self.assertEqual(c1.is_active, True) - self.assertEqual(c2.is_active, False) + self.assertEqual(self.cond1.is_active, True) + self.assertEqual(self.cond2.is_active, False) todo.is_done = False - self.assertEqual(c1.is_active, True) - self.assertEqual(c2.is_active, False) + self.assertEqual(self.cond1.is_active, True) + self.assertEqual(self.cond2.is_active, False) def test_Todo_enablers_disablers(self) -> None: """Test Todo.enablers_for_at/disablers_for_at.""" - day1 = Day('2024-01-01') - day2 = Day('2024-01-02') - process = Process(None) - process.save_without_steps(self.db_conn) - c1 = Condition(None, False) - c2 = Condition(None, True) - c1.save(self.db_conn) - c2.save(self.db_conn) - todo1 = Todo(None, process, False, day1) + assert self.cond1.id_ is not None + assert self.cond2.id_ is not None + todo1 = Todo(None, self.proc, False, self.day1) todo1.save(self.db_conn) - assert c1.id_ is not None - assert c2.id_ is not None - todo1.set_fulfills(self.db_conn, [c1.id_]) - todo1.set_undoes(self.db_conn, [c2.id_]) + todo1.set_fulfills(self.db_conn, [self.cond1.id_]) + todo1.set_undoes(self.db_conn, [self.cond2.id_]) todo1.save(self.db_conn) - assert todo1.id_ is not None - todo2 = Todo(None, process, False, day1) + todo2 = Todo(None, self.proc, False, self.day1) todo2.save(self.db_conn) - assert todo2.id_ is not None - todo2.set_fulfills(self.db_conn, [c2.id_]) + todo2.set_fulfills(self.db_conn, [self.cond2.id_]) todo2.save(self.db_conn) - todo3 = Todo(None, process, False, day2) + todo3 = Todo(None, self.proc, False, self.day2) todo3.save(self.db_conn) - assert todo3.id_ is not None - todo3.set_fulfills(self.db_conn, [c2.id_]) + todo3.set_fulfills(self.db_conn, [self.cond2.id_]) todo3.save(self.db_conn) - self.assertEqual(Todo.enablers_for_at(self.db_conn, c1, day1.date), - [todo1]) - self.assertEqual(Todo.enablers_for_at(self.db_conn, c1, day2.date), - []) - self.assertEqual(Todo.disablers_for_at(self.db_conn, c1, day1.date), - []) - self.assertEqual(Todo.disablers_for_at(self.db_conn, c1, day2.date), - []) - self.assertEqual(Todo.enablers_for_at(self.db_conn, c2, day1.date), - [todo2]) - self.assertEqual(Todo.enablers_for_at(self.db_conn, c2, day2.date), - [todo3]) - self.assertEqual(Todo.disablers_for_at(self.db_conn, c2, day1.date), - [todo1]) - self.assertEqual(Todo.disablers_for_at(self.db_conn, c2, day2.date), - []) + date1 = self.day1.date + date2 = self.day2.date + enablers = Todo.enablers_for_at(self.db_conn, self.cond1, date1) + self.assertEqual(enablers, [todo1]) + enablers = Todo.enablers_for_at(self.db_conn, self.cond1, date2) + self.assertEqual(enablers, []) + disablers = Todo.disablers_for_at(self.db_conn, self.cond1, date1) + self.assertEqual(disablers, []) + disablers = Todo.disablers_for_at(self.db_conn, self.cond1, date2) + self.assertEqual(disablers, []) + enablers = Todo.enablers_for_at(self.db_conn, self.cond2, date1) + self.assertEqual(enablers, [todo2]) + enablers = Todo.enablers_for_at(self.db_conn, self.cond2, date2) + self.assertEqual(enablers, [todo3]) + disablers = Todo.disablers_for_at(self.db_conn, self.cond2, date1) + self.assertEqual(disablers, [todo1]) + disablers = Todo.disablers_for_at(self.db_conn, self.cond2, date2) + self.assertEqual(disablers, []) def test_Todo_children(self) -> None: """Test Todo.children relations.""" - day = Day('2024-01-01') - process = Process(None) - process.save_without_steps(self.db_conn) - todo_1 = Todo(None, process, False, day) - todo_2 = Todo(None, process, False, day) + todo_1 = Todo(None, self.proc, False, self.day1) + todo_2 = Todo(None, self.proc, False, self.day1) with self.assertRaises(HandledException): todo_1.add_child(todo_2) todo_1.save(self.db_conn) @@ -158,12 +141,10 @@ class TestsWithDB(TestCaseWithDB): def test_Todo_conditioning(self) -> None: """Test Todo.doability conditions.""" - day = Day('2024-01-01') - process = Process(None) - process.save_without_steps(self.db_conn) - todo_1 = Todo(None, process, False, day) + assert self.cond1.id_ is not None + todo_1 = Todo(None, self.proc, False, self.day1) todo_1.save(self.db_conn) - todo_2 = Todo(None, process, False, day) + todo_2 = Todo(None, self.proc, False, self.day1) todo_2.save(self.db_conn) todo_2.add_child(todo_1) with self.assertRaises(BadFormatException): @@ -171,27 +152,20 @@ class TestsWithDB(TestCaseWithDB): todo_1.is_done = True todo_2.is_done = True todo_2.is_done = False - condition = Condition(None) - condition.save(self.db_conn) - assert condition.id_ is not None - todo_2.set_conditions(self.db_conn, [condition.id_]) + todo_2.set_conditions(self.db_conn, [self.cond1.id_]) with self.assertRaises(BadFormatException): todo_2.is_done = True - condition.is_active = True + self.cond1.is_active = True todo_2.is_done = True def test_Todo_singularity(self) -> None: """Test pointers made for single object keep pointing to it.""" - day = Day('2024-01-01') - day.save(self.db_conn) - process = Process(None) - process.save_without_steps(self.db_conn) - todo = Todo(None, process, False, day) + todo = Todo(None, self.proc, False, self.day1) 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, '2024-01-01')[0] + retrieved_todo = Todo.by_date(self.db_conn, self.day1.date)[0] retrieved_todo.is_done = False self.assertEqual(todo.is_done, False) @@ -204,25 +178,25 @@ class TestsWithServer(TestCaseWithServer): form_data = {'title': '', 'description': '', 'effort': 1} self.check_post(form_data, '/process?id=', 302, '/') self.check_post(form_data, '/process?id=', 302, '/') - process1 = Process.by_id(self.db_conn, 1) - process2 = Process.by_id(self.db_conn, 2) + proc = Process.by_id(self.db_conn, 1) + proc2 = Process.by_id(self.db_conn, 2) form_data = {'comment': ''} self.check_post(form_data, '/day?date=2024-01-01', 302, '/') self.assertEqual(Todo.by_date(self.db_conn, '2024-01-01'), []) - form_data['new_todo'] = str(process1.id_) + form_data['new_todo'] = str(proc.id_) self.check_post(form_data, '/day?date=2024-01-01', 302, '/') todos = Todo.by_date(self.db_conn, '2024-01-01') self.assertEqual(1, len(todos)) todo1 = todos[0] self.assertEqual(todo1.id_, 1) - self.assertEqual(todo1.process.id_, process1.id_) + self.assertEqual(todo1.process.id_, proc.id_) self.assertEqual(todo1.is_done, False) - form_data['new_todo'] = str(process2.id_) + form_data['new_todo'] = str(proc2.id_) self.check_post(form_data, '/day?date=2024-01-01', 302, '/') todos = Todo.by_date(self.db_conn, '2024-01-01') todo1 = todos[1] self.assertEqual(todo1.id_, 2) - self.assertEqual(todo1.process.id_, process2.id_) + self.assertEqual(todo1.process.id_, proc2.id_) self.assertEqual(todo1.is_done, False) def test_do_POST_todo(self) -> None: