home · contact · privacy
Clean up enablers/disablers code and naming conventions.
[plomtask] / tests / processes.py
index 960fd707eee4345cb4350c065d9dcc974e94405f..084cfe0c6acac566f391500bf092261c1b82d811 100644 (file)
@@ -4,7 +4,7 @@ from typing import Any
 from tests.utils import TestCaseWithDB, TestCaseWithServer
 from plomtask.processes import Process, ProcessStep
 from plomtask.conditions import Condition
 from tests.utils import TestCaseWithDB, TestCaseWithServer
 from plomtask.processes import Process, ProcessStep
 from plomtask.conditions import Condition
-from plomtask.exceptions import NotFoundException, BadFormatException
+from plomtask.exceptions import NotFoundException, HandledException
 
 
 class TestsSansDB(TestCase):
 
 
 class TestsSansDB(TestCase):
@@ -18,7 +18,7 @@ class TestsSansDB(TestCase):
 
     def test_Process_legal_ID(self) -> None:
         """Test Process cannot be instantiated with id_=0."""
 
     def test_Process_legal_ID(self) -> None:
         """Test Process cannot be instantiated with id_=0."""
-        with self.assertRaises(BadFormatException):
+        with self.assertRaises(HandledException):
             Process(0)
 
 
             Process(0)
 
 
@@ -54,8 +54,8 @@ class TestsWithDB(TestCaseWithDB):
             steps_proc += [step_tuple]
             proc.set_steps(self.db_conn, steps_proc)
             steps_proc[-1] = (expected_id, step_tuple[1], step_tuple[2])
             steps_proc += [step_tuple]
             proc.set_steps(self.db_conn, steps_proc)
             steps_proc[-1] = (expected_id, step_tuple[1], step_tuple[2])
