home · contact · privacy
Extend POST tests, and handling of missing form data.
[plomtask] / tests / days.py
index c6fdcc783db16bdd637d7944ced84ddfe19a2622..2850bb810c3af71e03a65e92e6f8f42d1768f6ad 100644 (file)
@@ -112,3 +112,19 @@ class TestsWithServer(TestCaseWithServer):
         response = self.conn.getresponse()
         self.assertEqual(response.status, 302)
         self.assertEqual(response.getheader('Location'), '/day')
+        self.conn.request('GET', '/foo')
+        self.assertEqual(self.conn.getresponse().status, 404)
+
+    def test_do_POST_day(self) -> None:
+        """Test POST /day."""
+        headers = {'Content-type': 'application/x-www-form-urlencoded'}
+        form_data = 'comment='
+        self.conn.request('POST', '/day', form_data, headers)
+        self.assertEqual(self.conn.getresponse().status, 400)
+        self.conn.request('POST', '/day?date=foo', form_data, headers)
+        self.assertEqual(self.conn.getresponse().status, 400)
+        self.conn.request('POST', '/day?date=2024-01-01', form_data, headers)
+        self.check_redirect('/')
+        form_data = 'foo='
+        self.conn.request('POST', '/day?date=2024-01-01', form_data, headers)
+        self.assertEqual(self.conn.getresponse().status, 400)