- def test_do_GET(self):
- """Test /day and /calendar response codes."""
- http_conn = HTTPConnection(*self.httpd.server_address)
- http_conn.request('GET', '/day')
- self.assertEqual(http_conn.getresponse().status, 200)
- http_conn.request('GET', '/day?date=3000-01-01')
- self.assertEqual(http_conn.getresponse().status, 200)
- http_conn.request('GET', '/day?date=FOO')
- self.assertEqual(http_conn.getresponse().status, 400)
- http_conn.request('GET', '/calendar')
- self.assertEqual(http_conn.getresponse().status, 200)
- http_conn.request('GET', '/calendar?start=&end=')
- self.assertEqual(http_conn.getresponse().status, 200)
- http_conn.request('GET', '/calendar?start=today&end=today')
- self.assertEqual(http_conn.getresponse().status, 200)
- http_conn.request('GET', '/calendar?start=2024-01-01&end=2025-01-01')
- self.assertEqual(http_conn.getresponse().status, 200)
- http_conn.request('GET', '/calendar?start=foo')
- self.assertEqual(http_conn.getresponse().status, 400)
+ def test_get_json(self) -> None:
+ """Test /day for JSON response."""
+ self.conn.request('GET', '/day?date=2024-01-01')
+ response = self.conn.getresponse()
+ self.assertEqual(response.status, 200)
+ expected = {'day': {'id': '2024-01-01',
+ 'comment': '',
+ 'todos': []},
+ 'top_nodes': [],
+ 'make_type': '',
+ 'enablers_for': {},
+ 'disablers_for': {},
+ 'conditions_present': [],
+ 'processes': []}
+ retrieved = json_loads(response.read().decode())
+ self.assertEqual(expected, retrieved)
+
+ def test_do_GET(self) -> None:
+ """Test /day and /calendar response codes, and / redirect."""
+ 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 = {'day_comment': '', 'make_type': 'full'}
+ 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&make_type=full', 302)
+ self.check_post({'foo': ''}, '/day?date=2024-01-01', 400)