X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/balance?a=blobdiff_plain;f=tests%2Fdays.py;h=2850bb810c3af71e03a65e92e6f8f42d1768f6ad;hb=11c4e6fc42ab96a13b18e8195c264899e31dddf0;hp=06e4302d71aaba58867e961506806a792c1fe807;hpb=be5fe79322159cee339baa7919e38774298ebd95;p=plomtask diff --git a/tests/days.py b/tests/days.py index 06e4302..2850bb8 100644 --- a/tests/days.py +++ b/tests/days.py @@ -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)