class TestsSansDB(TestCaseSansDB):
"""Module tests not requiring DB setup."""
checked_class = Process
-
- def test_Process_id_setting(self) -> None:
- """Test .id_ being set and its legal range being enforced."""
- self.check_id_setting()
-
- def test_Process_versioned_defaults(self) -> None:
- """Test defaults of VersionedAttributes."""
- self.check_versioned_defaults({
- 'title': 'UNNAMED',
- 'description': '',
- 'effort': 1.0})
+ do_id_test = True
+ versioned_defaults_to_test = {'title': 'UNNAMED', 'description': '',
+ '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)
+ do_id_test = True
+ default_init_args = [2, 3, 4]
class TestsWithDB(TestCaseWithDB):
"""Module tests requiring DB setup."""
checked_class = Process
+ test_versioneds = {'title': str, 'description': str, 'effort': float}
def three_processes(self) -> tuple[Process, Process, Process]:
"""Return three saved processes."""
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_conditions_saving(self) -> None:
+ """Test .save/.save_core."""
+ 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"""
class TestsWithDBForProcessStep(TestCaseWithDB):
"""Module tests requiring DB setup."""
checked_class = ProcessStep
-
- def test_ProcessStep_saving_and_caching(self) -> None:
- """Test .save/.save_core."""
- kwargs = {'id_': 1,
- 'owner_id': 2,
- 'step_process_id': 3,
- 'parent_step_id': 4}
- self.check_saving_and_caching(**kwargs)
+ default_init_kwargs = {'owner_id': 2, 'step_process_id': 3,
+ 'parent_step_id': 4}
def test_ProcessStep_from_table_row(self) -> None:
"""Test .from_table_row() properly reads in class from DB"""