Skip to content

Commit

Permalink
Expose the application as a classmethod rather than a property. That …
Browse files Browse the repository at this point in the history
…way we don't need an instantiated layer to get the application
  • Loading branch information
Brian Sutherland committed Mar 7, 2011
1 parent 43dc54e commit daa1544
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/zope/testbrowser/tests/test_wsgi.py
Expand Up @@ -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()
Expand Down
11 changes: 6 additions & 5 deletions src/zope/testbrowser/wsgi.py
Expand Up @@ -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 (.+)?:(.+)?$')
Expand Down Expand Up @@ -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.
Expand All @@ -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):
Expand Down

0 comments on commit daa1544

Please sign in to comment.