- p_saved.title.set('named')
- p_loaded = Process.by_id(self.db_conn, p_saved.id_)
- self.assertNotEqual(p_saved.title.history, p_loaded.title.history)
- p_saved.save(self.db_conn)
- p_loaded = Process.by_id(self.db_conn, p_saved.id_)
- self.assertEqual(p_saved.title.history, p_loaded.title.history)
- p_9 = Process(9)
- p_9.child_ids = [4]
- with self.assertRaises(NotFoundException):
- p_9.save(self.db_conn)
- p_9.child_ids = [5]
- p_9.save(self.db_conn)
- p_5 = Process.by_id(self.db_conn, 5)
- p_5.child_ids = [1]
- p_5.save(self.db_conn)
- p_1 = Process.by_id(self.db_conn, 1)
- p_1.child_ids = [9]
- with self.assertRaises(BadFormatException):
- p_1.save(self.db_conn)
+
+ def test_Process_versioned_attributes(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.assertNotEqual(p.title.history, p_loaded.title.history)
+ p.save_without_steps(self.db_conn)
+ p_loaded = Process.by_id(self.db_conn, p.id_)
+ self.assertEqual(p.title.history, p_loaded.title.history)
+
+ 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)
+ p_1_dict: dict[int, dict[str, Any]] = {1: {
+ 'process': p_2, 'parent_id': None,
+ 'is_explicit': True, 'steps': {}
+ }}
+ 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)
+ p_1_dict[2] = {
+ 'process': p_3, 'parent_id': None,
+ 'is_explicit': True, 'steps': {}
+ }
+ 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)
+ assert s_c.id_ is not None
+ p_1_dict[1]['steps'] = {3: {
+ 'process': p_3, 'parent_id': None,
+ 'is_explicit': False, 'steps': {}
+ }}
+ 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_)
+ p_1_dict[2]['steps'][4] = {
+ 'process': p_2, 'parent_id': s_b.id_,
+ 'is_explicit': True, 'steps': {3: {
+ 'process': p_3, 'parent_id': None,
+ 'is_explicit': False, 'steps': {}
+ }}}
+ 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)
+ p_1_dict[5] = {
+ 'process': p_3, 'parent_id': None,
+ 'is_explicit': True, 'steps': {}
+ }
+ 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)
+ p_1_dict[6] = {
+ 'process': p_3, 'parent_id': None,
+ 'is_explicit': True, 'steps': {}
+ }
+ self.assertEqual(p_1.get_steps(self.db_conn, None), p_1_dict)