home · contact · privacy
Minor improvements of Processes tests.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 5 Aug 2024 07:29:05 +0000 (09:29 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 5 Aug 2024 07:29:05 +0000 (09:29 +0200)
tests/processes.py

index 6f2dc42178564e6e251d964db12b3d9cb5a8f2e9..649aee5f96663780ed91f8e447f7bee47d8c50b0 100644 (file)
@@ -4,8 +4,7 @@ from tests.utils import (TestCaseSansDB, TestCaseWithDB, TestCaseWithServer,
                          Expected)
 from plomtask.processes import Process, ProcessStep
 from plomtask.conditions import Condition
-from plomtask.exceptions import HandledException, NotFoundException
-from plomtask.todos import Todo
+from plomtask.exceptions import NotFoundException
 
 
 class TestsSansDB(TestCaseSansDB):
@@ -193,26 +192,21 @@ class TestsWithDB(TestCaseWithDB):
         step = ProcessStep(None, p2.id_, p1.id_, None)
         p2.set_steps(self.db_conn, [step])
         step_id = step.id_
-        with self.assertRaises(HandledException):
-            p1.remove(self.db_conn)
         p2.set_steps(self.db_conn, [])
         with self.assertRaises(NotFoundException):
+            # check unset ProcessSteps actually cannot be found anymore
             assert step_id is not None
             ProcessStep.by_id(self.db_conn, step_id)
         p1.remove(self.db_conn)
         step = ProcessStep(None, p2.id_, p3.id_, None)
         p2.set_steps(self.db_conn, [step])
         step_id = step.id_
+        # check _can_ remove Process pointed to by ProcessStep.owner_id, and …
         p2.remove(self.db_conn)
         with self.assertRaises(NotFoundException):
+            # … being dis-owned eliminates ProcessStep
             assert step_id is not None
             ProcessStep.by_id(self.db_conn, step_id)
-        todo = Todo(None, p3, False, '2024-01-01')
-        todo.save(self.db_conn)
-        with self.assertRaises(HandledException):
-            p3.remove(self.db_conn)
-        todo.remove(self.db_conn)
-        p3.remove(self.db_conn)
 
 
 class TestsWithDBForProcessStep(TestCaseWithDB):
@@ -338,13 +332,20 @@ class TestsWithServer(TestCaseWithServer):
         self.check_json_get('/process?id=1', exp)
         # check cannot delete if Todos to Process
         self.check_post({'delete': ''}, '/process?id=1', 500)
+        # check cannot delete if some ProcessStep's .step_process_id
+        self.post_exp_process([exp], valid_post, 2)
+        self.post_exp_process([exp], valid_post | {'new_top_step': 2}, 3)
+        self.check_post({'delete': ''}, '/process?id=2', 500)
         # check successful deletion
-        self.post_exp_process([], valid_post, 2)
-        self.check_post({'delete': ''}, '/process?id=2', 302, '/processes')
-        exp = ExpectedGetProcess(2)
+        self.post_exp_process([exp], valid_post, 4)
+        self.check_post({'delete': ''}, '/process?id=4', 302, '/processes')
+        exp = ExpectedGetProcess(4)
         exp.set_proc_from_post(1, valid_post)
-        exp.force('process_candidates', [1])
-        self.check_json_get('/process?id=2', exp)
+        exp.set_proc_from_post(2, valid_post)
+        exp.set_proc_from_post(3, valid_post)
+        exp.lib_set('ProcessStep', [exp.procstep_as_dict(1, 3, 2)])
+        exp.force('process_candidates', [1, 2, 3])
+        self.check_json_get('/process?id=4', exp)
 
     def test_POST_process_steps(self) -> None:
         """Test behavior of ProcessStep posting."""