X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;f=tests%2Fprocesses.py;h=9e769c1e3da6acafa81b3d529d040aba4a5c5251;hb=e60bbd142b5026748ee2181ca6758afef6202fb4;hp=c3b1144de7563d956e5fd3a6d6474cb6180e726a;hpb=10af8a54a17047a4554d4b8d051a238271c74906;p=plomtask diff --git a/tests/processes.py b/tests/processes.py index c3b1144..9e769c1 100644 --- a/tests/processes.py +++ b/tests/processes.py @@ -22,6 +22,15 @@ class TestsSansDB(TestCaseSansDB): 'effort': 1.0}) +class TestsSansDBProcessStep(TestCaseSansDB): + """Module tests not requiring DB setup.""" + checked_class = ProcessStep + + def test_ProcessStep_id_setting(self) -> None: + """Test .id_ being set and its legal range being enforced.""" + self.check_id_setting(2, 3, 4) + + class TestsWithDB(TestCaseWithDB): """Module tests requiring DB setup.""" checked_class = Process @@ -33,34 +42,58 @@ class TestsWithDB(TestCaseWithDB): p.save(self.db_conn) return p1, p2, p3 - def test_Process_saving_and_caching(self) -> None: - """Test .save/.save_core.""" - kwargs = {'id_': 1} - self.check_saving_and_caching(**kwargs) + def p_of_conditions(self) -> tuple[Process, list[Condition], + list[Condition], list[Condition]]: + """Return Process and its three Condition sets.""" p = Process(None) - p.title.set('t1') - p.title.set('t2') - p.description.set('d1') - p.description.set('d2') - p.effort.set(0.5) - p.effort.set(1.5) c1, c2, c3 = Condition(None), Condition(None), Condition(None) for c in [c1, c2, c3]: c.save(self.db_conn) assert isinstance(c1.id_, int) assert isinstance(c2.id_, int) assert isinstance(c3.id_, int) - p.set_conditions(self.db_conn, [c1.id_, c2.id_]) - p.set_enables(self.db_conn, [c2.id_, c3.id_]) - p.set_disables(self.db_conn, [c1.id_, c3.id_]) + set_1 = [c1, c2] + set_2 = [c2, c3] + set_3 = [c1, c3] + p.set_conditions(self.db_conn, [c.id_ for c in set_1 + if isinstance(c.id_, int)]) + p.set_enables(self.db_conn, [c.id_ for c in set_2 + if isinstance(c.id_, int)]) + p.set_disables(self.db_conn, [c.id_ for c in set_3 + if isinstance(c.id_, int)]) p.save(self.db_conn) + return p, set_1, set_2, set_3 + + def test_Process_saving_and_caching(self) -> None: + """Test .save/.save_core.""" + kwargs = {'id_': 1} + self.check_saving_and_caching(**kwargs) + self.check_saving_of_versioned('title', str) + self.check_saving_of_versioned('description', str) + self.check_saving_of_versioned('effort', float) + p, set1, set2, set3 = self.p_of_conditions() + p.uncache() r = Process.by_id(self.db_conn, p.id_) - self.assertEqual(sorted(r.title.history.values()), ['t1', 't2']) - self.assertEqual(sorted(r.description.history.values()), ['d1', 'd2']) - self.assertEqual(sorted(r.effort.history.values()), [0.5, 1.5]) - self.assertEqual(sorted(r.conditions), sorted([c1, c2])) - self.assertEqual(sorted(r.enables), sorted([c2, c3])) - self.assertEqual(sorted(r.disables), sorted([c1, c3])) + self.assertEqual(sorted(r.conditions), sorted(set1)) + self.assertEqual(sorted(r.enables), sorted(set2)) + self.assertEqual(sorted(r.disables), sorted(set3)) + + def test_Process_from_table_row(self) -> None: + """Test .from_table_row() properly reads in class from DB""" + self.check_from_table_row() + self.check_versioned_from_table_row('title', str) + self.check_versioned_from_table_row('description', str) + self.check_versioned_from_table_row('effort', float) + p, set1, set2, set3 = self.p_of_conditions() + p.save(self.db_conn) + assert isinstance(p.id_, int) + for row in self.db_conn.row_where(self.checked_class.table_name, + 'id', p.id_): + # pylint: disable=no-member + r = Process.from_table_row(self.db_conn, row) + self.assertEqual(sorted(r.conditions), sorted(set1)) + self.assertEqual(sorted(r.enables), sorted(set2)) + self.assertEqual(sorted(r.disables), sorted(set3)) def test_Process_steps(self) -> None: """Test addition, nesting, and non-recursion of ProcessSteps"""