home · contact · privacy
Enable deletion of Processes.
[plomtask] / tests / processes.py
index 9413822291a87439aafda0cd39459c93b3905661..6695f78363656cffb5963b539c23bf2444db1703 100644 (file)
@@ -135,12 +135,20 @@ class TestsWithDB(TestCaseWithDB):
         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."""
+        """Test pointers made for single object keep pointing to it, and
+        subsequent retrievals don't overload relations."""
         assert isinstance(self.proc1.id_, int)
         assert isinstance(self.proc2.id_, int)
+        c1 = Condition(None, False)
+        c1.save(self.db_conn)
+        assert isinstance(c1.id_, int)
+        self.proc1.set_conditions(self.db_conn, [c1.id_])
         self.proc1.set_steps(self.db_conn, [(None, self.proc2.id_, None)])
+        self.proc1.save(self.db_conn)
         p_retrieved = Process.by_id(self.db_conn, self.proc1.id_)
         self.assertEqual(self.proc1.explicit_steps, p_retrieved.explicit_steps)
+        self.assertEqual(self.proc1.conditions, p_retrieved.conditions)
+        self.proc1.save(self.db_conn)
 
     def test_Process_versioned_attributes_singularity(self) -> None:
         """Test behavior of VersionedAttributes on saving (with .title)."""
@@ -149,6 +157,22 @@ class TestsWithDB(TestCaseWithDB):
         p_loaded = Process.by_id(self.db_conn, self.proc1.id_)
         self.assertEqual(self.proc1.title.history, p_loaded.title.history)
 
+    def test_Process_removal(self) -> None:
+        """Test removal of Processes."""
+        assert isinstance(self.proc3.id_, int)
+        self.proc1.remove(self.db_conn)
+        self.assertEqual({self.proc2.id_, self.proc3.id_},
+                         set(p.id_ for p in Process.all(self.db_conn)))
+        self.proc2.set_steps(self.db_conn, [(None, self.proc3.id_, None)])
+        self.proc2.explicit_steps[0].remove(self.db_conn)
+        retrieved = Process.by_id(self.db_conn, self.proc2.id_)
+        self.assertEqual(retrieved.explicit_steps, [])
+        self.proc2.set_steps(self.db_conn, [(None, self.proc3.id_, None)])
+        step = retrieved.explicit_steps[0]
+        self.proc2.remove(self.db_conn)
+        with self.assertRaises(NotFoundException):
+            ProcessStep.by_id(self.db_conn, step.id_)
+
 
 class TestsWithServer(TestCaseWithServer):
     """Module tests against our HTTP server/handler (and database)."""