From: Christian Heller Date: Mon, 29 Apr 2024 04:17:14 +0000 (+0200) Subject: Minor stylistic improvements to tests code. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bprefix%7D%7D/foo.html?a=commitdiff_plain;h=c6ad5c1fe2811225648a1d1c74c667ed38b7671e;p=plomtask Minor stylistic improvements to tests code. --- diff --git a/tests/processes.py b/tests/processes.py index 165f566..3d861b7 100644 --- a/tests/processes.py +++ b/tests/processes.py @@ -192,28 +192,21 @@ class TestsWithServer(TestCaseWithServer): form_data = self.post_process() self.assertEqual(1, len(Process.all(self.db_conn))) self.check_post(form_data, '/process?id=FOO', 400) - form_data['effort'] = 'foo' - self.check_post(form_data, '/process?id=', 400) + self.check_post(form_data | {'effort': 'foo'}, '/process?id=', 400) self.check_post({}, '/process?id=', 400) - form_data = {'title': '', 'description': ''} - self.check_post(form_data, '/process?id=', 400) - form_data = {'title': '', 'effort': 1.1} - self.check_post(form_data, '/process?id=', 400) - form_data = {'description': '', 'effort': 1.0} - self.check_post(form_data, '/process?id=', 400) + self.check_post({'title': '', 'description': ''}, '/process?id=', 400) + self.check_post({'title': '', 'effort': 1.1}, '/process?id=', 400) + self.check_post({'description': '', 'effort': 1.0}, + '/process?id=', 400) self.assertEqual(1, len(Process.all(self.db_conn))) - form_data = {'title': 'foo', 'description': 'foo', 'effort': 1.0, - 'condition': []} - self.post_process(2, form_data) - form_data['condition'] = [1] - self.check_post(form_data, '/process?id=', 404) - form_data_cond = {'title': 'foo', 'description': 'foo'} - self.check_post(form_data_cond, '/condition', 302, '/condition?id=1') - self.post_process(3, form_data) - form_data['disables'] = [1] - self.post_process(4, form_data) - form_data['enables'] = [1] - self.post_process(5, form_data) + form_data = {'title': 'foo', 'description': 'foo', 'effort': 1.0} + self.post_process(2, form_data | {'condition': []}) + self.check_post(form_data | {'condition': [1]}, '/process?id=', 404) + self.check_post({'title': 'foo', 'description': 'foo'}, + '/condition', 302, '/condition?id=1') + self.post_process(3, form_data | {'condition': [1]}) + self.post_process(4, form_data | {'disables': [1]}) + self.post_process(5, form_data | {'enables': [1]}) form_data['delete'] = '' self.check_post(form_data, '/process?id=', 404) self.check_post(form_data, '/process?id=6', 404) diff --git a/tests/todos.py b/tests/todos.py index c6b2878..a5dafd1 100644 --- a/tests/todos.py +++ b/tests/todos.py @@ -319,69 +319,58 @@ class TestsWithServer(TestCaseWithServer): return Todo.by_date(self.db_conn, '2024-01-01')[0] # test minimum self.post_process() - form_data = {'comment': '', 'new_todo': 1} - self.check_post(form_data, '/day?date=2024-01-01', 302) + self.check_post({'comment': '', 'new_todo': 1}, + '/day?date=2024-01-01', 302) # test posting to bad URLs - form_data = {} - self.check_post(form_data, '/todo=', 404) - self.check_post(form_data, '/todo?id=', 400) - self.check_post(form_data, '/todo?id=FOO', 400) - self.check_post(form_data, '/todo?id=0', 404) + self.check_post({}, '/todo=', 404) + self.check_post({}, '/todo?id=', 400) + self.check_post({}, '/todo?id=FOO', 400) + self.check_post({}, '/todo?id=0', 404) # test posting naked entity - todo1 = post_and_reload(form_data) + todo1 = post_and_reload({}) self.assertEqual(todo1.children, []) self.assertEqual(todo1.parents, []) self.assertEqual(todo1.is_done, False) # test posting doneness - form_data = {'done': ''} - todo1 = post_and_reload(form_data) + todo1 = post_and_reload({'done': ''}) self.assertEqual(todo1.is_done, True) # test implicitly posting non-doneness - form_data = {} - todo1 = post_and_reload(form_data) + todo1 = post_and_reload({}) self.assertEqual(todo1.is_done, False) # test malformed adoptions - form_data = {'adopt': 'foo'} - self.check_post(form_data, '/todo?id=1', 400) - form_data = {'adopt': 1} - self.check_post(form_data, '/todo?id=1', 400) - form_data = {'adopt': 2} - self.check_post(form_data, '/todo?id=1', 404) + self.check_post({'adopt': 'foo'}, '/todo?id=1', 400) + self.check_post({'adopt': 1}, '/todo?id=1', 400) + self.check_post({'adopt': 2}, '/todo?id=1', 404) # test posting second todo of same process - form_data = {'comment': '', 'new_todo': 1} - self.check_post(form_data, '/day?date=2024-01-01', 302) + self.check_post({'comment': '', 'new_todo': 1}, + '/day?date=2024-01-01', 302) # test todo 1 adopting todo 2 - form_data = {'adopt': 2} - todo1 = post_and_reload(form_data) + todo1 = post_and_reload({'adopt': 2}) todo2 = Todo.by_date(self.db_conn, '2024-01-01')[1] self.assertEqual(todo1.children, [todo2]) self.assertEqual(todo1.parents, []) self.assertEqual(todo2.children, []) self.assertEqual(todo2.parents, [todo1]) # test todo1 cannot be set done with todo2 not done yet - form_data = {'done': '', 'adopt': 2} - todo1 = post_and_reload(form_data, 400) + todo1 = post_and_reload({'done': '', 'adopt': 2}, 400) self.assertEqual(todo1.is_done, False) # test todo1 un-adopting todo 2 by just not sending an adopt - form_data = {} - todo1 = post_and_reload(form_data, 302) + todo1 = post_and_reload({}, 302) todo2 = Todo.by_date(self.db_conn, '2024-01-01')[1] self.assertEqual(todo1.children, []) self.assertEqual(todo1.parents, []) self.assertEqual(todo2.children, []) self.assertEqual(todo2.parents, []) # test todo1 deletion - form_data = {'delete': ''} - todo1 = post_and_reload(form_data, 302, '/') + todo1 = post_and_reload({'delete': ''}, 302, '/') def test_do_POST_day_todo_adoption(self) -> None: """Test Todos posted to Day view may adopt existing Todos.""" form_data = self.post_process() - form_data['new_top_step'] = 1 - form_data = self.post_process(2, form_data) + form_data = self.post_process(2, form_data | {'new_top_step': 1}) form_data = {'comment': '', 'new_todo': 1} self.check_post(form_data, '/day?date=2024-01-01', 302) - form_data = {'comment': '', 'new_todo': 2} + form_data['new_todo'] = 2 self.check_post(form_data, '/day?date=2024-01-01', 302) todo1 = Todo.by_date(self.db_conn, '2024-01-01')[0] todo2 = Todo.by_date(self.db_conn, '2024-01-01')[1]