X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/balance?a=blobdiff_plain;f=tests%2Fdays.py;h=2e2ef50cbe85ae6ff9fd01edd802417a7122598f;hb=aed1d5968abf97976db3725347fe4e7672c935e7;hp=2850bb810c3af71e03a65e92e6f8f42d1768f6ad;hpb=11c4e6fc42ab96a13b18e8195c264899e31dddf0;p=plomtask diff --git a/tests/days.py b/tests/days.py index 2850bb8..2e2ef50 100644 --- a/tests/days.py +++ b/tests/days.py @@ -33,7 +33,7 @@ class TestsSansDB(TestCase): class TestsWithDB(TestCaseWithDB): - """Days module tests not requiring DB setup.""" + """Tests requiring DB, but not server setup.""" def test_Day_by_date(self) -> None: """Test Day.by_date().""" @@ -86,45 +86,33 @@ class TestsWithDB(TestCaseWithDB): self.assertEqual(Day('2024-01-01').prev_date, '2023-12-31') self.assertEqual(Day('2023-02-28').next_date, '2023-03-01') + def test_Day_singularity(self) -> None: + """Test pointers made for single object keep pointing to it.""" + day = Day('2024-01-01') + day.save(self.db_conn) + retrieved_day = Day.by_date(self.db_conn, '2024-01-01') + day.comment = 'foo' + self.assertEqual(retrieved_day.comment, 'foo') + class TestsWithServer(TestCaseWithServer): """Tests against our HTTP server/handler (and database).""" 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)