- 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)
+ @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)