redir_to = f'{target}&make_type={form_data["make_type"]}'
self.check_post(form_data, target, status, redir_to)
- def test_do_GET_day_basics(self) -> None:
- """Test GET /day basics (no Todos)."""
- # check undefined day
- date = date_in_n_days(0)
- expected = self.GET_day_dict(date)
- self.check_json_get('/day', expected)
- # check "today", "yesterday", "tomorrow" days
- self.check_json_get('/day?date=today', expected)
- expected = self.GET_day_dict(date_in_n_days(1))
- self.check_json_get('/day?date=tomorrow', expected)
- expected = self.GET_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.GET_day_dict(date)
- assert isinstance(expected['_library'], dict)
- self.check_json_get(f'/day?date={date}', expected)
- # check saved day
- post: dict[str, object] = {'day_comment': 'foo', 'make_type': ''}
- self.post_day(f'date={date}', post)
- expected['_library']['Day'][date]['comment'] = post['day_comment']
- self.check_json_get(f'/day?date={date}', expected)
- # check GET parameter to GET requests affects immediate reply, but …
- expected['make_type'] = 'bar'
- self.check_json_get(f'/day?date={date}&make_type=bar', expected)
- # … not any following, …
- expected['make_type'] = ''
- self.check_json_get(f'/day?date={date}', expected)
- # … not even when part of a POST request
- post['make_type'] = 'foo'
- self.post_day(f'date={date}', post)
- self.check_json_get(f'/day?date={date}', expected)
-
@staticmethod
def post_batch(list_of_args: list[list[object]],
names_of_simples: list[str],
self.check_get('/calendar?start=2024-01-01&end=2025-01-01', 200)
self.check_get('/calendar?start=foo', 400)
+ def test_fail_GET_day(self) -> None:
+ """Test malformed/illegal GET /day requests."""
+ self.check_get('/day?date=foo', 400)
+ self.check_get('/day?date=2024-02-30', 400)
+
+ def test_basic_GET_day(self) -> None:
+ """Test basic (no Processes/Conditions/Todos) GET /day basics."""
+ # check undefined day
+ date = date_in_n_days(0)
+ expected = self.GET_day_dict(date)
+ self.check_json_get('/day', expected)
+ # NB: GET ?date="today"/"yesterday"/"tomorrow" in test_basic_POST_day
+ # check 'make_type' GET parameter affects immediate reply, but …
+ date = '2024-01-01'
+ expected = self.GET_day_dict(date)
+ expected['make_type'] = 'bar'
+ self.check_json_get(f'/day?date={date}&make_type=bar', expected)
+ # … not any following, …
+ expected['make_type'] = ''
+ self.check_json_get(f'/day?date={date}', expected)
+ # … not even when part of a POST request
+ post: dict[str, object] = {'day_comment': '', 'make_type': 'foo'}
+ self.post_day(f'date={date}', post)
+ self.check_json_get(f'/day?date={date}', expected)
+
def test_fail_POST_day(self) -> None:
- """Test malformed/illegal POST /condition requests."""
+ """Test malformed/illegal POST /day requests."""
# check payloads lacking minimum expecteds
url = '/day?date=2024-01-01'
self.check_post({}, url, 400)
self.check_post(post, '/day', 400)
self.check_post(post, '/day?date=', 400)
self.check_post(post, '/day?date=foo', 400)
+
+ def test_basic_POST_day(self) -> None:
+ """Test basic (no Todos) POST /day.
+
+ Check POST (& GET!) requests properly parse 'today', 'tomorrow',
+ 'yesterday', and actual date strings;
+ preserve 'make_type' setting in redirect even if nonsensical;
+ and store 'day_comment'
+ """
+ for name, dist, test_str in [('2024-01-01', None, 'a'),
+ ('today', 0, 'b'),
+ ('yesterday', -1, 'c'),
+ ('tomorrow', +1, 'd')]:
+ date = name if dist is None else date_in_n_days(dist)
+ post = {'day_comment': test_str, 'make_type': f'x:{test_str}'}
+ post_url = f'/day?date={name}'
+ redir_url = f'{post_url}&make_type={post["make_type"]}'
+ self.check_post(post, post_url, 302, redir_url)
+ expected = self.GET_day_dict(date)
+ assert isinstance(expected['_library'], dict)
+ expected['_library']['Day'][date]['comment'] = test_str
+ self.check_json_get(post_url, expected)