[Checkins] SVN: gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/ Test app is now a class instead of a function. Use the sane base layer. Avoid super calls. Setup the wsgi stack in the wsgi layer.
Jan-Jaap Driessen
jdriessen at thehealthagency.com
Wed Dec 1 09:15:08 EST 2010
Log message for revision 118658:
Test app is now a class instead of a function. Use the sane base layer. Avoid super calls. Setup the wsgi stack in the wsgi layer.
Changed:
U gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/__init__.py
U gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/testing.py
U gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/tests.py
-=-
Modified: gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/__init__.py
===================================================================
--- gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/__init__.py 2010-12-01 14:13:50 UTC (rev 118657)
+++ gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/__init__.py 2010-12-01 14:15:08 UTC (rev 118658)
@@ -29,17 +29,18 @@
WSGIRequestHandler.log_request(self, *args)
-class WSGILayer(gocept.selenium.base.Layer):
+class WSGILayer(gocept.selenium.base.SaneLayer):
- def __init__(self, application=None, *bases):
- super(WSGILayer, self).__init__(*bases)
- self.application = application
+ application = None
+ def setup_wsgi_stack(self, app):
+ return app
+
def setUp(self):
- super(WSGILayer, self).setUp()
+ gocept.selenium.base.SaneLayer.setUp(self)
self.http = WSGIServer((self.host, self.port), LogWSGIRequestHandler)
- self.http.set_app(self.application)
+ self.http.set_app(self.setup_wsgi_stack(self.application))
self.thread = threading.Thread(target=self.http.serve_forever)
self.thread.daemon = True
@@ -50,7 +51,7 @@
self.thread.join()
# Make the server really go away and give up the socket:
self.http = None
- super(WSGILayer, self).tearDown()
+ gocept.selenium.base.SaneLayer.tearDown(self)
class TestCase(unittest.TestCase):
Modified: gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/testing.py
===================================================================
--- gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/testing.py 2010-12-01 14:13:50 UTC (rev 118657)
+++ gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/testing.py 2010-12-01 14:15:08 UTC (rev 118658)
@@ -13,32 +13,34 @@
##############################################################################
-def simple_app(environ, start_response):
- path = environ['PATH_INFO']
+class SimpleApp(object):
- statuscode = '404 Not Found'
- body = 'Not Found'
- headers = []
- if path == '/':
- statuscode = '200 OK'
- headers.append(('Content-Type', 'text/html'))
- body = '''
- <html>
- <head>
- <script src="colors.js"></script>
- </head>
- <body>
- <p id="foo">Testing...</p>
- </body>
- </html>'''
- elif path == '/colors.js':
- statuscode = '200 OK'
- headers.append(('Content-Type', 'text/javascript'))
- body = '''
- var hello = function hello () {
- document.getElementById('foo').innerHTML = 'Hello from javascript';
- };
- window.onload = hello;
- '''
- start_response(statuscode, headers)
- return body
+ def __call__(self, environ, start_response):
+ path = environ['PATH_INFO']
+
+ statuscode = '404 Not Found'
+ body = 'Not Found'
+ headers = []
+ if path == '/':
+ statuscode = '200 OK'
+ headers.append(('Content-Type', 'text/html'))
+ body = '''
+ <html>
+ <head>
+ <script src="colors.js"></script>
+ </head>
+ <body>
+ <p id="foo">Testing...</p>
+ </body>
+ </html>'''
+ elif path == '/colors.js':
+ statuscode = '200 OK'
+ headers.append(('Content-Type', 'text/javascript'))
+ body = '''
+ var hello = function hello () {
+ document.getElementById('foo').innerHTML = 'Hello from javascript';
+ };
+ window.onload = hello;
+ '''
+ start_response(statuscode, headers)
+ return body
Modified: gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/tests.py
===================================================================
--- gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/tests.py 2010-12-01 14:13:50 UTC (rev 118657)
+++ gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/tests.py 2010-12-01 14:15:08 UTC (rev 118658)
@@ -13,12 +13,16 @@
##############################################################################
import gocept.selenium.wsgi
-from gocept.selenium.wsgi.testing import simple_app
+from gocept.selenium.wsgi.testing import SimpleApp
+class TestLayer(gocept.selenium.wsgi.WSGILayer):
+ application = SimpleApp()
+test_layer = TestLayer()
+
class TestWSGITestCase(gocept.selenium.wsgi.TestCase):
- layer = gocept.selenium.wsgi.WSGILayer(application=simple_app)
+ layer = test_layer
def test_wsgi_layer(self):
self.assertTrue(self.layer.thread.isAlive)
More information about the checkins
mailing list