-        assert self.proc2.id_ is not None
-        assert self.proc3.id_ is not None
+        assert isinstance(self.proc2.id_, int)
+        assert isinstance(self.proc3.id_, int)
         steps_proc1: list[tuple[int | None, int, int | None]] = []
         add_step(self.proc1, steps_proc1, (None, self.proc2.id_, None), 1)
         p_1_dict: dict[int, dict[str, Any]] = {1: {
         steps_proc1: list[tuple[int | None, int, int | None]] = []
         add_step(self.proc1, steps_proc1, (None, self.proc2.id_, None), 1)
         p_1_dict: dict[int, dict[str, Any]] = {1: {
@@ -65,6 +65,7 @@ class TestsWithDB(TestCaseWithDB):
         self.assertEqual(self.proc1.get_steps(self.db_conn, None), p_1_dict)
         add_step(self.proc1, steps_proc1, (None, self.proc3.id_, None), 2)
         step_2 = self.proc1.explicit_steps[-1]
         self.assertEqual(self.proc1.get_steps(self.db_conn, None), p_1_dict)
         add_step(self.proc1, steps_proc1, (None, self.proc3.id_, None), 2)
         step_2 = self.proc1.explicit_steps[-1]
+        assert isinstance(step_2.id_, int)
         p_1_dict[2] = {
             'process': self.proc3, 'parent_id': None,
             'is_explicit': True, 'steps': {}, 'seen': False
         p_1_dict[2] = {
             'process': self.proc3, 'parent_id': None,
             'is_explicit': True, 'steps': {}, 'seen': False
@@ -107,14 +108,14 @@ class TestsWithDB(TestCaseWithDB):
                          [self.proc1, self.proc2])
 
     def test_Process_conditions(self) -> None:
                          [self.proc1, self.proc2])
 
     def test_Process_conditions(self) -> None:
-        """Test setting Process.conditions/fulfills/undoes."""
-        for target in ('conditions', 'fulfills', 'undoes'):
+        """Test setting Process.conditions/enables/disables."""
+        for target in ('conditions', 'enables', 'disables'):
             c1 = Condition(None, False)
             c1.save(self.db_conn)
             c1 = Condition(None, False)
             c1.save(self.db_conn)
-            assert c1.id_ is not None
+            assert isinstance(c1.id_, int)
             c2 = Condition(None, False)
             c2.save(self.db_conn)
             c2 = Condition(None, False)
             c2.save(self.db_conn)
-            assert c2.id_ is not None
+            assert isinstance(c2.id_, int)
             self.proc1.set_conditions(self.db_conn, [], target)
             self.assertEqual(getattr(self.proc1, target), [])
             self.proc1.set_conditions(self.db_conn, [c1.id_], target)
             self.proc1.set_conditions(self.db_conn, [], target)
             self.assertEqual(getattr(self.proc1, target), [])
             self.proc1.set_conditions(self.db_conn, [c1.id_], target)
@@ -142,23 +143,25 @@ class TestsWithDB(TestCaseWithDB):
 
     def test_ProcessStep_singularity(self) -> None:
         """Test pointers made for single object keep pointing to it."""
 
     def test_ProcessStep_singularity(self) -> None:
         """Test pointers made for single object keep pointing to it."""
-        assert self.proc2.id_ is not None
+        assert isinstance(self.proc2.id_, int)
         self.proc1.set_steps(self.db_conn, [(None, self.proc2.id_, None)])
         step = self.proc1.explicit_steps[-1]
         self.proc1.set_steps(self.db_conn, [(None, self.proc2.id_, None)])
         step = self.proc1.explicit_steps[-1]
-        assert step.id_ is not None
+        assert isinstance(step.id_, int)
         step_retrieved = ProcessStep.by_id(self.db_conn, step.id_)
         step.parent_step_id = 99
         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."""
         step_retrieved = ProcessStep.by_id(self.db_conn, step.id_)
         step.parent_step_id = 99
         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."""
-        assert self.proc2.id_ is not None
+        assert isinstance(self.proc1.id_, int)
+        assert isinstance(self.proc2.id_, int)
         self.proc1.set_steps(self.db_conn, [(None, self.proc2.id_, None)])
         p_retrieved = Process.by_id(self.db_conn, self.proc1.id_)
         self.assertEqual(self.proc1.explicit_steps, p_retrieved.explicit_steps)
 
     def test_Process_versioned_attributes_singularity(self) -> None:
         """Test behavior of VersionedAttributes on saving (with .title)."""
         self.proc1.set_steps(self.db_conn, [(None, self.proc2.id_, None)])
         p_retrieved = Process.by_id(self.db_conn, self.proc1.id_)
         self.assertEqual(self.proc1.explicit_steps, p_retrieved.explicit_steps)
 
     def test_Process_versioned_attributes_singularity(self) -> None:
         """Test behavior of VersionedAttributes on saving (with .title)."""
+        assert isinstance(self.proc1.id_, int)
         self.proc1.title.set('named')
         p_loaded = Process.by_id(self.db_conn, self.proc1.id_)
         self.assertEqual(self.proc1.title.history, p_loaded.title.history)
         self.proc1.title.set('named')
         p_loaded = Process.by_id(self.db_conn, self.proc1.id_)
         self.assertEqual(self.proc1.title.history, p_loaded.title.history)
@@ -192,15 +195,15 @@ class TestsWithServer(TestCaseWithServer):
         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_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]
+        form_data['disables'] = [1]
         self.check_post(form_data, '/process?id=', 302, '/')
         self.check_post(form_data, '/process?id=', 302, '/')
-        form_data['fulfills'] = [1]
+        form_data['enables'] = [1]
         self.check_post(form_data, '/process?id=', 302, '/')
 
     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_post(form_data, '/process?id=', 302, '/')
 
     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', 400)
+        self.check_get('/process?id=0', 500)
         self.check_get('/process?id=FOO', 400)
         self.check_get('/processes', 200)
         self.check_get('/process?id=FOO', 400)
         self.check_get('/processes', 200)