home · contact · privacy
Extend POST tests, and handling of missing form data.
[plomtask] / tests / days.py
index 06e4302d71aaba58867e961506806a792c1fe807..2850bb810c3af71e03a65e92e6f8f42d1768f6ad 100644 (file)
@@ -91,7 +91,7 @@ class TestsWithServer(TestCaseWithServer):
     """Tests against our HTTP server/handler (and database)."""
 
     def test_do_GET(self) -> None:
-        """Test /day and /calendar response codes."""
+        """Test /day and /calendar response codes, and / redirect."""
         self.conn.request('GET', '/day')
         self.assertEqual(self.conn.getresponse().status, 200)
         self.conn.request('GET', '/day?date=3000-01-01')
@@ -108,3 +108,23 @@ class TestsWithServer(TestCaseWithServer):
         self.assertEqual(self.conn.getresponse().status, 200)
         self.conn.request('GET', '/calendar?start=foo')
         self.assertEqual(self.conn.getresponse().status, 400)
+        self.conn.request('GET', '/')
+        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)