todos: list[dict[str, object]],
processes: list[dict[str, object]],
process_steps: list[dict[str, object]] | None = None,
+ conditions: list[dict[str, object]] | None = None
) -> dict[str, object]:
"""Return JSON of GET /todo to expect."""
+ # pylint: disable=too-many-arguments
library = {'Todo': cls.as_refs(todos),
'Process': cls.as_refs(processes)}
if process_steps:
library['ProcessStep'] = cls.as_refs(process_steps)
+ conditions = conditions if conditions else []
+ if conditions:
+ library['Condition'] = cls.as_refs(conditions)
return {'todo': target_id,
'steps_todo_to_process': [],
'adoption_candidates_for': {},
'process_candidates': [p['id'] for p in processes],
- 'todo_candidates': [],
- 'condition_candidates': [],
+ 'todo_candidates': [t['id'] for t in todos
+ if t['id'] != target_id],
+ 'condition_candidates': [c['id'] for c in conditions],
'_library': library}
@staticmethod
self.check_post({'effort': ''}, '/todo?id=1')
todo_dict['effort'] = None
self.check_json_get('/todo?id=1', expected)
+ # test Condition posts
+ c1_post = {'title': 'foo', 'description': 'oof', 'is_active': False}
+ c2_post = {'title': 'bar', 'description': 'rab', 'is_active': True}
+ self.check_post(c1_post, '/condition', redir='/condition?id=1')
+ self.check_post(c2_post, '/condition', redir='/condition?id=2')
+ c1_dict = self.cond_as_dict(1, False, ['foo'], ['oof'])
+ c2_dict = self.cond_as_dict(2, True, ['bar'], ['rab'])
+ conditions = [c1_dict, c2_dict]
+ todo_post = {'conditions': [1], 'disables': [1],
+ 'blockers': [2], 'enables': [2]}
+ for k, v in todo_post.items():
+ todo_dict[k] = v
+ self.check_post(todo_post, '/todo?id=1')
+ expected = self.GET_todo_dict(1, [todo_dict], [proc_dict],
+ conditions=conditions)
+ self.check_json_get('/todo?id=1', expected)
def test_POST_todo_deletion(self) -> None:
"""Test deletions via POST /todo."""
todo2_dict = self.todo_as_dict(2, process_id=1, parents=[1])
todos = [todo1_dict, todo2_dict]
expected = self.GET_todo_dict(1, todos, [proc1_dict])
- expected['todo_candidates'] = [2]
expected['steps_todo_to_process'] = [self._step_as_dict(1, [], todo=2)]
self.check_post({'adopt': 2}, '/todo?id=1')
self.check_json_get('/todo?id=1', expected)
step_proc2 = self._step_as_dict(1, [], 2, 4, True)
step_proc3 = self._step_as_dict(2, [], 3, 5, True)
expected['steps_todo_to_process'] = [step_proc2, step_proc3]
- expected['todo_candidates'] = [2, 3, 4, 5]
self.check_json_get('/todo?id=1', expected)
# test cannot adopt into non-top-level elements of chain
self.post_process(4, proc_post)
expected['steps_todo_to_process'] = [step_proc2, step_proc3,
step2_proc4]
expected['adoption_candidates_for'] = {'4': [6]}
- expected['todo_candidates'] = [2, 3, 4, 5, 6]
self.check_json_get('/todo?id=1', expected)
def test_POST_todo_make_full(self) -> None:
step_proc2 = self._step_as_dict(2, [step_proc1], 2, 3, True)
step_proc3 = self._step_as_dict(1, [step_proc2], 3, 2, True)
expected['steps_todo_to_process'] = [step_proc3]
- expected['todo_candidates'] = [2, 3, 4]
self.check_post({'step_filler': 'make_full_3'}, '/todo?id=1')
self.check_json_get('/todo?id=1', expected)
# make new chain next to expected, find steps_todo_to_process extended,
step2_proc1 = self._step_as_dict(5, [], None, 4)
step2_proc2 = self._step_as_dict(4, [step2_proc1], None, 5)
expected = self.GET_todo_dict(1, todos, procs, procsteps)
- expected['todo_candidates'] = [2, 3, 4, 5]
expected['steps_todo_to_process'] = [step_proc3, step2_proc2]
self.check_json_get('/todo?id=1', expected)
+ # fail on trying to call make_full on non-existing Process
+ self.check_post({'make_full': 5}, '/todo?id=1', 404)
def test_POST_todo_make_empty(self) -> None:
"""Test creation and adoption via POST /todo with "make_empty"."""
step_proc2 = self._step_as_dict(2, [step_proc1], 2, None, True)
step_proc3 = self._step_as_dict(1, [step_proc2], 3, 2, True)
expected['steps_todo_to_process'] = [step_proc3]
- expected['todo_candidates'] = [2]
expected['adoption_candidates_for'] = {'1': [], '2': []}
self.check_post({'step_filler': 'make_empty_3'}, '/todo?id=1')
self.check_json_get('/todo?id=1', expected)
todos += [todo3_dict]
step2_proc2 = self._step_as_dict(4, [], None, 3)
expected = self.GET_todo_dict(1, todos, procs, procsteps)
- expected['todo_candidates'] = [2, 3]
expected['steps_todo_to_process'] = [step_proc3, step2_proc2]
expected['adoption_candidates_for'] = {'1': [], '2': [3]}
self.check_json_get('/todo?id=1', expected)
+ # fail on trying to call make_empty on non-existing Process
+ self.check_post({'make_full': 5}, '/todo?id=1', 404)
def test_do_GET_todo(self) -> None:
"""Test GET /todo response codes."""