def do_POST_todo(self) -> str:
"""Update Todo and its children."""
id_ = self.params.get_int('id')
+ for _ in self.form_data.get_all_str('delete'):
+ todo = Todo .by_id(self.conn, id_)
+ todo.remove(self.conn)
+ return '/'
todo = Todo.by_id(self.conn, id_)
adopted_child_ids = self.form_data.get_all_int('adopt')
for child in todo.children:
[[c.id_] for c in self.enables])
db_conn.rewrite_relations('todo_disables', 'todo', self.id_,
[[c.id_] for c in self.disables])
+
+ def remove(self, db_conn: DatabaseConnection) -> None:
+ """Remove from DB, including relations."""
+ assert isinstance(self.id_, int)
+ for child in self.children:
+ self.remove_child(child)
+ for parent in self.parents:
+ parent.remove_child(self)
+ db_conn.delete_where('todo_conditions', 'todo', self.id_)
+ db_conn.delete_where('todo_enables', 'todo', self.id_)
+ db_conn.delete_where('todo_disables', 'todo', self.id_)
+ super().remove(db_conn)
retrieved_todo.is_done = False
self.assertEqual(todo.is_done, False)
+ def test_Todo_remove(self) -> None:
+ """Test removal."""
+ todo_1 = Todo(None, self.proc, False, self.date1)
+ todo_1.save(self.db_conn)
+ todo_0 = Todo(None, self.proc, False, self.date1)
+ todo_0.save(self.db_conn)
+ todo_0.add_child(todo_1)
+ todo_2 = Todo(None, self.proc, False, self.date1)
+ todo_2.save(self.db_conn)
+ todo_1.add_child(todo_2)
+ todo_1.remove(self.db_conn)
+ with self.assertRaises(NotFoundException):
+ Todo.by_id(self.db_conn, todo_1.id_)
+ self.assertEqual(todo_0.children, [])
+ self.assertEqual(todo_2.parents, [])
+
class TestsWithServer(TestCaseWithServer):
"""Tests against our HTTP server/handler (and database)."""
def test_do_POST_todo(self) -> None:
"""Test POST /todo."""
- def post_and_reload(form_data: dict[str, object],
- status: int = 302) -> Todo:
- self.check_post(form_data, '/todo?id=1', status)
+ def post_and_reload(form_data: dict[str, object], status: int = 302,
+ redir_url: str = '/todo?id=1') -> Todo:
+ self.check_post(form_data, '/todo?id=1', status, redir_url)
return Todo.by_date(self.db_conn, '2024-01-01')[0]
# test minimum
form_data = {'title': '', 'description': '', 'effort': 1}
self.assertEqual(todo1.parents, [])
self.assertEqual(todo2.children, [])
self.assertEqual(todo2.parents, [])
+ # test todo1 deletion
+ form_data = {'delete': ''}
+ todo1 = post_and_reload(form_data, 302, '/')
def test_do_POST_day_todo_adoption(self) -> None:
"""Test Todos posted to Day view may adopt existing Todos."""