- 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[1]
- 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[0]
- 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[1]
- 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[0]
- 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=1', 200)
- self.check_get_defaults('/process')
- self.check_get('/processes', 200)
+ url = '/process?id=1'
+ exp = ExpectedGetProcess(1)
+ self.post_exp_process([exp], {}, 1)
+ # post first (top-level) step of proc2 to proc1 by 'step_of' in 2
+ self.post_exp_process([exp], {'step_of': 1}, 2)
+ exp.lib_set('ProcessStep', [exp.procstep_as_dict(1, owner_id=1, step_process_id=2)])
+ exp.set('steps', [
+ exp.stepnode_as_dict(
+ step_id=1,
+ proc_id=2)])
+ self.check_json_get(url, exp)
+ # post empty/absent steps list to process, expect clean slate, and old
+ # step to completely disappear
+ self.post_exp_process([exp], {}, 1)
+ exp.lib_wipe('ProcessStep')
+ exp.set('steps', [])
+ self.check_json_get(url, exp)
+ # post anew (as only step yet) step of proc2 to proc1 by 'new_top_step'
+ self.post_exp_process([exp], {'new_top_step': 2}, 1)
+ exp.lib_set('ProcessStep',
+ [exp.procstep_as_dict(1, owner_id=1, step_process_id=2)])
+ self.post_exp_process([exp], {'kept_steps': [1]}, 1)
+ step_nodes = [exp.stepnode_as_dict(step_id=1, proc_id=2)]
+ exp.set('steps', step_nodes)
+ self.check_json_get(url, exp)
+ # fail on single--step recursion
+ p_min = {'title': '', 'description': '', 'effort': 0}
+ self.check_post(p_min | {'new_top_step': 1}, url, 400)
+ self.check_post(p_min | {'step_of': 1}, url, 400)
+ # post sibling steps
+ self.post_exp_process([exp], {}, 3)
+ self.post_exp_process([exp], {'kept_steps': [1], 'new_top_step': 3}, 1)
+ exp.lib_set('ProcessStep',
+ [exp.procstep_as_dict(2, owner_id=1, step_process_id=3)])
+ step_nodes += [exp.stepnode_as_dict(step_id=2, proc_id=3)]
+ self.check_json_get(url, exp)
+ # # post implicit sub-step via post to proc2
+ self.post_exp_process([exp], {}, 4)
+ self.post_exp_process([exp], {'step_of': [1], 'new_top_step': 4}, 2)
+ exp.lib_set('ProcessStep',
+ [exp.procstep_as_dict(3, owner_id=2, step_process_id=4)])
+ step_nodes[0]['steps'] = [
+ exp.stepnode_as_dict(step_id=3, proc_id=4, is_explicit=False)]
+ self.check_json_get(url, exp)
+ # post explicit sub-step via post to proc1
+ p = {'kept_steps': [1, 2], 'new_step_to_2': 4}
+ self.post_exp_process([exp], p, 1)
+ exp.lib_set('ProcessStep', [exp.procstep_as_dict(
+ 4, owner_id=1, step_process_id=4, parent_step_id=2)])
+ step_nodes[1]['steps'] = [
+ exp.stepnode_as_dict(step_id=4, proc_id=4)]
+ self.check_json_get(url, exp)
+ # fail on multi-step recursion via new step(s)
+ self.post_exp_process([exp], {}, 5)
+ self.post_exp_process([exp], {'new_top_step': 1}, 5)
+ exp.lib_set('ProcessStep', [exp.procstep_as_dict(
+ 5, owner_id=5, step_process_id=1)])
+ self.check_post(p_min | {'step_of': 5, 'new_top_step': 5}, url, 400)
+ self.post_exp_process([exp], {}, 6)
+ self.post_exp_process([exp], {'new_top_step': 5}, 6)
+ exp.lib_set('ProcessStep', [exp.procstep_as_dict(
+ 6, owner_id=6, step_process_id=5)])
+ self.check_post(p_min | {'step_of': 5, 'new_top_step': 6}, url, 400)
+ # fail on multi-step recursion via explicit sub-step
+ self.check_json_get(url, exp)
+ p = {'step_of': 5, 'kept_steps': [1, 2, 4], 'new_step_to_2': 6}
+ self.check_post(p_min | p, url, 400)