day = Day.by_id(self.conn, date, create=True)
day.comment = self.form_data.get_str('comment')
day.save(self.conn)
+ existing_todos = Todo.by_date(self.conn, date)
for process_id in self.form_data.get_all_int('new_todo'):
process = Process.by_id(self.conn, process_id)
todo = Todo(None, process, False, day.date)
todo.save(self.conn)
+ for step in todo.process.explicit_steps:
+ for t in [t for t in existing_todos
+ if t.process.id_ == step.step_process_id]:
+ todo.add_child(t)
+ break
+ todo.save(self.conn)
def do_POST_todo(self) -> None:
"""Update Todo and its children."""
self.assertEqual(todo2.children, [])
self.assertEqual(todo2.parents, [])
+ def test_do_POST_day_todo_adoption(self) -> None:
+ """Test Todos posted to Day view may adopt existing Todos."""
+ form_data = {'title': '', 'description': '', 'effort': 1}
+ self.check_post(form_data, '/process', 302, '/')
+ form_data['new_top_step'] = 1
+ self.check_post(form_data, '/process', 302, '/')
+ form_data = {'comment': '', 'new_todo': 1}
+ self.check_post(form_data, '/day?date=2024-01-01', 302)
+ form_data = {'comment': '', 'new_todo': 2}
+ self.check_post(form_data, '/day?date=2024-01-01', 302)
+ todo1 = Todo.by_date(self.db_conn, '2024-01-01')[0]
+ todo2 = Todo.by_date(self.db_conn, '2024-01-01')[1]
+ self.assertEqual(todo1.children, [])
+ self.assertEqual(todo1.parents, [todo2])
+ self.assertEqual(todo2.children, [todo1])
+ self.assertEqual(todo2.parents, [])
+
def test_do_GET_todo(self) -> None:
"""Test GET /todo response codes."""
form_data = {'title': '', 'description': '', 'effort': 1}