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, '/')
+ self.db_conn.cached_todos = {}
+ return Todo.by_date(self.db_conn, '2024-01-01')[0]
form_data = {'title': '', 'description': '', 'effort': 1}
self.check_post(form_data, '/process', 302, '/')
form_data = {'comment': '', 'new_todo': 1}
self.check_post(form_data, '/todo?id=', 404)
self.check_post(form_data, '/todo?id=FOO', 400)
self.check_post(form_data, '/todo?id=0', 404)
- self.check_post(form_data, '/todo?id=1', 302, '/')
- todo1 = Todo.by_date(self.db_conn, '2024-01-01')[0]
+ todo1 = post_and_reload(form_data)
self.assertEqual(todo1.children, [])
self.assertEqual(todo1.parents, [])
self.assertEqual(todo1.is_done, False)
form_data = {'done': ''}
- self.check_post(form_data, '/todo?id=1', 302, '/')
- self.db_conn.cached_todos = {}
- todo1 = Todo.by_date(self.db_conn, '2024-01-01')[0]
+ todo1 = post_and_reload(form_data)
self.assertEqual(todo1.is_done, True)
+ form_data = {}
+ todo1 = post_and_reload(form_data)
+ self.assertEqual(todo1.is_done, False)
form_data = {'adopt': 'foo'}
self.check_post(form_data, '/todo?id=1', 400)
form_data = {'adopt': 1}
form_data = {'comment': '', 'new_todo': 1}
self.check_post(form_data, '/day?date=2024-01-01', 302, '/')
form_data = {'adopt': 2}
- self.check_post(form_data, '/todo?id=1', 302, '/')
- self.db_conn.cached_todos = {}
- todo1 = Todo.by_date(self.db_conn, '2024-01-01')[0]
+ todo1 = post_and_reload(form_data)
todo2 = Todo.by_date(self.db_conn, '2024-01-01')[1]
self.assertEqual(todo1.children, [todo2])
self.assertEqual(todo1.parents, [])
self.assertEqual(todo2.children, [])
self.assertEqual(todo2.parents, [todo1])
self.check_post(form_data, '/todo?id=1', 400, '/')
+ form_data = {'done': ''}
+ todo1 = post_and_reload(form_data, 400)
+ self.assertEqual(todo1.is_done, False)
def test_do_GET_todo(self) -> None:
"""Test GET /todo response codes."""