home · contact · privacy
Add Conditions for Todos/Processes to be met or undone by other Todos.
[plomtask] / tests / processes.py
index bda62750442501445fae1883f9a8a2b280aa18f8..539d86f47bea49d639ff7ae377272e89059a9dcf 100644 (file)
@@ -3,6 +3,7 @@ from unittest import TestCase
 from typing import Any
 from tests.utils import TestCaseWithDB, TestCaseWithServer
 from plomtask.processes import Process, ProcessStep
+from plomtask.conditions import Condition
 from plomtask.exceptions import NotFoundException, BadFormatException
 
 
@@ -93,6 +94,63 @@ class TestsWithDB(TestCaseWithDB):
         self.assertEqual(p_2.used_as_step_by(self.db_conn), [p_1])
         self.assertEqual(p_3.used_as_step_by(self.db_conn), [p_1, p_2])
 
+    def test_Process_undoes(self) -> None:
+        """Test setting Process.undoes"""
+        p = Process(None)
+        p.set_undoes(self.db_conn, [])
+        p.set_undoes(self.db_conn, [])
+        self.assertEqual(p.undoes, [])
+        c1 = Condition(None, False)
+        c1.save(self.db_conn)
+        assert c1.id_ is not None
+        p.set_undoes(self.db_conn, [c1.id_])
+        self.assertEqual(p.undoes, [c1])
+        c2 = Condition(None, False)
+        c2.save(self.db_conn)
+        assert c2.id_ is not None
+        p.set_undoes(self.db_conn, [c2.id_])
+        self.assertEqual(p.undoes, [c2])
+        p.set_undoes(self.db_conn, [c1.id_, c2.id_])
+        self.assertEqual(p.undoes, [c1, c2])
+
+    def test_Process_fulfills(self) -> None:
+        """Test setting Process.fulfills"""
+        p = Process(None)
+        p.set_fulfills(self.db_conn, [])
+        p.set_fulfills(self.db_conn, [])
+        self.assertEqual(p.fulfills, [])
+        c1 = Condition(None, False)
+        c1.save(self.db_conn)
+        assert c1.id_ is not None
+        p.set_fulfills(self.db_conn, [c1.id_])
+        self.assertEqual(p.fulfills, [c1])
+        c2 = Condition(None, False)
+        c2.save(self.db_conn)
+        assert c2.id_ is not None
+        p.set_fulfills(self.db_conn, [c2.id_])
+        self.assertEqual(p.fulfills, [c2])
+        p.set_fulfills(self.db_conn, [c1.id_, c2.id_])
+        self.assertEqual(p.fulfills, [c1, c2])
+
+    def test_Process_conditions(self) -> None:
+        """Test setting Process.conditions"""
+        p = Process(None)
+        p.set_conditions(self.db_conn, [])
+        p.set_conditions(self.db_conn, [])
+        self.assertEqual(p.conditions, [])
+        c1 = Condition(None, False)
+        c1.save(self.db_conn)
+        assert c1.id_ is not None
+        p.set_conditions(self.db_conn, [c1.id_])
+        self.assertEqual(p.conditions, [c1])
+        c2 = Condition(None, False)
+        c2.save(self.db_conn)
+        assert c2.id_ is not None
+        p.set_conditions(self.db_conn, [c2.id_])
+        self.assertEqual(p.conditions, [c2])
+        p.set_conditions(self.db_conn, [c1.id_, c2.id_])
+        self.assertEqual(p.conditions, [c1, c2])
+
     def test_Process_by_id(self) -> None:
         """Test Process.by_id()."""
         with self.assertRaises(NotFoundException):
@@ -170,6 +228,18 @@ class TestsWithServer(TestCaseWithServer):
         form_data = {'description': '', 'effort': 1.0}
         self.check_post(form_data, '/process?id=', 400)
         self.assertEqual(1, len(Process.all(self.db_conn)))
+        form_data = {'title': 'foo', 'description': 'foo', 'effort': 1.0,
+                     'condition': []}
+        self.check_post(form_data, '/process?id=', 302, '/')
+        form_data['condition'] = [1]
+        self.check_post(form_data, '/process?id=', 404)
+        form_data_cond = {'title': 'foo', 'description': 'foo'}
+        self.check_post(form_data_cond, '/condition', 302, '/')
+        self.check_post(form_data, '/process?id=', 302, '/')
+        form_data['undoes'] = [1]
+        self.check_post(form_data, '/process?id=', 302, '/')
+        form_data['fulfills'] = [1]
+        self.check_post(form_data, '/process?id=', 302, '/')
 
     def test_do_GET(self) -> None:
         """Test /process and /processes response codes."""