From: Christian Heller Date: Fri, 21 Jun 2024 16:50:53 +0000 (+0200) Subject: Re-organize and extend POST/GET /day tests. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/tasks?a=commitdiff_plain;h=3c9bff1fcd9f67baa7a13256a1cf49cad085d54e;p=plomtask Re-organize and extend POST/GET /day tests. --- diff --git a/tests/conditions.py b/tests/conditions.py index 9fcb68c..bf04f7b 100644 --- a/tests/conditions.py +++ b/tests/conditions.py @@ -78,7 +78,7 @@ class TestsWithServer(TestCaseWithServer): self.check_post(valid_payload, '/condition?id=foo', 400) def test_do_POST_condition(self) -> None: - """Test POST /condition and its effect on GET /condition[s].""" + """Test (valid) POST /condition and its effect on GET /condition[s].""" # test valid POST's effect on … post = {'title': 'foo', 'description': 'oof', 'is_active': False} self.check_post(post, '/condition', 302, '/condition?id=1') diff --git a/tests/days.py b/tests/days.py index 52a3722..0b039bf 100644 --- a/tests/days.py +++ b/tests/days.py @@ -138,42 +138,6 @@ class TestsWithServer(TestCaseWithServer): 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], @@ -279,8 +243,33 @@ class TestsWithServer(TestCaseWithServer): 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) @@ -333,3 +322,25 @@ class TestsWithServer(TestCaseWithServer): 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)