From: Christian Heller Date: Wed, 20 Mar 2024 01:37:20 +0000 (+0100) Subject: On GET /day with unknown (but valid) "?date=", create new Day. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/%7B%7Bdb.prefix%7D%7D/templates?a=commitdiff_plain;h=508024e09c84da4e11595e900586f3d7f79094d2;p=plomtask On GET /day with unknown (but valid) "?date=", create new Day. --- diff --git a/plomtask/http.py b/plomtask/http.py index 01a949e..be7affa 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -48,7 +48,7 @@ class TaskHandler(BaseHTTPRequestHandler): def do_GET_day(self, conn: DatabaseConnection, date: str): """Show single Day.""" - day = Day.by_date(conn, date) + day = Day.by_date(conn, date, create=True) return self.server.jinja.get_template('day.html').render(day=day) def do_POST(self): diff --git a/tests/test_days.py b/tests/test_days.py index 35380c6..04f667b 100644 --- a/tests/test_days.py +++ b/tests/test_days.py @@ -116,8 +116,9 @@ class TestsWithServer(TestsWithDB): """Test /day response.""" conn = HTTPConnection(*self.httpd.server_address) conn.request('GET', '/day') - response = conn.getresponse() - self.assertEqual(response.status, 200) + self.assertEqual(conn.getresponse().status, 200) + conn.request('GET', '/day?date=FOO') + self.assertEqual(conn.getresponse().status, 400) def tearDown(self): self.httpd.shutdown()