From daa15449dd8fcae5df8b525dbaa323a7a07dc23a Mon Sep 17 00:00:00 2001 From: Brian Sutherland Date: Mon, 7 Mar 2011 11:16:56 +0000 Subject: [PATCH] Expose the application as a classmethod rather than a property. That way we don't need an instantiated layer to get the application --- src/zope/testbrowser/tests/test_wsgi.py | 2 +- src/zope/testbrowser/wsgi.py | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/zope/testbrowser/tests/test_wsgi.py b/src/zope/testbrowser/tests/test_wsgi.py index 4f5f803..288df1f 100644 --- a/src/zope/testbrowser/tests/test_wsgi.py +++ b/src/zope/testbrowser/tests/test_wsgi.py @@ -69,7 +69,7 @@ def test_layer(self): def test_app_property(self): # The layer has a .app property where the application under test is available - self.assertTrue(SIMPLE_LAYER.app is demo_app) + self.assertTrue(SIMPLE_LAYER.get_app() is demo_app) def test_there_can_only_be_one(self): another_layer = SimpleLayer() diff --git a/src/zope/testbrowser/wsgi.py b/src/zope/testbrowser/wsgi.py index 933ffcd..5e28cc5 100644 --- a/src/zope/testbrowser/wsgi.py +++ b/src/zope/testbrowser/wsgi.py @@ -161,14 +161,12 @@ class Browser(zope.testbrowser.browser.Browser): def __init__(self, url=None, wsgi_app=None): if wsgi_app is None: - wsgi_app = _APP_UNDER_TEST + wsgi_app = Layer.get_app() if wsgi_app is None: raise AssertionError("wsgi_app not provided or zope.testbrowser.wsgi.Layer not setup") mech_browser = WSGIMechanizeBrowser(wsgi_app) super(Browser, self).__init__(url=url, mech_browser=mech_browser) -_APP_UNDER_TEST = None # setup and torn down by the Layer class - # Compatibility helpers to behave like zope.app.testing basicre = re.compile('Basic (.+)?:(.+)?$') @@ -222,6 +220,9 @@ def application_start_response(status, headers, exc_info=None): for entry in self.wsgi_stack(environ, application_start_response): yield entry + +_APP_UNDER_TEST = None # setup and torn down by the Layer class + class Layer(object): """Test layer which sets up WSGI application for use with WebTest/testbrowser. @@ -231,8 +232,8 @@ class Layer(object): __bases__ = () __name__ = 'Layer' - @property - def app(self): + @classmethod + def get_app(cls): return _APP_UNDER_TEST def make_wsgi_app(self):