[Checkins] SVN: gocept.selenium/branches/janjaapdriessen-wsgi/ gocept.selenium.wsgi allows you to plug in a wsgi app for testing
Jan-Jaap Driessen
jdriessen at thehealthagency.com
Tue Nov 9 10:43:02 EST 2010
Log message for revision 118300:
gocept.selenium.wsgi allows you to plug in a wsgi app for testing
Changed:
A gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/
A gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/__init__.py
A gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/testing.py
A gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/tests.py
A gocept.selenium/branches/janjaapdriessen-wsgi/wsgi.cfg
-=-
Added: gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/__init__.py
===================================================================
--- gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/__init__.py (rev 0)
+++ gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/__init__.py 2010-11-09 15:43:01 UTC (rev 118300)
@@ -0,0 +1,61 @@
+#############################################################################
+#
+# Copyright (c) 2010 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+import os
+import time
+import urllib
+import unittest
+import threading
+from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
+
+import gocept.selenium.base
+import gocept.selenium.selenese
+
+
+class LogWSGIRequestHandler(WSGIRequestHandler):
+
+ # Add conditional logging to handler.
+ def log_request(self, *args):
+ if os.environ.has_key('GOCEPT_SELENIUM_VERBOSE_LOGGING'):
+ WSGIRequestHandler.log_request(self, *args)
+
+
+class WSGILayer(gocept.selenium.base.Layer):
+
+ def __init__(self, application=None, *bases):
+ super(WSGILayer, self).__init__(*bases)
+ self.application = application
+
+ def setUp(self):
+ super(WSGILayer, self).setUp()
+
+ self.http = WSGIServer((self.host, self.port), LogWSGIRequestHandler)
+ self.http.set_app(self.application)
+
+ self.thread = threading.Thread(target=self.http.serve_forever)
+ self.thread.start()
+
+ def tearDown(self):
+ self.http.shutdown()
+ self.thread.join()
+ # Make the server really go away and give up the socket:
+ self.http = None
+ super(WSGILayer, self).tearDown()
+
+
+class TestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.selenium = gocept.selenium.selenese.Selenese(
+ self.layer.selenium, self)
Added: gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/testing.py
===================================================================
--- gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/testing.py (rev 0)
+++ gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/testing.py 2010-11-09 15:43:01 UTC (rev 118300)
@@ -0,0 +1,42 @@
+#############################################################################
+#
+# Copyright (c) 2010 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+def simple_app(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
Added: gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/tests.py
===================================================================
--- gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/tests.py (rev 0)
+++ gocept.selenium/branches/janjaapdriessen-wsgi/src/gocept/selenium/wsgi/tests.py 2010-11-09 15:43:01 UTC (rev 118300)
@@ -0,0 +1,28 @@
+#############################################################################
+#
+# Copyright (c) 2010 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+import gocept.selenium.wsgi
+from gocept.selenium.wsgi.testing import simple_app
+
+class TestWSGITestCase(gocept.selenium.wsgi.TestCase):
+
+ layer = gocept.selenium.wsgi.WSGILayer(application=simple_app)
+
+ def test_wsgi_layer(self):
+ self.assertTrue(self.layer.thread.isAlive)
+
+ def test_simple_app(self):
+ self.selenium.open('/')
+ self.selenium.assertTextPresent('Hello from javascript')
+
Added: gocept.selenium/branches/janjaapdriessen-wsgi/wsgi.cfg
===================================================================
--- gocept.selenium/branches/janjaapdriessen-wsgi/wsgi.cfg (rev 0)
+++ gocept.selenium/branches/janjaapdriessen-wsgi/wsgi.cfg 2010-11-09 15:43:01 UTC (rev 118300)
@@ -0,0 +1,13 @@
+[buildout]
+parts = test
+versions = versions
+develop = .
+
+[versions]
+gocept.selenium =
+selenium = 1.0.3
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = gocept.selenium
+defaults = ['--ignore_dir', 'grok', '--ignore_dir', 'ztk', '--ignore_dir', 'zope2', '--ignore_dir', 'plone', '--ignore_dir', 'static', '-v', '-c']
More information about the checkins
mailing list