X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;ds=inline;f=tests%2Fprocesses.py;h=9e266e017aab0abb23717e8550f98e31c9b5fe15;hb=1a9557367351fe26d08ea705400b3b56394caae6;hp=87b0b09809398ab1a5aa59af78bf1ac11d8bf1e4;hpb=b3ff25deb388919c9a205ceb1997ff3c42e93bc8;p=plomtask
diff --git a/tests/processes.py b/tests/processes.py
index 87b0b09..9e266e0 100644
--- a/tests/processes.py
+++ b/tests/processes.py
@@ -1,132 +1,237 @@
"""Test Processes module."""
-from unittest import TestCase
-from typing import Any
-from tests.utils import TestCaseWithDB, TestCaseWithServer
-from plomtask.processes import Process
-from plomtask.exceptions import NotFoundException, BadFormatException
+from tests.utils import TestCaseWithDB, TestCaseWithServer, TestCaseSansDB
+from plomtask.processes import Process, ProcessStep, ProcessStepsNode
+from plomtask.conditions import Condition
+from plomtask.exceptions import HandledException, NotFoundException
+from plomtask.todos import Todo
-class TestsSansDB(TestCase):
+class TestsSansDB(TestCaseSansDB):
"""Module tests not requiring DB setup."""
+ checked_class = Process
+ versioned_defaults_to_test = {'title': 'UNNAMED', 'description': '',
+ 'effort': 1.0}
- def test_Process_versioned_defaults(self) -> None:
- """Test defaults of Process' VersionedAttributes."""
- self.assertEqual(Process(None).title.newest, 'UNNAMED')
- self.assertEqual(Process(None).description.newest, '')
- self.assertEqual(Process(None).effort.newest, 1.0)
- def test_Process_legal_ID(self) -> None:
- """Test Process cannot be instantiated with id_=0."""
- with self.assertRaises(BadFormatException):
- Process(0)
+class TestsSansDBProcessStep(TestCaseSansDB):
+ """Module tests not requiring DB setup."""
+ checked_class = ProcessStep
+ default_init_args = [2, 3, 4]
class TestsWithDB(TestCaseWithDB):
- """Mdule tests not requiring DB setup."""
+ """Module tests requiring DB setup."""
+ checked_class = Process
+ test_versioneds = {'title': str, 'description': str, 'effort': float}
- def test_Process_ids(self) -> None:
- """Test Process.save_without_steps() re Process.id_."""
- p = Process(None)
- p.save_without_steps(self.db_conn)
- self.assertEqual(p.id_,
- Process.by_id(self.db_conn, 1, create=False).id_)
- p = Process(None)
- p.save_without_steps(self.db_conn)
- self.assertEqual(p.id_,
- Process.by_id(self.db_conn, 2, create=False).id_)
- p = Process(5)
- p.save_without_steps(self.db_conn)
- self.assertEqual(p.id_,
- Process.by_id(self.db_conn, 5, create=False).id_)
-
- def test_Process_versioned_attributes(self) -> None:
- """Test behavior of VersionedAttributes on saving (with .title)."""
+ def three_processes(self) -> tuple[Process, Process, Process]:
+ """Return three saved processes."""
+ p1, p2, p3 = Process(None), Process(None), Process(None)
+ for p in [p1, p2, p3]:
+ p.save(self.db_conn)
+ return p1, p2, p3
+
+ def p_of_conditions(self) -> tuple[Process, list[Condition],
+ list[Condition], list[Condition]]:
+ """Return Process and its three Condition sets."""
p = Process(None)
- p.save_without_steps(self.db_conn)
- p.title.set('named')
- p_loaded = Process.by_id(self.db_conn, p.id_)
- self.assertNotEqual(p.title.history, p_loaded.title.history)
- p.save_without_steps(self.db_conn)
- p_loaded = Process.by_id(self.db_conn, p.id_)
- self.assertEqual(p.title.history, p_loaded.title.history)
+ c1, c2, c3 = Condition(None), Condition(None), Condition(None)
+ for c in [c1, c2, c3]:
+ c.save(self.db_conn)
+ assert isinstance(c1.id_, int)
+ assert isinstance(c2.id_, int)
+ assert isinstance(c3.id_, int)
+ set_1 = [c1, c2]
+ set_2 = [c2, c3]
+ set_3 = [c1, c3]
+ p.set_conditions(self.db_conn, [c.id_ for c in set_1
+ if isinstance(c.id_, int)])
+ p.set_enables(self.db_conn, [c.id_ for c in set_2
+ if isinstance(c.id_, int)])
+ p.set_disables(self.db_conn, [c.id_ for c in set_3
+ if isinstance(c.id_, int)])
+ p.save(self.db_conn)
+ return p, set_1, set_2, set_3
+
+ def test_Process_conditions_saving(self) -> None:
+ """Test .save/.save_core."""
+ p, set1, set2, set3 = self.p_of_conditions()
+ assert p.id_ is not None
+ r = Process.by_id(self.db_conn, p.id_)
+ self.assertEqual(sorted(r.conditions), sorted(set1))
+ self.assertEqual(sorted(r.enables), sorted(set2))
+ self.assertEqual(sorted(r.disables), sorted(set3))
+
+ def test_from_table_row(self) -> None:
+ """Test .from_table_row() properly reads in class from DB."""
+ super().test_from_table_row()
+ p, set1, set2, set3 = self.p_of_conditions()
+ p.save(self.db_conn)
+ assert isinstance(p.id_, int)
+ for row in self.db_conn.row_where(self.checked_class.table_name,
+ 'id', p.id_):
+ r = Process.from_table_row(self.db_conn, row)
+ self.assertEqual(sorted(r.conditions), sorted(set1))
+ self.assertEqual(sorted(r.enables), sorted(set2))
+ self.assertEqual(sorted(r.disables), sorted(set3))
def test_Process_steps(self) -> None:
"""Test addition, nesting, and non-recursion of ProcessSteps"""
- p_1 = Process(1)
- p_1.save_without_steps(self.db_conn)
- assert p_1.id_ is not None
- p_2 = Process(2)
- p_2.save_without_steps(self.db_conn)
- assert p_2.id_ is not None
- p_3 = Process(3)
- p_3.save_without_steps(self.db_conn)
- assert p_3.id_ is not None
- p_1.add_step(self.db_conn, None, p_2.id_, None)
- p_1_dict: dict[int, dict[str, Any]] = {1: {
- 'process': p_2, 'parent_id': None,
- 'is_explicit': True, 'steps': {}, 'seen': False
- }}
- self.assertEqual(p_1.get_steps(self.db_conn, None), p_1_dict)
- s_b = p_1.add_step(self.db_conn, None, p_3.id_, None)
- p_1_dict[2] = {
- 'process': p_3, 'parent_id': None,
- 'is_explicit': True, 'steps': {}, 'seen': False
- }
- self.assertEqual(p_1.get_steps(self.db_conn, None), p_1_dict)
- s_c = p_2.add_step(self.db_conn, None, p_3.id_, None)
- assert s_c.id_ is not None
- p_1_dict[1]['steps'] = {3: {
- 'process': p_3, 'parent_id': None,
- 'is_explicit': False, 'steps': {}, 'seen': False
- }}
- self.assertEqual(p_1.get_steps(self.db_conn, None), p_1_dict)
- p_1.add_step(self.db_conn, None, p_2.id_, s_b.id_)
- p_1_dict[2]['steps'][4] = {
- 'process': p_2, 'parent_id': s_b.id_, 'seen': False,
- 'is_explicit': True, 'steps': {3: {
- 'process': p_3, 'parent_id': None,
- 'is_explicit': False, 'steps': {}, 'seen': True
- }}}
- self.assertEqual(p_1.get_steps(self.db_conn, None), p_1_dict)
- p_1.add_step(self.db_conn, None, p_3.id_, 999)
- p_1_dict[5] = {
- 'process': p_3, 'parent_id': None,
- 'is_explicit': True, 'steps': {}, 'seen': False
- }
- self.assertEqual(p_1.get_steps(self.db_conn, None), p_1_dict)
- p_1.add_step(self.db_conn, None, p_3.id_, 3)
- p_1_dict[6] = {
- 'process': p_3, 'parent_id': None,
- 'is_explicit': True, 'steps': {}, 'seen': False
- }
- self.assertEqual(p_1.get_steps(self.db_conn, None), p_1_dict)
- self.assertEqual(p_1.used_as_step_by(self.db_conn), [])
- 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_by_id(self) -> None:
- """Test Process.by_id()."""
- with self.assertRaises(NotFoundException):
- Process.by_id(self.db_conn, None, create=False)
+ # pylint: disable=too-many-locals
+ # pylint: disable=too-many-statements
+ p1, p2, p3 = self.three_processes()
+ assert isinstance(p1.id_, int)
+ assert isinstance(p2.id_, int)
+ assert isinstance(p3.id_, int)
+ steps_p1: list[ProcessStep] = []
+ # add step of process p2 as first (top-level) step to p1
+ s_p2_to_p1 = ProcessStep(None, p1.id_, p2.id_, None)
+ steps_p1 += [s_p2_to_p1]
+ p1.set_steps(self.db_conn, steps_p1)
+ p1_dict: dict[int, ProcessStepsNode] = {}
+ p1_dict[1] = ProcessStepsNode(p2, None, True, {})
+ self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
+ # add step of process p3 as second (top-level) step to p1
+ s_p3_to_p1 = ProcessStep(None, p1.id_, p3.id_, None)
+ steps_p1 += [s_p3_to_p1]
+ p1.set_steps(self.db_conn, steps_p1)
+ p1_dict[2] = ProcessStepsNode(p3, None, True, {})
+ self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
+ # add step of process p3 as first (top-level) step to p2,
+ steps_p2: list[ProcessStep] = []
+ s_p3_to_p2 = ProcessStep(None, p2.id_, p3.id_, None)
+ steps_p2 += [s_p3_to_p2]
+ p2.set_steps(self.db_conn, steps_p2)
+ # expect it as implicit sub-step of p1's second (p3) step
+ p2_dict = {3: ProcessStepsNode(p3, None, False, {})}
+ p1_dict[1].steps[3] = p2_dict[3]
+ self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
+ # add step of process p2 as explicit sub-step to p1's second sub-step
+ s_p2_to_p1_first = ProcessStep(None, p1.id_, p2.id_, s_p3_to_p1.id_)
+ steps_p1 += [s_p2_to_p1_first]
+ p1.set_steps(self.db_conn, steps_p1)
+ seen_3 = ProcessStepsNode(p3, None, False, {}, False)
+ p1_dict[1].steps[3].seen = True
+ p1_dict[2].steps[4] = ProcessStepsNode(p2, s_p3_to_p1.id_, True,
+ {3: seen_3})
+ self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
+ # add step of process p3 as explicit sub-step to non-existing p1
+ # sub-step (of id=999), expect it to become another p1 top-level step
+ s_p3_to_p1_999 = ProcessStep(None, p1.id_, p3.id_, 999)
+ steps_p1 += [s_p3_to_p1_999]
+ p1.set_steps(self.db_conn, steps_p1)
+ p1_dict[5] = ProcessStepsNode(p3, None, True, {})
+ self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
+ # add step of process p3 as explicit sub-step to p1's implicit p3
+ # sub-step, expect it to become another p1 top-level step
+ s_p3_to_p1_impl_p3 = ProcessStep(None, p1.id_, p3.id_, s_p3_to_p2.id_)
+ steps_p1 += [s_p3_to_p1_impl_p3]
+ p1.set_steps(self.db_conn, steps_p1)
+ p1_dict[6] = ProcessStepsNode(p3, None, True, {})
+ self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
+ self.assertEqual(p1.used_as_step_by(self.db_conn), [])
+ self.assertEqual(p2.used_as_step_by(self.db_conn), [p1])
+ self.assertEqual(p3.used_as_step_by(self.db_conn), [p1, p2])
+ # # add step of process p3 as explicit sub-step to p1's first sub-step,
+ # # expect it to eliminate implicit p3 sub-step
+ # s_p3_to_p1_first_explicit = ProcessStep(None, p1.id_, p3.id_,
+ # s_p2_to_p1.id_)
+ # p1_dict[1].steps = {7: ProcessStepsNode(p3, 1, True, {})}
+ # p1_dict[2].steps[4].steps[3].seen = False
+ # steps_p1 += [s_p3_to_p1_first_explicit]
+ # p1.set_steps(self.db_conn, steps_p1)
+ # self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
+ # ensure implicit steps non-top explicit steps are shown
+ s_p3_to_p2_first = ProcessStep(None, p2.id_, p3.id_, s_p3_to_p2.id_)
+ steps_p2 += [s_p3_to_p2_first]
+ p2.set_steps(self.db_conn, steps_p2)
+ p1_dict[1].steps[3].steps[7] = ProcessStepsNode(p3, 3, False, {}, True)
+ p1_dict[2].steps[4].steps[3].steps[7] = ProcessStepsNode(p3, 3, False,
+ {}, False)
+ self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
+ # ensure suppressed step nodes are hidden
+ assert isinstance(s_p3_to_p2.id_, int)
+ p1.set_step_suppressions(self.db_conn, [s_p3_to_p2.id_])
+ p1_dict[1].steps[3].steps = {}
+ p1_dict[1].steps[3].is_suppressed = True
+ p1_dict[2].steps[4].steps[3].steps = {}
+ p1_dict[2].steps[4].steps[3].is_suppressed = True
+ self.assertEqual(p1.get_steps(self.db_conn), p1_dict)
+
+ def test_Process_conditions(self) -> None:
+ """Test setting Process.conditions/enables/disables."""
+ p = Process(None)
+ p.save(self.db_conn)
+ for target in ('conditions', 'enables', 'disables'):
+ method = getattr(p, f'set_{target}')
+ c1, c2 = Condition(None), Condition(None)
+ c1.save(self.db_conn)
+ c2.save(self.db_conn)
+ assert isinstance(c1.id_, int)
+ assert isinstance(c2.id_, int)
+ method(self.db_conn, [])
+ self.assertEqual(getattr(p, target), [])
+ method(self.db_conn, [c1.id_])
+ self.assertEqual(getattr(p, target), [c1])
+ method(self.db_conn, [c2.id_])
+ self.assertEqual(getattr(p, target), [c2])
+ method(self.db_conn, [c1.id_, c2.id_])
+ self.assertEqual(getattr(p, target), [c1, c2])
+
+ def test_remove(self) -> None:
+ """Test removal of Processes and ProcessSteps."""
+ super().test_remove()
+ p1, p2, p3 = self.three_processes()
+ assert isinstance(p1.id_, int)
+ assert isinstance(p2.id_, int)
+ assert isinstance(p3.id_, int)
+ 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):
- Process.by_id(self.db_conn, 0, create=False)
+ 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_
+ p2.remove(self.db_conn)
with self.assertRaises(NotFoundException):
- Process.by_id(self.db_conn, 1, create=False)
- self.assertNotEqual(Process(1).id_,
- Process.by_id(self.db_conn, None, create=True).id_)
- self.assertEqual(Process(1).id_,
- Process.by_id(self.db_conn, 1, create=True).id_)
- self.assertEqual(Process(2).id_,
- Process.by_id(self.db_conn, 2, create=True).id_)
-
- def test_Process_all(self) -> None:
- """Test Process.all()."""
- p_1 = Process(None)
- p_1.save_without_steps(self.db_conn)
- p_2 = Process(None)
- p_2.save_without_steps(self.db_conn)
- self.assertEqual({p_1.id_, p_2.id_},
- set(p.id_ for p in Process.all(self.db_conn)))
+ 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):
+ """Module tests requiring DB setup."""
+ checked_class = ProcessStep
+ default_init_kwargs = {'owner_id': 1, 'step_process_id': 2,
+ 'parent_step_id': 3}
+
+ def setUp(self) -> None:
+ super().setUp()
+ self.p1 = Process(1)
+ self.p1.save(self.db_conn)
+
+ def test_remove(self) -> None:
+ """Test .remove and unsetting of owner's .explicit_steps entry."""
+ p2 = Process(2)
+ p2.save(self.db_conn)
+ assert isinstance(self.p1.id_, int)
+ assert isinstance(p2.id_, int)
+ step = ProcessStep(None, self.p1.id_, p2.id_, None)
+ self.p1.set_steps(self.db_conn, [step])
+ step.remove(self.db_conn)
+ self.assertEqual(self.p1.explicit_steps, [])
+ self.check_identity_with_cache_and_db([])
class TestsWithServer(TestCaseWithServer):
@@ -135,25 +240,149 @@ class TestsWithServer(TestCaseWithServer):
def test_do_POST_process(self) -> None:
"""Test POST /process and its effect on the database."""
self.assertEqual(0, len(Process.all(self.db_conn)))
- form_data = {'title': 'foo', 'description': 'foo', 'effort': 1.1}
- self.check_post(form_data, '/process?id=', 302, '/')
+ form_data = self.post_process()
self.assertEqual(1, len(Process.all(self.db_conn)))
self.check_post(form_data, '/process?id=FOO', 400)
- form_data['effort'] = 'foo'
- self.check_post(form_data, '/process?id=', 400)
+ self.check_post(form_data | {'effort': 'foo'}, '/process?id=', 400)
self.check_post({}, '/process?id=', 400)
- form_data = {'title': '', 'description': ''}
- self.check_post(form_data, '/process?id=', 400)
- form_data = {'title': '', 'effort': 1.1}
- self.check_post(form_data, '/process?id=', 400)
- form_data = {'description': '', 'effort': 1.0}
- self.check_post(form_data, '/process?id=', 400)
+ self.check_post({'title': '', 'description': ''}, '/process?id=', 400)
+ self.check_post({'title': '', 'effort': 1.1}, '/process?id=', 400)
+ self.check_post({'description': '', 'effort': 1.0},
+ '/process?id=', 400)
self.assertEqual(1, len(Process.all(self.db_conn)))
+ form_data = {'title': 'foo', 'description': 'foo', 'effort': 1.0}
+ self.post_process(2, form_data | {'conditions': []})
+ self.check_post(form_data | {'conditions': [1]}, '/process?id=', 404)
+ self.check_post({'title': 'foo', 'description': 'foo',
+ 'is_active': False},
+ '/condition', 302, '/condition?id=1')
+ self.post_process(3, form_data | {'conditions': [1]})
+ self.post_process(4, form_data | {'disables': [1]})
+ self.post_process(5, form_data | {'enables': [1]})
+ form_data['delete'] = ''
+ self.check_post(form_data, '/process?id=', 404)
+ self.check_post(form_data, '/process?id=6', 404)
+ self.check_post(form_data, '/process?id=5', 302, '/processes')
+
+ def test_do_POST_process_steps(self) -> None:
+ """Test behavior of ProcessStep posting."""
+ # pylint: disable=too-many-statements
+ form_data_1 = self.post_process(1)
+ self.post_process(2)
+ self.post_process(3)
+ # post first (top-level) step of process 2 to process 1
+ form_data_1['new_top_step'] = [2]
+ self.post_process(1, form_data_1)
+ retrieved_process = Process.by_id(self.db_conn, 1)
+ self.assertEqual(len(retrieved_process.explicit_steps), 1)
+ retrieved_step = retrieved_process.explicit_steps[0]
+ retrieved_step_id = retrieved_step.id_
+ self.assertEqual(retrieved_step.step_process_id, 2)
+ self.assertEqual(retrieved_step.owner_id, 1)
+ self.assertEqual(retrieved_step.parent_step_id, None)
+ # post empty steps list to process, expect clean slate, and old step to
+ # completely disappear
+ form_data_1['new_top_step'] = []
+ self.post_process(1, form_data_1)
+ retrieved_process = Process.by_id(self.db_conn, 1)
+ self.assertEqual(retrieved_process.explicit_steps, [])
+ assert retrieved_step_id is not None
+ with self.assertRaises(NotFoundException):
+ ProcessStep.by_id(self.db_conn, retrieved_step_id)
+ # post new first (top_level) step of process 3 to process 1
+ form_data_1['new_top_step'] = [3]
+ self.post_process(1, form_data_1)
+ retrieved_process = Process.by_id(self.db_conn, 1)
+ retrieved_step = retrieved_process.explicit_steps[0]
+ self.assertEqual(retrieved_step.step_process_id, 3)
+ self.assertEqual(retrieved_step.owner_id, 1)
+ self.assertEqual(retrieved_step.parent_step_id, None)
+ # post to process steps list without keeps, expect clean slate
+ form_data_1['new_top_step'] = []
+ form_data_1['steps'] = [retrieved_step.id_]
+ self.post_process(1, form_data_1)
+ retrieved_process = Process.by_id(self.db_conn, 1)
+ self.assertEqual(retrieved_process.explicit_steps, [])
+ # post to process empty steps list but keep, expect 400
+ form_data_1['steps'] = []
+ form_data_1['keep_step'] = [retrieved_step_id]
+ self.check_post(form_data_1, '/process?id=1', 400, '/process?id=1')
+ # post to process steps list with keep on non-created step, expect 400
+ form_data_1['steps'] = [retrieved_step_id]
+ form_data_1['keep_step'] = [retrieved_step_id]
+ self.check_post(form_data_1, '/process?id=1', 400, '/process?id=1')
+ # post to process steps list with keep and process ID, expect 200
+ form_data_1[f'step_{retrieved_step_id}_process_id'] = [2]
+ self.post_process(1, form_data_1)
+ retrieved_process = Process.by_id(self.db_conn, 1)
+ self.assertEqual(len(retrieved_process.explicit_steps), 1)
+ retrieved_step = retrieved_process.explicit_steps[0]
+ self.assertEqual(retrieved_step.step_process_id, 2)
+ self.assertEqual(retrieved_step.owner_id, 1)
+ self.assertEqual(retrieved_step.parent_step_id, None)
+ # post nonsense, expect 400 and preservation of previous state
+ form_data_1['steps'] = ['foo']
+ form_data_1['keep_step'] = []
+ self.check_post(form_data_1, '/process?id=1', 400, '/process?id=1')
+ retrieved_process = Process.by_id(self.db_conn, 1)
+ self.assertEqual(len(retrieved_process.explicit_steps), 1)
+ retrieved_step = retrieved_process.explicit_steps[0]
+ self.assertEqual(retrieved_step.step_process_id, 2)
+ self.assertEqual(retrieved_step.owner_id, 1)
+ self.assertEqual(retrieved_step.parent_step_id, None)
+ # post to process steps list with keep and process ID, expect 200
+ form_data_1['new_top_step'] = [3]
+ form_data_1['steps'] = [retrieved_step.id_]
+ form_data_1['keep_step'] = [retrieved_step.id_]
+ self.post_process(1, form_data_1)
+ retrieved_process = Process.by_id(self.db_conn, 1)
+ self.assertEqual(len(retrieved_process.explicit_steps), 2)
+ retrieved_step_0 = retrieved_process.explicit_steps[0]
+ self.assertEqual(retrieved_step_0.step_process_id, 3)
+ self.assertEqual(retrieved_step_0.owner_id, 1)
+ self.assertEqual(retrieved_step_0.parent_step_id, None)
+ retrieved_step_1 = retrieved_process.explicit_steps[1]
+ self.assertEqual(retrieved_step_1.step_process_id, 2)
+ self.assertEqual(retrieved_step_1.owner_id, 1)
+ self.assertEqual(retrieved_step_1.parent_step_id, None)
+ # post to process steps list with keeps etc., but trigger recursion
+ form_data_1['new_top_step'] = []
+ form_data_1['steps'] = [retrieved_step_0.id_, retrieved_step_1.id_]
+ form_data_1['keep_step'] = [retrieved_step_0.id_, retrieved_step_1.id_]
+ form_data_1[f'step_{retrieved_step_0.id_}_process_id'] = [2]
+ form_data_1[f'step_{retrieved_step_1.id_}_process_id'] = [1]
+ self.check_post(form_data_1, '/process?id=1', 400, '/process?id=1')
+ # check previous status preserved despite failed steps setting
+ retrieved_process = Process.by_id(self.db_conn, 1)
+ self.assertEqual(len(retrieved_process.explicit_steps), 2)
+ retrieved_step_0 = retrieved_process.explicit_steps[0]
+ self.assertEqual(retrieved_step_0.step_process_id, 2)
+ self.assertEqual(retrieved_step_0.owner_id, 1)
+ self.assertEqual(retrieved_step_0.parent_step_id, None)
+ retrieved_step_1 = retrieved_process.explicit_steps[1]
+ self.assertEqual(retrieved_step_1.step_process_id, 3)
+ self.assertEqual(retrieved_step_1.owner_id, 1)
+ self.assertEqual(retrieved_step_1.parent_step_id, None)
+ # post sub-step to step
+ form_data_1[f'step_{retrieved_step_0.id_}_process_id'] = [3]
+ form_data_1[f'new_step_to_{retrieved_step_0.id_}'] = [3]
+ self.post_process(1, form_data_1)
+ retrieved_process = Process.by_id(self.db_conn, 1)
+ self.assertEqual(len(retrieved_process.explicit_steps), 3)
+ retrieved_step_0 = retrieved_process.explicit_steps[0]
+ self.assertEqual(retrieved_step_0.step_process_id, 2)
+ self.assertEqual(retrieved_step_0.owner_id, 1)
+ self.assertEqual(retrieved_step_0.parent_step_id, None)
+ retrieved_step_1 = retrieved_process.explicit_steps[1]
+ self.assertEqual(retrieved_step_1.step_process_id, 3)
+ self.assertEqual(retrieved_step_1.owner_id, 1)
+ self.assertEqual(retrieved_step_1.parent_step_id, None)
+ retrieved_step_2 = retrieved_process.explicit_steps[2]
+ self.assertEqual(retrieved_step_2.step_process_id, 3)
+ self.assertEqual(retrieved_step_2.owner_id, 1)
+ self.assertEqual(retrieved_step_2.parent_step_id, retrieved_step_1.id_)
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=FOO', 400)
+ self.check_get_defaults('/process')
self.check_get('/processes', 200)