X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/add_free?a=blobdiff_plain;f=tests%2Fdays.py;h=2e2ef50cbe85ae6ff9fd01edd802417a7122598f;hb=63249f5d7cefb97574610848ca3473cb1f9687e2;hp=7cb0f4fa6c9da13e8064e7e51a8c40e7284c7375;hpb=36d71cd777259ad08da17aeb0b0ef05fc40156ca;p=plomtask diff --git a/tests/days.py b/tests/days.py index 7cb0f4f..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,31 +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.""" + 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)