X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;ds=sidebyside;f=tests%2Fdays.py;h=81dbcf58c0cf3d4215044809a3851017fbfa169e;hb=a4ca74f81ae42abe27cf6dbab7ef18c850db72c2;hp=2850bb810c3af71e03a65e92e6f8f42d1768f6ad;hpb=11c4e6fc42ab96a13b18e8195c264899e31dddf0;p=plomtask diff --git a/tests/days.py b/tests/days.py index 2850bb8..81dbcf5 100644 --- a/tests/days.py +++ b/tests/days.py @@ -92,39 +92,19 @@ class TestsWithServer(TestCaseWithServer): def test_do_GET(self) -> None: """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') - self.assertEqual(self.conn.getresponse().status, 200) - self.conn.request('GET', '/day?date=FOO') - self.assertEqual(self.conn.getresponse().status, 400) - self.conn.request('GET', '/calendar') - self.assertEqual(self.conn.getresponse().status, 200) - self.conn.request('GET', '/calendar?start=&end=') - self.assertEqual(self.conn.getresponse().status, 200) - self.conn.request('GET', '/calendar?start=today&end=today') - self.assertEqual(self.conn.getresponse().status, 200) - self.conn.request('GET', '/calendar?start=2024-01-01&end=2025-01-01') - 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) + self.check_get('/day', 200) + self.check_get('/day?date=3000-01-01', 200) + self.check_get('/day?date=FOO', 400) + self.check_get('/calendar', 200) + self.check_get('/calendar?start=&end=', 200) + self.check_get('/calendar?start=today&end=today', 200) + self.check_get('/calendar?start=2024-01-01&end=2025-01-01', 200) + self.check_get('/calendar?start=foo', 400) 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) + form_data = {'comment': ''} + self.check_post(form_data, '/day', 400) + self.check_post(form_data, '/day?date=foo', 400) + self.check_post(form_data, '/day?date=2024-01-01', 302, '/') + self.check_post({'foo': ''}, '/day?date=2024-01-01', 400)