From: Christian Heller Date: Mon, 5 Aug 2024 07:29:05 +0000 (+0200) Subject: Minor improvements of Processes tests. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/template?a=commitdiff_plain;h=82e0437e1310b1adea92ccde4a965ba78ed8bd03;p=plomtask Minor improvements of Processes tests. --- diff --git a/tests/processes.py b/tests/processes.py index 6f2dc42..649aee5 100644 --- a/tests/processes.py +++ b/tests/processes.py @@ -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."""