1 """Test Processes module."""
3 from tests.utils import TestCaseWithDB, TestCaseWithServer, TestCaseSansDB
4 from plomtask.processes import Process, ProcessStep, ProcessStepsNode
5 from plomtask.conditions import Condition
6 from plomtask.exceptions import HandledException, NotFoundException
7 from plomtask.todos import Todo
10 class TestsSansDB(TestCaseSansDB):
11 """Module tests not requiring DB setup."""
12 checked_class = Process
13 versioned_defaults_to_test = {'title': 'UNNAMED', 'description': '',
17 class TestsSansDBProcessStep(TestCaseSansDB):
18 """Module tests not requiring DB setup."""
19 checked_class = ProcessStep
20 default_init_args = [2, 3, 4]
23 class TestsWithDB(TestCaseWithDB):
24 """Module tests requiring DB setup."""
25 checked_class = Process
26 test_versioneds = {'title': str, 'description': str, 'effort': float}
28 def three_processes(self) -> tuple[Process, Process, Process]:
29 """Return three saved processes."""
30 p1, p2, p3 = Process(None), Process(None), Process(None)
31 for p in [p1, p2, p3]:
35 def p_of_conditions(self) -> tuple[Process, list[Condition],
36 list[Condition], list[Condition]]:
37 """Return Process and its three Condition sets."""
39 c1, c2, c3 = Condition(None), Condition(None), Condition(None)
40 for c in [c1, c2, c3]:
42 assert isinstance(c1.id_, int)
43 assert isinstance(c2.id_, int)
44 assert isinstance(c3.id_, int)
48 p.set_conditions(self.db_conn, [c.id_ for c in set_1
49 if isinstance(c.id_, int)])
50 p.set_enables(self.db_conn, [c.id_ for c in set_2
51 if isinstance(c.id_, int)])
52 p.set_disables(self.db_conn, [c.id_ for c in set_3
53 if isinstance(c.id_, int)])
55 return p, set_1, set_2, set_3
57 def test_Process_conditions_saving(self) -> None:
58 """Test .save/.save_core."""
59 p, set1, set2, set3 = self.p_of_conditions()
60 assert p.id_ is not None
61 r = Process.by_id(self.db_conn, p.id_)
62 self.assertEqual(sorted(r.conditions), sorted(set1))
63 self.assertEqual(sorted(r.enables), sorted(set2))
64 self.assertEqual(sorted(r.disables), sorted(set3))
66 def test_from_table_row(self) -> None:
67 """Test .from_table_row() properly reads in class from DB."""
68 super().test_from_table_row()
69 p, set1, set2, set3 = self.p_of_conditions()
71 assert isinstance(p.id_, int)
72 for row in self.db_conn.row_where(self.checked_class.table_name,
74 r = Process.from_table_row(self.db_conn, row)
75 self.assertEqual(sorted(r.conditions), sorted(set1))
76 self.assertEqual(sorted(r.enables), sorted(set2))
77 self.assertEqual(sorted(r.disables), sorted(set3))
79 def test_Process_steps(self) -> None:
80 """Test addition, nesting, and non-recursion of ProcessSteps"""
81 # pylint: disable=too-many-locals
82 # pylint: disable=too-many-statements
83 p1, p2, p3 = self.three_processes()
84 assert isinstance(p1.id_, int)
85 assert isinstance(p2.id_, int)
86 assert isinstance(p3.id_, int)
87 steps_p1: list[ProcessStep] = []
88 # add step of process p2 as first (top-level) step to p1
89 s_p2_to_p1 = ProcessStep(None, p1.id_, p2.id_, None)
90 steps_p1 += [s_p2_to_p1]
91 p1.set_steps(self.db_conn, steps_p1)
92 p1_dict: dict[int, ProcessStepsNode] = {}
93 p1_dict[1] = ProcessStepsNode(p2, None, True, {})
94 self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
95 # add step of process p3 as second (top-level) step to p1
96 s_p3_to_p1 = ProcessStep(None, p1.id_, p3.id_, None)
97 steps_p1 += [s_p3_to_p1]
98 p1.set_steps(self.db_conn, steps_p1)
99 p1_dict[2] = ProcessStepsNode(p3, None, True, {})
100 self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
101 # add step of process p3 as first (top-level) step to p2,
102 steps_p2: list[ProcessStep] = []
103 s_p3_to_p2 = ProcessStep(None, p2.id_, p3.id_, None)
104 steps_p2 += [s_p3_to_p2]
105 p2.set_steps(self.db_conn, steps_p2)
106 # expect it as implicit sub-step of p1's second (p3) step
107 p2_dict = {3: ProcessStepsNode(p3, None, False, {})}
108 p1_dict[1].steps[3] = p2_dict[3]
109 self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
110 # add step of process p2 as explicit sub-step to p1's second sub-step
111 s_p2_to_p1_first = ProcessStep(None, p1.id_, p2.id_, s_p3_to_p1.id_)
112 steps_p1 += [s_p2_to_p1_first]
113 p1.set_steps(self.db_conn, steps_p1)
114 seen_3 = ProcessStepsNode(p3, None, False, {}, False)
115 p1_dict[1].steps[3].seen = True
116 p1_dict[2].steps[4] = ProcessStepsNode(p2, s_p3_to_p1.id_, True,
118 self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
119 # add step of process p3 as explicit sub-step to non-existing p1
120 # sub-step (of id=999), expect it to become another p1 top-level step
121 s_p3_to_p1_999 = ProcessStep(None, p1.id_, p3.id_, 999)
122 steps_p1 += [s_p3_to_p1_999]
123 p1.set_steps(self.db_conn, steps_p1)
124 p1_dict[5] = ProcessStepsNode(p3, None, True, {})
125 self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
126 # add step of process p3 as explicit sub-step to p1's implicit p3
127 # sub-step, expect it to become another p1 top-level step
128 s_p3_to_p1_impl_p3 = ProcessStep(None, p1.id_, p3.id_, s_p3_to_p2.id_)
129 steps_p1 += [s_p3_to_p1_impl_p3]
130 p1.set_steps(self.db_conn, steps_p1)
131 p1_dict[6] = ProcessStepsNode(p3, None, True, {})
132 self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
133 self.assertEqual(p1.used_as_step_by(self.db_conn), [])
134 self.assertEqual(p2.used_as_step_by(self.db_conn), [p1])
135 self.assertEqual(p3.used_as_step_by(self.db_conn), [p1, p2])
136 # # add step of process p3 as explicit sub-step to p1's first sub-step,
137 # # expect it to eliminate implicit p3 sub-step
138 # s_p3_to_p1_first_explicit = ProcessStep(None, p1.id_, p3.id_,
140 # p1_dict[1].steps = {7: ProcessStepsNode(p3, 1, True, {})}
141 # p1_dict[2].steps[4].steps[3].seen = False
142 # steps_p1 += [s_p3_to_p1_first_explicit]
143 # p1.set_steps(self.db_conn, steps_p1)
144 # self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
145 # ensure implicit steps non-top explicit steps are shown
146 s_p3_to_p2_first = ProcessStep(None, p2.id_, p3.id_, s_p3_to_p2.id_)
147 steps_p2 += [s_p3_to_p2_first]
148 p2.set_steps(self.db_conn, steps_p2)
149 p1_dict[1].steps[3].steps[7] = ProcessStepsNode(p3, 3, False, {}, True)
150 p1_dict[2].steps[4].steps[3].steps[7] = ProcessStepsNode(p3, 3, False,
152 self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
153 # ensure suppressed step nodes are hidden
154 assert isinstance(s_p3_to_p2.id_, int)
155 p1.set_step_suppressions(self.db_conn, [s_p3_to_p2.id_])
156 p1_dict[1].steps[3].steps = {}
157 p1_dict[1].steps[3].is_suppressed = True
158 p1_dict[2].steps[4].steps[3].steps = {}
159 p1_dict[2].steps[4].steps[3].is_suppressed = True
160 self.assertEqual(p1.get_steps(self.db_conn), p1_dict)
162 def test_Process_conditions(self) -> None:
163 """Test setting Process.conditions/enables/disables."""
166 for target in ('conditions', 'enables', 'disables'):
167 method = getattr(p, f'set_{target}')
168 c1, c2 = Condition(None), Condition(None)
169 c1.save(self.db_conn)
170 c2.save(self.db_conn)
171 assert isinstance(c1.id_, int)
172 assert isinstance(c2.id_, int)
173 method(self.db_conn, [])
174 self.assertEqual(getattr(p, target), [])
175 method(self.db_conn, [c1.id_])
176 self.assertEqual(getattr(p, target), [c1])
177 method(self.db_conn, [c2.id_])
178 self.assertEqual(getattr(p, target), [c2])
179 method(self.db_conn, [c1.id_, c2.id_])
180 self.assertEqual(getattr(p, target), [c1, c2])
182 def test_remove(self) -> None:
183 """Test removal of Processes and ProcessSteps."""
184 super().test_remove()
185 p1, p2, p3 = self.three_processes()
186 assert isinstance(p1.id_, int)
187 assert isinstance(p2.id_, int)
188 assert isinstance(p3.id_, int)
189 step = ProcessStep(None, p2.id_, p1.id_, None)
190 p2.set_steps(self.db_conn, [step])
192 with self.assertRaises(HandledException):
193 p1.remove(self.db_conn)
194 p2.set_steps(self.db_conn, [])
195 with self.assertRaises(NotFoundException):
196 assert step_id is not None
197 ProcessStep.by_id(self.db_conn, step_id)
198 p1.remove(self.db_conn)
199 step = ProcessStep(None, p2.id_, p3.id_, None)
200 p2.set_steps(self.db_conn, [step])
202 p2.remove(self.db_conn)
203 with self.assertRaises(NotFoundException):
204 assert step_id is not None
205 ProcessStep.by_id(self.db_conn, step_id)
206 todo = Todo(None, p3, False, '2024-01-01')
207 todo.save(self.db_conn)
208 with self.assertRaises(HandledException):
209 p3.remove(self.db_conn)
210 todo.remove(self.db_conn)
211 p3.remove(self.db_conn)
214 class TestsWithDBForProcessStep(TestCaseWithDB):
215 """Module tests requiring DB setup."""
216 checked_class = ProcessStep
217 default_init_kwargs = {'owner_id': 1, 'step_process_id': 2,
220 def setUp(self) -> None:
223 self.p1.save(self.db_conn)
225 def test_remove(self) -> None:
226 """Test .remove and unsetting of owner's .explicit_steps entry."""
228 p2.save(self.db_conn)
229 assert isinstance(self.p1.id_, int)
230 assert isinstance(p2.id_, int)
231 step = ProcessStep(None, self.p1.id_, p2.id_, None)
232 self.p1.set_steps(self.db_conn, [step])
233 step.remove(self.db_conn)
234 self.assertEqual(self.p1.explicit_steps, [])
235 self.check_identity_with_cache_and_db([])
238 class TestsWithServer(TestCaseWithServer):
239 """Module tests against our HTTP server/handler (and database)."""
241 def test_do_POST_process(self) -> None:
242 """Test POST /process and its effect on the database."""
243 self.assertEqual(0, len(Process.all(self.db_conn)))
244 form_data = self.post_process()
245 self.assertEqual(1, len(Process.all(self.db_conn)))
246 self.check_post(form_data, '/process?id=FOO', 400)
247 self.check_post(form_data | {'effort': 'foo'}, '/process?id=', 400)
248 self.check_post({}, '/process?id=', 400)
249 self.check_post({'title': '', 'description': ''}, '/process?id=', 400)
250 self.check_post({'title': '', 'effort': 1.1}, '/process?id=', 400)
251 self.check_post({'description': '', 'effort': 1.0},
253 self.assertEqual(1, len(Process.all(self.db_conn)))
254 form_data = {'title': 'foo', 'description': 'foo', 'effort': 1.0}
255 self.post_process(2, form_data | {'conditions': []})
256 self.check_post(form_data | {'conditions': [1]}, '/process?id=', 404)
257 self.check_post({'title': 'foo', 'description': 'foo',
259 '/condition', 302, '/condition?id=1')
260 self.post_process(3, form_data | {'conditions': [1]})
261 self.post_process(4, form_data | {'disables': [1]})
262 self.post_process(5, form_data | {'enables': [1]})
263 form_data['delete'] = ''
264 self.check_post(form_data, '/process?id=', 404)
265 self.check_post(form_data, '/process?id=6', 404)
266 self.check_post(form_data, '/process?id=5', 302, '/processes')
268 def test_do_POST_process_steps(self) -> None:
269 """Test behavior of ProcessStep posting."""
270 # pylint: disable=too-many-statements
271 form_data_1 = self.post_process(1)
274 # post first (top-level) step of process 2 to process 1
275 form_data_1['new_top_step'] = [2]
276 self.post_process(1, form_data_1)
277 retrieved_process = Process.by_id(self.db_conn, 1)
278 self.assertEqual(len(retrieved_process.explicit_steps), 1)
279 retrieved_step = retrieved_process.explicit_steps[0]
280 retrieved_step_id = retrieved_step.id_
281 self.assertEqual(retrieved_step.step_process_id, 2)
282 self.assertEqual(retrieved_step.owner_id, 1)
283 self.assertEqual(retrieved_step.parent_step_id, None)
284 # post empty steps list to process, expect clean slate, and old step to
285 # completely disappear
286 form_data_1['new_top_step'] = []
287 self.post_process(1, form_data_1)
288 retrieved_process = Process.by_id(self.db_conn, 1)
289 self.assertEqual(retrieved_process.explicit_steps, [])
290 assert retrieved_step_id is not None
291 with self.assertRaises(NotFoundException):
292 ProcessStep.by_id(self.db_conn, retrieved_step_id)
293 # post new first (top_level) step of process 3 to process 1
294 form_data_1['new_top_step'] = [3]
295 self.post_process(1, form_data_1)
296 retrieved_process = Process.by_id(self.db_conn, 1)
297 retrieved_step = retrieved_process.explicit_steps[0]
298 self.assertEqual(retrieved_step.step_process_id, 3)
299 self.assertEqual(retrieved_step.owner_id, 1)
300 self.assertEqual(retrieved_step.parent_step_id, None)
301 # post to process steps list without keeps, expect clean slate
302 form_data_1['new_top_step'] = []
303 form_data_1['steps'] = [retrieved_step.id_]
304 self.post_process(1, form_data_1)
305 retrieved_process = Process.by_id(self.db_conn, 1)
306 self.assertEqual(retrieved_process.explicit_steps, [])
307 # post to process empty steps list but keep, expect 400
308 form_data_1['steps'] = []
309 form_data_1['keep_step'] = [retrieved_step_id]
310 self.check_post(form_data_1, '/process?id=1', 400, '/process?id=1')
311 # post to process steps list with keep on non-created step, expect 400
312 form_data_1['steps'] = [retrieved_step_id]
313 form_data_1['keep_step'] = [retrieved_step_id]
314 self.check_post(form_data_1, '/process?id=1', 400, '/process?id=1')
315 # post to process steps list with keep and process ID, expect 200
316 form_data_1[f'step_{retrieved_step_id}_process_id'] = [2]
317 self.post_process(1, form_data_1)
318 retrieved_process = Process.by_id(self.db_conn, 1)
319 self.assertEqual(len(retrieved_process.explicit_steps), 1)
320 retrieved_step = retrieved_process.explicit_steps[0]
321 self.assertEqual(retrieved_step.step_process_id, 2)
322 self.assertEqual(retrieved_step.owner_id, 1)
323 self.assertEqual(retrieved_step.parent_step_id, None)
324 # post nonsense, expect 400 and preservation of previous state
325 form_data_1['steps'] = ['foo']
326 form_data_1['keep_step'] = []
327 self.check_post(form_data_1, '/process?id=1', 400, '/process?id=1')
328 retrieved_process = Process.by_id(self.db_conn, 1)
329 self.assertEqual(len(retrieved_process.explicit_steps), 1)
330 retrieved_step = retrieved_process.explicit_steps[0]
331 self.assertEqual(retrieved_step.step_process_id, 2)
332 self.assertEqual(retrieved_step.owner_id, 1)
333 self.assertEqual(retrieved_step.parent_step_id, None)
334 # post to process steps list with keep and process ID, expect 200
335 form_data_1['new_top_step'] = [3]
336 form_data_1['steps'] = [retrieved_step.id_]
337 form_data_1['keep_step'] = [retrieved_step.id_]
338 self.post_process(1, form_data_1)
339 retrieved_process = Process.by_id(self.db_conn, 1)
340 self.assertEqual(len(retrieved_process.explicit_steps), 2)
341 retrieved_step_0 = retrieved_process.explicit_steps[1]
342 self.assertEqual(retrieved_step_0.step_process_id, 3)
343 self.assertEqual(retrieved_step_0.owner_id, 1)
344 self.assertEqual(retrieved_step_0.parent_step_id, None)
345 retrieved_step_1 = retrieved_process.explicit_steps[0]
346 self.assertEqual(retrieved_step_1.step_process_id, 2)
347 self.assertEqual(retrieved_step_1.owner_id, 1)
348 self.assertEqual(retrieved_step_1.parent_step_id, None)
349 # post to process steps list with keeps etc., but trigger recursion
350 form_data_1['new_top_step'] = []
351 form_data_1['steps'] = [retrieved_step_0.id_, retrieved_step_1.id_]
352 form_data_1['keep_step'] = [retrieved_step_0.id_, retrieved_step_1.id_]
353 form_data_1[f'step_{retrieved_step_0.id_}_process_id'] = [2]
354 form_data_1[f'step_{retrieved_step_1.id_}_process_id'] = [1]
355 self.check_post(form_data_1, '/process?id=1', 400, '/process?id=1')
356 # check previous status preserved despite failed steps setting
357 retrieved_process = Process.by_id(self.db_conn, 1)
358 self.assertEqual(len(retrieved_process.explicit_steps), 2)
359 retrieved_step_0 = retrieved_process.explicit_steps[0]
360 self.assertEqual(retrieved_step_0.step_process_id, 2)
361 self.assertEqual(retrieved_step_0.owner_id, 1)
362 self.assertEqual(retrieved_step_0.parent_step_id, None)
363 retrieved_step_1 = retrieved_process.explicit_steps[1]
364 self.assertEqual(retrieved_step_1.step_process_id, 3)
365 self.assertEqual(retrieved_step_1.owner_id, 1)
366 self.assertEqual(retrieved_step_1.parent_step_id, None)
367 # post sub-step to step
368 form_data_1[f'step_{retrieved_step_0.id_}_process_id'] = [3]
369 form_data_1[f'new_step_to_{retrieved_step_0.id_}'] = [3]
370 self.post_process(1, form_data_1)
371 retrieved_process = Process.by_id(self.db_conn, 1)
372 self.assertEqual(len(retrieved_process.explicit_steps), 3)
373 retrieved_step_0 = retrieved_process.explicit_steps[1]
374 self.assertEqual(retrieved_step_0.step_process_id, 2)
375 self.assertEqual(retrieved_step_0.owner_id, 1)
376 self.assertEqual(retrieved_step_0.parent_step_id, None)
377 retrieved_step_1 = retrieved_process.explicit_steps[0]
378 self.assertEqual(retrieved_step_1.step_process_id, 3)
379 self.assertEqual(retrieved_step_1.owner_id, 1)
380 self.assertEqual(retrieved_step_1.parent_step_id, None)
381 retrieved_step_2 = retrieved_process.explicit_steps[2]
382 self.assertEqual(retrieved_step_2.step_process_id, 3)
383 self.assertEqual(retrieved_step_2.owner_id, 1)
384 self.assertEqual(retrieved_step_2.parent_step_id, retrieved_step_1.id_)
386 def test_do_GET(self) -> None:
387 """Test /process and /processes response codes."""
388 self.check_get('/process', 200)
389 self.check_get('/process?id=', 200)
390 self.check_get('/process?id=1', 200)
391 self.check_get_defaults('/process')
392 self.check_get('/processes', 200)
394 def test_fail_GET_process(self) -> None:
395 """Test invalid GET /process params."""
396 # check for invalid IDs
397 self.check_get('/process?id=foo', 400)
398 self.check_get('/process?id=0', 500)
399 # check we catch invalid base64
400 self.check_get('/process?title_b64=foo', 400)
401 # check failure on references to unknown processes; we create Process
402 # of ID=1 here so we know the 404 comes from step_to=2 etc. (that tie
403 # the Process displayed by /process to others), not from not finding
404 # the main Process itself
406 self.check_get('/process?id=1&step_to=2', 404)
407 self.check_get('/process?id=1&has_step=2', 404)
410 def GET_processes_dict(cls, procs: list[dict[str, object]]
411 ) -> dict[str, object]:
412 """Return JSON of GET /processes to expect."""
413 library = {'Process': cls.as_refs(procs)} if procs else {}
414 d: dict[str, object] = {'processes': cls.as_id_list(procs),
421 def procstep_as_dict(id_: int,
423 step_process_id: int,
424 parent_step_id: int | None = None
425 ) -> dict[str, object]:
426 """Return JSON of Process to expect."""
428 'owner_id': owner_id,
429 'step_process_id': step_process_id,
430 'parent_step_id': parent_step_id}
432 def test_GET_processes(self) -> None:
433 """Test GET /processes."""
434 # pylint: disable=too-many-statements
435 # test empty result on empty DB, default-settings on empty params
436 expected = self.GET_processes_dict([])
437 self.check_json_get('/processes', expected)
438 # test on meaningless non-empty params (incl. entirely un-used key),
439 # that 'sort_by' default to 'title' (even if set to something else, as
440 # long as without handler) and 'pattern' get preserved
441 expected['pattern'] = 'bar' # preserved despite zero effect!
442 url = '/processes?sort_by=foo&pattern=bar&foo=x'
443 self.check_json_get(url, expected)
444 # test non-empty result, automatic (positive) sorting by title
445 post1: dict[str, Any]
446 post2: dict[str, Any]
447 post3: dict[str, Any]
448 post1 = {'title': 'foo', 'description': 'oof', 'effort': 1.0}
449 post2 = {'title': 'bar', 'description': 'rab', 'effort': 1.1}
450 post2['new_top_step'] = 1
451 post3 = {'title': 'baz', 'description': 'zab', 'effort': 0.9}
452 post3['new_top_step'] = 1
453 self.post_process(1, post1)
454 self.post_process(2, post2)
455 self.post_process(3, post3)
456 post3['new_top_step'] = 2
457 post3['keep_step'] = 2
459 post3['step_2_process_id'] = 1
460 self.post_process(3, post3)
461 proc1 = self.proc_as_dict(1, post1['title'],
462 post1['description'], post1['effort'])
463 proc2 = self.proc_as_dict(2, post2['title'],
464 post2['description'], post2['effort'])
465 proc3 = self.proc_as_dict(3, post3['title'],
466 post3['description'], post3['effort'])
467 proc2['explicit_steps'] = [1]
468 proc3['explicit_steps'] = [2, 3]
469 step1 = self.procstep_as_dict(1, 2, 1)
470 step2 = self.procstep_as_dict(2, 3, 1)
471 step3 = self.procstep_as_dict(3, 3, 2)
472 expected = self.GET_processes_dict([proc2, proc3, proc1])
473 assert isinstance(expected['_library'], dict)
474 expected['_library']['ProcessStep'] = self.as_refs([step1, step2,
476 self.check_json_get('/processes', expected)
477 # test other sortings
478 expected['sort_by'] = '-title'
479 expected['processes'] = self.as_id_list([proc1, proc3, proc2])
480 self.check_json_get('/processes?sort_by=-title', expected)
481 expected['sort_by'] = 'effort'
482 expected['processes'] = self.as_id_list([proc3, proc1, proc2])
483 self.check_json_get('/processes?sort_by=effort', expected)
484 expected['sort_by'] = '-effort'
485 expected['processes'] = self.as_id_list([proc2, proc1, proc3])
486 self.check_json_get('/processes?sort_by=-effort', expected)
487 expected['sort_by'] = 'steps'
488 expected['processes'] = self.as_id_list([proc1, proc2, proc3])
489 self.check_json_get('/processes?sort_by=steps', expected)
490 expected['sort_by'] = '-steps'
491 expected['processes'] = self.as_id_list([proc3, proc2, proc1])
492 self.check_json_get('/processes?sort_by=-steps', expected)
493 expected['sort_by'] = 'owners'
494 expected['processes'] = self.as_id_list([proc3, proc2, proc1])
495 self.check_json_get('/processes?sort_by=owners', expected)
496 expected['sort_by'] = '-owners'
497 expected['processes'] = self.as_id_list([proc1, proc2, proc3])
498 self.check_json_get('/processes?sort_by=-owners', expected)
499 # test pattern matching on title
500 expected = self.GET_processes_dict([proc2, proc3])
501 assert isinstance(expected['_library'], dict)
502 expected['pattern'] = 'ba'
503 expected['_library']['ProcessStep'] = self.as_refs([step1, step2,
505 self.check_json_get('/processes?pattern=ba', expected)
506 # test pattern matching on description
507 expected['processes'] = self.as_id_list([proc1])
508 expected['_library'] = {'Process': self.as_refs([proc1])}
509 expected['pattern'] = 'of'
510 self.check_json_get('/processes?pattern=of', expected)