+
+ def test_Process_steps(self) -> None:
+ """Test addition, nesting, and non-recursion of ProcessSteps"""
+ 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': self.proc2, 'parent_id': None,
+ 'is_explicit': True, 'steps': {}, 'seen': False
+ }}
+ 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': self.proc3, 'parent_id': None,
+ 'is_explicit': True, 'steps': {}, 'seen': False
+ }
+ 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': self.proc3, 'parent_id': None,
+ 'is_explicit': False, 'steps': {}, 'seen': False
+ }}
+ 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': self.proc2, 'parent_id': s_b.id_, 'seen': False,
+ 'is_explicit': True, 'steps': {3: {
+ 'process': self.proc3, 'parent_id': None,
+ 'is_explicit': False, 'steps': {}, 'seen': True
+ }}}
+ 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': self.proc3, 'parent_id': None,
+ 'is_explicit': True, 'steps': {}, 'seen': False
+ }
+ 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': self.proc3, 'parent_id': None,
+ 'is_explicit': True, 'steps': {}, 'seen': False
+ }
+ 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/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: