1 """Test Todos module."""
3 from tests.utils import (TestCaseSansDB, TestCaseWithDB, TestCaseWithServer,
5 from plomtask.todos import Todo, TodoNode
6 from plomtask.processes import Process, ProcessStep
7 from plomtask.conditions import Condition
8 from plomtask.exceptions import (NotFoundException, BadFormatException,
12 class TestsWithDB(TestCaseWithDB, TestCaseSansDB):
13 """Tests requiring DB, but not server setup.
15 NB: We subclass TestCaseSansDB too, to run any tests there that due to any
16 Todo requiring a _saved_ Process wouldn't run without a DB.
19 default_init_kwargs = {'process': None, 'is_done': False,
22 def setUp(self) -> None:
24 self.date1 = '2024-01-01'
25 self.date2 = '2024-01-02'
26 self.proc = Process(None)
27 self.proc.save(self.db_conn)
28 self.cond1 = Condition(None)
29 self.cond1.save(self.db_conn)
30 self.cond2 = Condition(None)
31 self.cond2.save(self.db_conn)
32 self.default_init_kwargs['process'] = self.proc
34 def test_Todo_init(self) -> None:
35 """Test creation of Todo and what they default to."""
36 process = Process(None)
37 with self.assertRaises(NotFoundException):
38 Todo(None, process, False, self.date1)
39 process.save(self.db_conn)
40 assert isinstance(self.cond1.id_, int)
41 assert isinstance(self.cond2.id_, int)
42 process.set_condition_relations(self.db_conn,
43 [self.cond1.id_, self.cond2.id_], [],
44 [self.cond1.id_], [self.cond2.id_])
45 todo_no_id = Todo(None, process, False, self.date1)
46 self.assertEqual(todo_no_id.conditions, [self.cond1, self.cond2])
47 self.assertEqual(todo_no_id.enables, [self.cond1])
48 self.assertEqual(todo_no_id.disables, [self.cond2])
49 todo_yes_id = Todo(5, process, False, self.date1)
50 self.assertEqual(todo_yes_id.conditions, [])
51 self.assertEqual(todo_yes_id.enables, [])
52 self.assertEqual(todo_yes_id.disables, [])
54 def test_Todo_by_date(self) -> None:
55 """Test findability of Todos by date."""
56 t1 = Todo(None, self.proc, False, self.date1)
58 t2 = Todo(None, self.proc, False, self.date1)
60 self.assertEqual(Todo.by_date(self.db_conn, self.date1), [t1, t2])
61 self.assertEqual(Todo.by_date(self.db_conn, self.date2), [])
62 with self.assertRaises(BadFormatException):
63 self.assertEqual(Todo.by_date(self.db_conn, 'foo'), [])
65 def test_Todo_by_date_range_with_limits(self) -> None:
66 """Test .by_date_range_with_limits."""
67 self.check_by_date_range_with_limits('day')
69 def test_Todo_on_conditions(self) -> None:
70 """Test effect of Todos on Conditions."""
71 assert isinstance(self.cond1.id_, int)
72 assert isinstance(self.cond2.id_, int)
73 todo = Todo(None, self.proc, False, self.date1)
74 todo.save(self.db_conn)
75 todo.set_condition_relations(self.db_conn, [], [],
76 [self.cond1.id_], [self.cond2.id_])
78 self.assertEqual(self.cond1.is_active, True)
79 self.assertEqual(self.cond2.is_active, False)
81 self.assertEqual(self.cond1.is_active, True)
82 self.assertEqual(self.cond2.is_active, False)
84 def test_Todo_children(self) -> None:
85 """Test Todo.children relations."""
86 todo_1 = Todo(None, self.proc, False, self.date1)
87 todo_2 = Todo(None, self.proc, False, self.date1)
88 todo_2.save(self.db_conn)
89 with self.assertRaises(HandledException):
90 todo_1.add_child(todo_2)
91 todo_1.save(self.db_conn)
92 todo_3 = Todo(None, self.proc, False, self.date1)
93 with self.assertRaises(HandledException):
94 todo_1.add_child(todo_3)
95 todo_3.save(self.db_conn)
96 todo_1.add_child(todo_3)
97 todo_1.save(self.db_conn)
98 assert isinstance(todo_1.id_, int)
99 todo_retrieved = Todo.by_id(self.db_conn, todo_1.id_)
100 self.assertEqual(todo_retrieved.children, [todo_3])
101 with self.assertRaises(BadFormatException):
102 todo_3.add_child(todo_1)
104 def test_Todo_conditioning(self) -> None:
105 """Test Todo.doability conditions."""
106 assert isinstance(self.cond1.id_, int)
107 todo_1 = Todo(None, self.proc, False, self.date1)
108 todo_1.save(self.db_conn)
109 todo_2 = Todo(None, self.proc, False, self.date1)
110 todo_2.save(self.db_conn)
111 todo_2.add_child(todo_1)
112 with self.assertRaises(BadFormatException):
113 todo_2.is_done = True
114 todo_1.is_done = True
115 todo_2.is_done = True
116 todo_2.is_done = False
117 todo_2.set_condition_relations(
118 self.db_conn, [self.cond1.id_], [], [], [])
119 with self.assertRaises(BadFormatException):
120 todo_2.is_done = True
121 self.cond1.is_active = True
122 todo_2.is_done = True
124 def test_Todo_step_tree(self) -> None:
125 """Test self-configuration of TodoStepsNode tree for Day view."""
127 def todo_node_as_dict(node: TodoNode) -> dict[str, object]:
128 return {'todo': node.todo.id_, 'seen': node.seen,
129 'children': [todo_node_as_dict(c) for c in node.children]}
131 todo_1 = Todo(None, self.proc, False, self.date1)
132 todo_1.save(self.db_conn)
133 assert isinstance(todo_1.id_, int)
135 node_0 = TodoNode(todo_1, False, [])
136 cmp_0_dict = todo_node_as_dict(todo_1.get_step_tree(set()))
137 cmp_1_dict = todo_node_as_dict(node_0)
138 self.assertEqual(cmp_0_dict, cmp_1_dict)
139 # test non_emtpy seen_todo does something
141 cmp_0_dict = todo_node_as_dict(todo_1.get_step_tree({todo_1.id_}))
142 cmp_1_dict = todo_node_as_dict(node_0)
143 self.assertEqual(cmp_0_dict, cmp_1_dict)
144 # test child shows up
145 todo_2 = Todo(None, self.proc, False, self.date1)
146 todo_2.save(self.db_conn)
147 assert isinstance(todo_2.id_, int)
148 todo_1.add_child(todo_2)
149 node_2 = TodoNode(todo_2, False, [])
150 node_0.children = [node_2]
152 cmp_0_dict = todo_node_as_dict(todo_1.get_step_tree(set()))
153 cmp_1_dict = todo_node_as_dict(node_0)
154 self.assertEqual(cmp_0_dict, cmp_1_dict)
155 # test child shows up with child
156 todo_3 = Todo(None, self.proc, False, self.date1)
157 todo_3.save(self.db_conn)
158 assert isinstance(todo_3.id_, int)
159 todo_2.add_child(todo_3)
160 node_3 = TodoNode(todo_3, False, [])
161 node_2.children = [node_3]
162 cmp_0_dict = todo_node_as_dict(todo_1.get_step_tree(set()))
163 cmp_1_dict = todo_node_as_dict(node_0)
164 self.assertEqual(cmp_0_dict, cmp_1_dict)
165 # test same todo can be child-ed multiple times at different locations
166 todo_1.add_child(todo_3)
167 node_4 = TodoNode(todo_3, True, [])
168 node_0.children += [node_4]
169 cmp_0_dict = todo_node_as_dict(todo_1.get_step_tree(set()))
170 cmp_1_dict = todo_node_as_dict(node_0)
171 self.assertEqual(cmp_0_dict, cmp_1_dict)
173 def test_Todo_ensure_children(self) -> None:
174 """Test parenthood guarantees of Todo.ensure_children."""
175 assert isinstance(self.proc.id_, int)
176 proc2 = Process(None)
177 proc2.save(self.db_conn)
178 assert isinstance(proc2.id_, int)
179 proc3 = Process(None)
180 proc3.save(self.db_conn)
181 assert isinstance(proc3.id_, int)
182 proc4 = Process(None)
183 proc4.save(self.db_conn)
184 assert isinstance(proc4.id_, int)
185 # make proc4 step of proc3
186 step = ProcessStep(None, proc3.id_, proc4.id_, None)
187 proc3.set_steps(self.db_conn, [step])
188 # give proc2 three steps; 2× proc1, 1× proc3
189 step1 = ProcessStep(None, proc2.id_, self.proc.id_, None)
190 step2 = ProcessStep(None, proc2.id_, self.proc.id_, None)
191 step3 = ProcessStep(None, proc2.id_, proc3.id_, None)
192 proc2.set_steps(self.db_conn, [step1, step2, step3])
193 # test mere creation does nothing
194 todo_ignore = Todo(None, proc2, False, self.date1)
195 todo_ignore.save(self.db_conn)
196 self.assertEqual(todo_ignore.children, [])
197 # test create_with_children on step-less does nothing
198 todo_1 = Todo(None, self.proc, False, self.date1)
199 todo_1.save(self.db_conn)
200 todo_1.ensure_children(self.db_conn)
201 self.assertEqual(todo_1.children, [])
202 self.assertEqual(len(Todo.all(self.db_conn)), 2)
203 # test create_with_children adopts and creates, and down tree too
204 todo_2 = Todo(None, proc2, False, self.date1)
205 todo_2.save(self.db_conn)
206 todo_2.ensure_children(self.db_conn)
207 self.assertEqual(3, len(todo_2.children))
208 self.assertEqual(todo_1, todo_2.children[0])
209 self.assertEqual(self.proc, todo_2.children[2].process)
210 self.assertEqual(proc3, todo_2.children[1].process)
211 todo_3 = todo_2.children[1]
212 self.assertEqual(len(todo_3.children), 1)
213 self.assertEqual(todo_3.children[0].process, proc4)
216 class ExpectedGetTodo(Expected):
217 """Builder of expectations for GET /todo."""
221 *args: Any, **kwargs: Any) -> None:
222 self._fields = {'todo': todo_id,
223 'steps_todo_to_process': []}
224 super().__init__(*args, **kwargs)
226 def recalc(self) -> None:
227 """Update internal dictionary by subclass-specific rules."""
229 def walk_steps(step: dict[str, Any]) -> None:
231 proc_id = step['process']
233 [t for t in todos if proc_id == t['process_id']
234 and t['id'] in self._fields['todo_candidates']])
235 self._fields['adoption_candidates_for'][str(proc_id)] = cands
236 for child in step['children']:
241 todos = self.lib_all('Todo')
242 procs = self.lib_all('Process')
243 conds = self.lib_all('Condition')
244 self._fields['todo_candidates'] = self.as_ids(
245 [t for t in todos if t['id'] != self._fields['todo']])
246 self._fields['process_candidates'] = self.as_ids(procs)
247 self._fields['condition_candidates'] = self.as_ids(conds)
248 self._fields['adoption_candidates_for'] = {}
249 for step in self._fields['steps_todo_to_process']:
253 def step_as_dict(node_id: int,
254 children: list[dict[str, object]],
255 process: int | None = None,
256 todo: int | None = None,
257 fillable: bool = False,
258 ) -> dict[str, object]:
259 """Return JSON of TodoOrProcStepsNode to expect."""
260 return {'node_id': node_id,
261 'children': children,
263 'fillable': fillable,
267 class TestsWithServer(TestCaseWithServer):
268 """Tests against our HTTP server/handler (and database)."""
271 self, id_: int, payload: dict[str, Any], exp: Expected) -> None:
272 self.check_post(payload, f'/todo?id={id_}')
273 exp.set_todo_from_post(id_, payload)
275 def test_basic_fail_POST_todo(self) -> None:
276 """Test basic malformed/illegal POST /todo requests."""
277 self.post_exp_process([], {}, 1)
278 # test we cannot just POST into non-existing Todo
279 self.check_post({}, '/todo', 404)
280 self.check_post({}, '/todo?id=FOO', 400)
281 self.check_post({}, '/todo?id=0', 404)
282 self.check_post({}, '/todo?id=1', 404)
283 # test malformed values on existing Todo
284 self.post_exp_day([], {'new_todo': [1]})
285 for name in ['adopt', 'effort', 'make_full', 'make_empty',
286 'conditions', 'disables', 'blockers', 'enables']:
287 self.check_post({name: 'x'}, '/todo?id=1', 400, '/todo')
288 for prefix in ['make_', '']:
289 for suffix in ['', 'x', '1.1']:
290 self.check_post({'step_filler_to_1': [f'{prefix}{suffix}']},
291 '/todo?id=1', 400, '/todo')
292 for suffix in ['', 'x', '1.1']:
293 self.check_post({'step_filler_to_{suffix}': ['1']},
294 '/todo?id=1', 400, '/todo')
296 def test_basic_POST_todo(self) -> None:
297 """Test basic POST /todo manipulations."""
298 exp = ExpectedGetTodo(1)
299 self.post_exp_process([exp], {'calendarize': 0}, 1)
300 self.post_exp_day([exp], {'new_todo': [1]})
301 # test posting naked entity at first changes nothing
302 self.check_json_get('/todo?id=1', exp)
303 self.check_post({}, '/todo?id=1')
304 self.check_json_get('/todo?id=1', exp)
305 # test posting doneness, comment, calendarization, effort
306 todo_post = {'is_done': 1, 'calendarize': 1,
307 'comment': 'foo', 'effort': 2.3}
308 self._post_exp_todo(1, todo_post, exp)
309 self.check_json_get('/todo?id=1', exp)
310 # test implicitly un-setting (only) comment by empty post
311 self.check_post({}, '/todo?id=1')
312 exp.lib_get('Todo', 1)['comment'] = ''
313 self.check_json_get('/todo?id=1', exp)
314 # test effort post can be explicitly unset by "effort":"" post
315 self.check_post({'effort': ''}, '/todo?id=1')
316 exp.lib_get('Todo', 1)['effort'] = None
317 self.check_json_get('/todo?id=1', exp)
318 # test Condition posts
319 c1_post = {'title': 'foo', 'description': 'oof', 'is_active': 0}
320 c2_post = {'title': 'bar', 'description': 'rab', 'is_active': 1}
321 self.post_exp_cond([exp], c1_post, 1)
322 self.post_exp_cond([exp], c2_post, 2)
323 self.check_json_get('/todo?id=1', exp)
324 todo_post = {'conditions': [1], 'disables': [1],
325 'blockers': [2], 'enables': [2]}
326 self._post_exp_todo(1, todo_post, exp)
327 self.check_json_get('/todo?id=1', exp)
329 def test_POST_todo_deletion(self) -> None:
330 """Test deletions via POST /todo."""
331 exp = ExpectedGetTodo(1)
332 self.post_exp_process([exp], {}, 1)
333 # test failure of deletion on non-existing Todo
334 self.check_post({'delete': ''}, '/todo?id=2', 404, '/')
335 # test deletion of existing Todo
336 self.post_exp_day([exp], {'new_todo': [1]})
337 self.check_post({'delete': ''}, '/todo?id=1', 302, '/')
338 self.check_get('/todo?id=1', 404)
339 exp.lib_del('Todo', 1)
340 # test deletion of adopted Todo
341 self.post_exp_day([exp], {'new_todo': [1]})
342 self.post_exp_day([exp], {'new_todo': [1]})
343 self.check_post({'adopt': 2}, '/todo?id=1')
344 self.check_post({'delete': ''}, '/todo?id=2', 302, '/')
345 exp.lib_del('Todo', 2)
346 self.check_get('/todo?id=2', 404)
347 self.check_json_get('/todo?id=1', exp)
348 # test deletion of adopting Todo
349 self.post_exp_day([exp], {'new_todo': [1]})
350 self.check_post({'adopt': 2}, '/todo?id=1')
351 self.check_post({'delete': ''}, '/todo?id=1', 302, '/')
353 exp.lib_del('Todo', 1)
354 self.check_json_get('/todo?id=2', exp)
355 # test cannot delete Todo with comment or effort
356 self.check_post({'comment': 'foo'}, '/todo?id=2')
357 self.check_post({'delete': ''}, '/todo?id=2', 500, '/')
358 self.check_post({'effort': 5}, '/todo?id=2')
359 self.check_post({'delete': ''}, '/todo?id=2', 500, '/')
360 # test deletion via effort < 0, but only if deletable
361 self.check_post({'effort': -1, 'comment': 'foo'}, '/todo?id=2')
362 self.check_post({}, '/todo?id=2')
363 self.check_get('/todo?id=2', 404)
365 def test_POST_todo_adoption(self) -> None:
366 """Test adoption via POST /todo with "adopt"."""
367 # post two Todos to Day, have first adopt second
368 exp = ExpectedGetTodo(1)
369 self.post_exp_process([exp], {}, 1)
370 self.post_exp_day([exp], {'new_todo': [1]})
371 self.post_exp_day([exp], {'new_todo': [1]})
372 self._post_exp_todo(1, {'adopt': 2}, exp)
373 exp.set('steps_todo_to_process', [exp.step_as_dict(1, [], todo=2)])
374 self.check_json_get('/todo?id=1', exp)
375 # test Todo un-adopting by just not sending an adopt
376 self._post_exp_todo(1, {}, exp)
377 exp.set('steps_todo_to_process', [])
378 self.check_json_get('/todo?id=1', exp)
379 # test fail on trying to adopt non-existing Todo
380 self.check_post({'adopt': 3}, '/todo?id=1', 404)
381 # test cannot self-adopt
382 self.check_post({'adopt': 1}, '/todo?id=1', 400)
383 # test cannot do 1-step circular adoption
384 self._post_exp_todo(2, {'adopt': 1}, exp)
385 self.check_post({'adopt': 2}, '/todo?id=1', 400)
386 # test cannot do 2-step circular adoption
387 self.post_exp_day([exp], {'new_todo': [1]})
388 self._post_exp_todo(3, {'adopt': 2}, exp)
389 self.check_post({'adopt': 3}, '/todo?id=1', 400)
390 # test can adopt Todo into ProcessStep chain via its Process (with key
391 # 'step_filler' equivalent to single-element 'adopt' if intable)
392 self.post_exp_process([exp], {}, 2)
393 self.post_exp_process([exp], {}, 3)
394 self.post_exp_process([exp], {'new_top_step': [2, 3]}, 1)
395 exp.lib_set('ProcessStep', [exp.procstep_as_dict(1, 1, 2),
396 exp.procstep_as_dict(2, 1, 3)])
397 step1_proc2 = exp.step_as_dict(1, [], 2, None, True)
398 step2_proc3 = exp.step_as_dict(2, [], 3, None, True)
399 exp.set('steps_todo_to_process', [step1_proc2, step2_proc3])
400 self.post_exp_day([exp], {'new_todo': [2]})
401 self.post_exp_day([exp], {'new_todo': [3]})
402 self.check_json_get('/todo?id=1', exp)
403 self._post_exp_todo(1, {'step_filler_to_1': 5, 'adopt': [4]}, exp)
404 exp.lib_get('Todo', 1)['children'] += [5]
405 step1_proc2 = exp.step_as_dict(1, [], 2, 4, True)
406 step2_proc3 = exp.step_as_dict(2, [], 3, 5, True)
407 exp.set('steps_todo_to_process', [step1_proc2, step2_proc3])
408 self.check_json_get('/todo?id=1', exp)
409 # test 'ignore' values for 'step_filler' are ignored, and intable
410 # 'step_filler' values are interchangeable with those of 'adopt'
411 todo_post = {'adopt': 5, 'step_filler_to_1': ['ignore', 4]}
412 self.check_post(todo_post, '/todo?id=1')
413 self.check_json_get('/todo?id=1', exp)
414 # test cannot adopt into non-top-level elements of chain, instead
415 # creating new top-level steps when adopting of respective Process
416 self.post_exp_process([exp], {}, 4)
417 self.post_exp_process([exp], {'new_top_step': 4, 'step_of': [1]}, 3)
418 exp.lib_set('ProcessStep', [exp.procstep_as_dict(3, 3, 4)])
419 step3_proc4 = exp.step_as_dict(3, [], 4, None, True)
420 step2_proc3 = exp.step_as_dict(2, [step3_proc4], 3, 5, True)
421 exp.set('steps_todo_to_process', [step1_proc2, step2_proc3])
422 self.post_exp_day([exp], {'new_todo': [4]})
423 self._post_exp_todo(1, {'adopt': [4, 5, 6]}, exp)
424 step4_todo6 = exp.step_as_dict(4, [], None, 6, False)
425 exp.set('steps_todo_to_process', [step1_proc2, step2_proc3,
427 self.check_json_get('/todo?id=1', exp)
429 def test_POST_todo_make_empty(self) -> None:
430 """Test creation via POST /todo "step_filler_to"/"make"."""
431 # create chain of Processes
432 exp = ExpectedGetTodo(1)
433 self.post_exp_process([exp], {}, 1)
434 for i in range(1, 4):
435 self.post_exp_process([exp], {'new_top_step': i}, i+1)
436 exp.lib_set('ProcessStep', [exp.procstep_as_dict(1, 2, 1),
437 exp.procstep_as_dict(2, 3, 2),
438 exp.procstep_as_dict(3, 4, 3)])
439 # post (childless) Todo of chain end, then make empty on next in line
440 self.post_exp_day([exp], {'new_todo': [4]})
441 step3_proc1 = exp.step_as_dict(3, [], 1)
442 step2_proc2 = exp.step_as_dict(2, [step3_proc1], 2)
443 step1_proc3 = exp.step_as_dict(1, [step2_proc2], 3, None, True)
444 exp.set('steps_todo_to_process', [step1_proc3])
445 self.check_json_get('/todo?id=1', exp)
446 self.check_post({'step_filler_to_1': 'make_3'}, '/todo?id=1')
447 exp.set_todo_from_post(2, {'process_id': 3})
448 exp.set_todo_from_post(1, {'process_id': 4, 'children': [2]})
449 step2_proc2 = exp.step_as_dict(2, [step3_proc1], 2, None, True)
450 step1_proc3 = exp.step_as_dict(1, [step2_proc2], 3, 2, True)
451 exp.set('steps_todo_to_process', [step1_proc3])
452 self.check_json_get('/todo?id=1', exp)
453 # make new top-level Todo without chain implied by its Process
454 self.check_post({'make_empty': 2, 'adopt': [2]}, '/todo?id=1')
455 exp.set_todo_from_post(3, {'process_id': 2})
456 exp.set_todo_from_post(1, {'process_id': 4, 'children': [2, 3]})
457 step4_todo3 = exp.step_as_dict(4, [], None, 3)
458 exp.set('steps_todo_to_process', [step1_proc3, step4_todo3])
459 self.check_json_get('/todo?id=1', exp)
460 # fail on trying to call make_empty on non-existing Process
461 self.check_post({'make_full': 5}, '/todo?id=1', 404)
463 def test_GET_todo(self) -> None:
464 """Test GET /todo response codes."""
465 # test malformed or illegal parameter values
466 self.check_get('/todo', 404)
467 self.check_get('/todo?id=', 404)
468 self.check_get('/todo?id=foo', 400)
469 self.check_get('/todo?id=0', 404)
470 self.check_get('/todo?id=2', 404)
471 # test all existing Processes are shown as available
472 exp = ExpectedGetTodo(1)
473 self.post_exp_process([exp], {}, 1)
474 self.post_exp_day([exp], {'new_todo': [1]})
475 self.post_exp_process([exp], {}, 2)
476 self.check_json_get('/todo?id=1', exp)
477 # test chain of Processes shown as potential step nodes
478 self.post_exp_process([exp], {}, 3)
479 self.post_exp_process([exp], {}, 4)
480 self.post_exp_process([exp], {'new_top_step': 2}, 1)
481 self.post_exp_process([exp], {'new_top_step': 3, 'step_of': [1]}, 2)
482 self.post_exp_process([exp], {'new_top_step': 4, 'step_of': [2]}, 3)
483 exp.lib_set('ProcessStep', [exp.procstep_as_dict(1, 1, 2, None),
484 exp.procstep_as_dict(2, 2, 3, None),
485 exp.procstep_as_dict(3, 3, 4, None)])
486 step3_proc4 = exp.step_as_dict(3, [], 4)
487 step2_proc3 = exp.step_as_dict(2, [step3_proc4], 3)
488 step1_proc2 = exp.step_as_dict(1, [step2_proc3], 2, fillable=True)
489 exp.set('steps_todo_to_process', [step1_proc2])
490 self.check_json_get('/todo?id=1', exp)
491 # test display of parallel chains
492 proc_steps_post = {'new_top_step': 4, 'kept_steps': [1, 3]}
493 self.post_exp_process([], proc_steps_post, 1)
494 step4_proc4 = exp.step_as_dict(4, [], 4, fillable=True)
495 exp.lib_set('ProcessStep', [exp.procstep_as_dict(4, 1, 4, None)])
496 exp.set('steps_todo_to_process', [step1_proc2, step4_proc4])
497 self.check_json_get('/todo?id=1', exp)
499 def test_POST_todo_doneness_relations(self) -> None:
500 """Test Todo.is_done Condition, adoption relations for /todo POSTs."""
501 self.post_exp_process([], {}, 1)
502 # test Todo with adoptee can only be set done if adoptee is done too
503 self.post_exp_day([], {'new_todo': [1]})
504 self.post_exp_day([], {'new_todo': [1]})
505 self.check_post({'adopt': 2, 'is_done': 1}, '/todo?id=1', 400)
506 self.check_post({'is_done': 1}, '/todo?id=2')
507 self.check_post({'adopt': 2, 'is_done': 1}, '/todo?id=1', 302)
508 # test Todo cannot be set undone with adopted Todo not done yet
509 self.check_post({'is_done': 0}, '/todo?id=2')
510 self.check_post({'adopt': 2, 'is_done': 0}, '/todo?id=1', 400)
511 # test unadoption relieves block
512 self.check_post({'is_done': 0}, '/todo?id=1', 302)
513 # test Condition being set or unset can block doneness setting
514 c1_post = {'title': '', 'description': '', 'is_active': 0}
515 c2_post = {'title': '', 'description': '', 'is_active': 1}
516 self.check_post(c1_post, '/condition', redir='/condition?id=1')
517 self.check_post(c2_post, '/condition', redir='/condition?id=2')
518 self.check_post({'conditions': [1], 'is_done': 1}, '/todo?id=1', 400)
519 self.check_post({'is_done': 1}, '/todo?id=1', 302)
520 self.check_post({'is_done': 0}, '/todo?id=1', 302)
521 self.check_post({'blockers': [2], 'is_done': 1}, '/todo?id=1', 400)
522 self.check_post({'is_done': 1}, '/todo?id=1', 302)
523 # test setting Todo doneness can set/un-set Conditions, but only on
524 # doneness change, not by mere passive state
525 self.check_post({'is_done': 0}, '/todo?id=2', 302)
526 self.check_post({'enables': [1], 'is_done': 1}, '/todo?id=1')
527 self.check_post({'conditions': [1], 'is_done': 1}, '/todo?id=2', 400)
528 self.check_post({'enables': [1], 'is_done': 0}, '/todo?id=1')
529 self.check_post({'enables': [1], 'is_done': 1}, '/todo?id=1')
530 self.check_post({'conditions': [1], 'is_done': 1}, '/todo?id=2')
531 self.check_post({'blockers': [1], 'is_done': 0}, '/todo?id=2', 400)
532 self.check_post({'disables': [1], 'is_done': 1}, '/todo?id=1')
533 self.check_post({'blockers': [1], 'is_done': 0}, '/todo?id=2', 400)
534 self.check_post({'disables': [1]}, '/todo?id=1')
535 self.check_post({'disables': [1], 'is_done': 1}, '/todo?id=1')
536 self.check_post({'blockers': [1]}, '/todo?id=2')