From cd36bb2826a1c539a2f4673078f41334cc7432a3 Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Thu, 8 May 2025 08:52:08 -0400 Subject: [PATCH] test_pages updates This fixes issues with test_pages that I found while checking coverage. The environ dict was recycled across each call in the loop, but those calls can modify it, leaking data from one pass to another. Also, the mocking for _getServer was not placing the session in the environ, which was causing the tests to miss some cases. --- tests/test_www/data/pages_calls.json | 6 ++++++ tests/test_www/test_pages.py | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/tests/test_www/data/pages_calls.json b/tests/test_www/data/pages_calls.json index 911e8e07..49268e19 100644 --- a/tests/test_www/data/pages_calls.json +++ b/tests/test_www/data/pages_calls.json @@ -51057,6 +51057,12 @@ "method": "mavenEnabled", "result": true }, + { + "args": [], + "kwargs": {}, + "method": "winEnabled", + "result": true + }, { "args": [ 2 diff --git a/tests/test_www/test_pages.py b/tests/test_www/test_pages.py index 3ff9f1dd..612c8ba6 100644 --- a/tests/test_www/test_pages.py +++ b/tests/test_www/test_pages.py @@ -70,6 +70,8 @@ class TestPages(unittest.TestCase): self.time.return_value = 1735707600.0 def __get_server(env): + # this is replacing the call to _getServer + env['koji.session'] = self.server return self.server self.get_server.side_effect = __get_server @@ -186,12 +188,13 @@ class TestPages(unittest.TestCase): def prep_handler(self, method, query): """Takes method name and query string, returns handler and data""" # based loosely on publisher prep_handler - self.environ['QUERY_STRING'] = query - self.environ['koji.method'] = method - self.environ['SCRIPT_NAME'] = method + environ = self.environ.copy() + environ['QUERY_STRING'] = query + environ['koji.method'] = method + environ['SCRIPT_NAME'] = method handler = getattr(webidx, method) - fs = FieldStorageCompat(self.environ) - self.environ['koji.form'] = fs + fs = FieldStorageCompat(environ) + environ['koji.form'] = fs # even though we have curated urls, we need to filter args for some cases, e.g. search args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann = \ inspect.getfullargspec(handler) @@ -199,14 +202,14 @@ class TestPages(unittest.TestCase): data = dslice(fs.data, args, strict=False) else: data = fs.data.copy() - return handler, data + return handler, data, environ def test_web_handlers(self): """Test a bunch of web handlers""" for method, query in self.CALLS: - handler, data = self.prep_handler(method, query) + handler, data, environ = self.prep_handler(method, query) - result = handler(self.environ, **data) + result = handler(environ, **data) # result should be a string containing the rendered template self.assertIsInstance(result, str)