home · contact · privacy
Cache DB objects to ensure we do not accidentally edit clones.
[plomtask] / tests / processes.py
index 87b0b09809398ab1a5aa59af78bf1ac11d8bf1e4..bda62750442501445fae1883f9a8a2b280aa18f8 100644 (file)
@@ -2,7 +2,7 @@
 from unittest import TestCase
 from typing import Any
 from tests.utils import TestCaseWithDB, TestCaseWithServer
-from plomtask.processes import Process
+from plomtask.processes import Process, ProcessStep
 from plomtask.exceptions import NotFoundException, BadFormatException
 
 
@@ -39,17 +39,6 @@ class TestsWithDB(TestCaseWithDB):
         self.assertEqual(p.id_,
                          Process.by_id(self.db_conn, 5, create=False).id_)
 
-    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)
@@ -128,6 +117,38 @@ class TestsWithDB(TestCaseWithDB):
         self.assertEqual({p_1.id_, p_2.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 step.id_ is not None
+        step_retrieved = ProcessStep.by_id(self.db_conn, step.id_)
+        step.parent_step_id = 99
+        self.assertEqual(step.parent_step_id, step_retrieved.parent_step_id)
+
+    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)
+
+    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)
+
 
 class TestsWithServer(TestCaseWithServer):
     """Module tests against our HTTP server/handler (and database)."""