- 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)
+ @staticmethod
+ def day_dict(date: str) -> dict[str, object]:
+ """Return JSON of Process to expect."""
+ d: dict[str, object] = {'day': {'id': date,
+ 'comment': '',
+ 'todos': []},
+ 'top_nodes': [],
+ 'make_type': '',
+ 'enablers_for': {},
+ 'disablers_for': {},
+ 'conditions_present': [],
+ 'processes': []}
+ return d
+
+ def test_do_GET_day(self) -> None:
+ """Test GET /day basics."""
+ # check undefined day
+ date = date_in_n_days(0)
+ expected = self.day_dict(date)
+ self.check_json_get('/day', expected)
+ # check "today", "yesterday", "tomorrow" days
+ self.check_json_get('/day?date=today', expected)
+ expected = self.day_dict(date_in_n_days(1))
+ self.check_json_get('/day?date=tomorrow', expected)
+ expected = self.day_dict(date_in_n_days(-1))
+ self.check_json_get('/day?date=yesterday', expected)
+ # check wrong day strings
+ self.check_get('/day?date=foo', 400)
+ self.check_get('/day?date=2024-02-30', 400)
+ # check defined day
+ date = '2024-01-01'
+ expected = self.day_dict(date)
+ self.check_json_get(f'/day?date={date}', expected)
+ # check saved day
+ post_day = {'day_comment': 'foo', 'make_type': ''}
+ self.check_post(post_day, f'/day?date={date}', 302,
+ f'/day?date={date}&make_type=')
+ assert isinstance(expected['day'], dict)
+ expected['day']['comment'] = 'foo'
+ self.check_json_get(f'/day?date={date}', expected)
+ # check GET parameter POST not affecting reply to non-parameter GET
+ post_day['make_type'] = 'foo'
+ self.check_post(post_day, f'/day?date={date}', 302,
+ f'/day?date={date}&make_type=foo')
+ self.check_json_get(f'/day?date={date}', expected)
+ expected['make_type'] = 'bar'
+ self.check_json_get(f'/day?date={date}&make_type=bar', expected)
+
+ def test_do_GET(self) -> None:
+ """Test /day and /calendar response codes, and / redirect."""
+ 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)