home · contact · privacy
Enable Condition.is_active toggling in Condition view.
[plomtask] / tests / processes.py
index 2ac8cf4cf7787be287792b583a7402c6ed013855..06ed257689b0601e814a074c454cabe6ea0b6c98 100644 (file)
@@ -3,6 +3,7 @@ from unittest import TestCase
 from tests.utils import TestCaseWithDB, TestCaseWithServer
 from plomtask.processes import Process, ProcessStep, ProcessStepsNode
 from plomtask.conditions import Condition
 from tests.utils import TestCaseWithDB, TestCaseWithServer
 from plomtask.processes import Process, ProcessStep, ProcessStepsNode
 from plomtask.conditions import Condition
+from plomtask.todos import Todo
 from plomtask.exceptions import NotFoundException, HandledException
 
 
 from plomtask.exceptions import NotFoundException, HandledException
 
 
@@ -158,12 +159,14 @@ class TestsWithDB(TestCaseWithDB):
         self.assertEqual(self.proc1.title.history, p_loaded.title.history)
 
     def test_Process_removal(self) -> None:
         self.assertEqual(self.proc1.title.history, p_loaded.title.history)
 
     def test_Process_removal(self) -> None:
-        """Test removal of Processes."""
+        """Test removal of Processes and ProcessSteps."""
         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)])
         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)])
+        with self.assertRaises(HandledException):
+            self.proc3.remove(self.db_conn)
         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.explicit_steps[0].remove(self.db_conn)
         retrieved = Process.by_id(self.db_conn, self.proc2.id_)
         self.assertEqual(retrieved.explicit_steps, [])
@@ -172,6 +175,12 @@ class TestsWithDB(TestCaseWithDB):
         self.proc2.remove(self.db_conn)
         with self.assertRaises(NotFoundException):
             ProcessStep.by_id(self.db_conn, step.id_)
         self.proc2.remove(self.db_conn)
         with self.assertRaises(NotFoundException):
             ProcessStep.by_id(self.db_conn, step.id_)
+        todo = Todo(None, self.proc3, False, '2024-01-01')
+        todo.save(self.db_conn)
+        with self.assertRaises(HandledException):
+            self.proc3.remove(self.db_conn)
+        todo.remove(self.db_conn)
+        self.proc3.remove(self.db_conn)
 
 
 class TestsWithServer(TestCaseWithServer):
 
 
 class TestsWithServer(TestCaseWithServer):
@@ -213,8 +222,7 @@ class TestsWithServer(TestCaseWithServer):
 
     def test_do_GET(self) -> None:
         """Test /process and /processes response codes."""
 
     def test_do_GET(self) -> None:
         """Test /process and /processes response codes."""
-        self.check_get('/process', 200)
-        self.check_get('/process?id=', 200)
-        self.check_get('/process?id=0', 500)
-        self.check_get('/process?id=FOO', 400)
+        form_data = {'title': 'foo', 'description': 'foo', 'effort': 1.1}
+        self.check_post(form_data, '/process?id=', 302, '/process?id=1')
+        self.check_get_defaults('/process')
         self.check_get('/processes', 200)
         self.check_get('/processes', 200)