[Checkins] SVN: zc.selenium/branches/wosc-zope2/src/zc/selenium/ replaced zope-side results view with testrunner-side http server, so we can report results back even if zope is not running in the same process (zope2 requires its own process)
Wolfgang Schnerring
wosc at wosc.de
Wed Feb 18 04:19:24 EST 2009
Log message for revision 96683:
replaced zope-side results view with testrunner-side http server, so we can report results back even if zope is not running in the same process (zope2 requires its own process)
Changed:
U zc.selenium/branches/wosc-zope2/src/zc/selenium/configure.zcml
A zc.selenium/branches/wosc-zope2/src/zc/selenium/http.py
U zc.selenium/branches/wosc-zope2/src/zc/selenium/pytest.txt
U zc.selenium/branches/wosc-zope2/src/zc/selenium/results.pt
D zc.selenium/branches/wosc-zope2/src/zc/selenium/results.py
U zc.selenium/branches/wosc-zope2/src/zc/selenium/selenium.py
U zc.selenium/branches/wosc-zope2/src/zc/selenium/tests.py
-=-
Modified: zc.selenium/branches/wosc-zope2/src/zc/selenium/configure.zcml
===================================================================
--- zc.selenium/branches/wosc-zope2/src/zc/selenium/configure.zcml 2009-02-18 08:59:59 UTC (rev 96682)
+++ zc.selenium/branches/wosc-zope2/src/zc/selenium/configure.zcml 2009-02-18 09:19:24 UTC (rev 96683)
@@ -10,14 +10,6 @@
directory="resources"
/>
- <class class=".results.Results">
- <require
- permission="zope.Public"
- interface="zope.publisher.interfaces.IPublishTraverse"
- attributes="__call__"
- />
- </class>
-
<browser:page
for="*"
name="zc.selenium.suite"
@@ -28,13 +20,6 @@
<browser:page
for="*"
- name="zc.selenium.results"
- class=".results.Results"
- permission="zope.Public"
- />
-
- <browser:page
- for="*"
name="zc.selenium.db.push"
class=".dbs.PushDBs"
permission="zope.Public"
Added: zc.selenium/branches/wosc-zope2/src/zc/selenium/http.py
===================================================================
--- zc.selenium/branches/wosc-zope2/src/zc/selenium/http.py (rev 0)
+++ zc.selenium/branches/wosc-zope2/src/zc/selenium/http.py 2009-02-18 09:19:24 UTC (rev 96683)
@@ -0,0 +1,68 @@
+#############################################################################
+#
+# Copyright (c) 2009 Zope Corporation 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 cgi
+import errno
+import BaseHTTPServer
+import socket
+import threading
+import zc.selenium.selenium
+import zope.pagetemplate.pagetemplatefile
+
+class DictTemplateFile(zope.pagetemplate.pagetemplatefile.PageTemplateFile):
+ """A pagetemplate that accepts arbitrary keyword arguments."""
+
+ def pt_getContext(self, *args, **kw):
+ context = super(DictTemplateFile, self).pt_getContext(*args, **kw)
+ kw = args[1].copy()
+ if kw:
+ kw.pop('args', None)
+ kw.pop('options', None)
+ context.update(kw)
+ return context
+
+
+class QueuePOSTHandler(BaseHTTPServer.BaseHTTPRequestHandler):
+
+ template = DictTemplateFile('results.pt')
+
+ def do_POST(self):
+ form = cgi.FieldStorage(
+ fp=self.rfile,
+ headers=self.headers,
+ environ={'REQUEST_METHOD':'POST',
+ 'CONTENT_TYPE':self.headers['Content-Type'],
+ })
+ request = dict([(key, form.getvalue(key)) for key in form.keys()])
+ zc.selenium.selenium.messages.put(request)
+ self.send_response(200)
+ self.end_headers()
+ self.wfile.write(self.template(request=request))
+
+ def log_message(self, *args, **kw):
+ # be silent
+ pass
+
+
+class ServerThread(threading.Thread):
+
+ def __init__(self, port):
+ super(ServerThread, self).__init__()
+ self.setDaemon(True)
+ self.port = port
+
+ def run(self):
+ self.server = BaseHTTPServer.HTTPServer(('', self.port),
+ QueuePOSTHandler)
+ self.server.serve_forever()
Modified: zc.selenium/branches/wosc-zope2/src/zc/selenium/pytest.txt
===================================================================
--- zc.selenium/branches/wosc-zope2/src/zc/selenium/pytest.txt 2009-02-18 08:59:59 UTC (rev 96682)
+++ zc.selenium/branches/wosc-zope2/src/zc/selenium/pytest.txt 2009-02-18 09:19:24 UTC (rev 96683)
@@ -514,9 +514,11 @@
>>> from zope import interface
>>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer
>>> component.provideAdapter(Test,
- ... (interface.Interface, IDefaultBrowserLayer), name='first.html')
+ ... (interface.Interface, IDefaultBrowserLayer), name='first.html',
+ ... provides=zc.selenium.pytest.ISeleniumTest)
>>> component.provideAdapter(Second,
- ... (interface.Interface, IDefaultBrowserLayer), name='second.html')
+ ... (interface.Interface, IDefaultBrowserLayer), name='second.html',
+ ... provides=zc.selenium.pytest.ISeleniumTest)
The test suite used the zc.selenium.pytest.suite function to
compute rows for the test suite:
Modified: zc.selenium/branches/wosc-zope2/src/zc/selenium/results.pt
===================================================================
--- zc.selenium/branches/wosc-zope2/src/zc/selenium/results.pt 2009-02-18 08:59:59 UTC (rev 96682)
+++ zc.selenium/branches/wosc-zope2/src/zc/selenium/results.pt 2009-02-18 09:19:24 UTC (rev 96683)
@@ -7,12 +7,10 @@
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:tal="http://xml.zope.org/namespaces/tal"
- xmlns:i18n="http://xml.zope.org/namespaces/i18n"
xml:lang="en" lang="en"
- i18n:domain="zc.selenium"
>
<head>
- <title i18n:translate="">Selenium Results</title>
+ <title>Selenium Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
@@ -21,7 +19,7 @@
style="color: #0D0; font-weight: bold; font-size: 500%;
width: 100%; text-align: center; padding-top: 1em;"
>
- <i18n:span translate="">Passed!</i18n:span>
+ Passed!
<script language="Javascript1.1">
window.setTimeout("top.close()", 2000)
</script>
@@ -31,7 +29,7 @@
style="color: #F33; font-weight: bold; font-size: 500%;
width: 100%; text-align: center; padding-top: 1em;"
>
- <i18n:span translate="">Failed!</i18n:span>
+ Failed!
</div>
</body>
</html>
Deleted: zc.selenium/branches/wosc-zope2/src/zc/selenium/results.py
===================================================================
--- zc.selenium/branches/wosc-zope2/src/zc/selenium/results.py 2009-02-18 08:59:59 UTC (rev 96682)
+++ zc.selenium/branches/wosc-zope2/src/zc/selenium/results.py 2009-02-18 09:19:24 UTC (rev 96683)
@@ -1,31 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2005, 2006 Zope Corporation 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.
-#
-##############################################################################
-
-"""Result reporting resource for zc.selenium.
-"""
-
-import sys
-import zc.selenium.selenium
-import zope.app.pagetemplate
-
-
-class Results(object):
- """Transports test results from the browser to the selenium test runner"""
-
- template = zope.app.pagetemplate.ViewPageTemplateFile('results.pt')
-
- def __call__(self):
- if hasattr(zc.selenium.selenium, 'messages'):
- zc.selenium.selenium.messages.put(self.request)
- return self.template(self)
Modified: zc.selenium/branches/wosc-zope2/src/zc/selenium/selenium.py
===================================================================
--- zc.selenium/branches/wosc-zope2/src/zc/selenium/selenium.py 2009-02-18 08:59:59 UTC (rev 96682)
+++ zc.selenium/branches/wosc-zope2/src/zc/selenium/selenium.py 2009-02-18 09:19:24 UTC (rev 96683)
@@ -23,19 +23,23 @@
import sys
import threading
import time
+import urllib
import urllib2
import webbrowser
from zope.testing import testrunner
from zc.selenium.pytest import selectTestsToRun
+import zc.selenium.http
+
# Compute a default port; this is simple and doesn't ensure that the
# port is available, but does better than just hardcoding a port
# number. The goal is to avoid browser cache effects due to resource
# changes (especially in JavaScript resources).
#
DEFAULT_PORT = "8034"
+RESULTS_PORT = 39589
def run_zope3(config, port):
# This removes the script directory from sys.path, which we do
@@ -70,11 +74,11 @@
# wait for the server to start
old_timeout = socket.getdefaulttimeout()
socket.setdefaulttimeout(5)
- url = base_url % {'port': port}
- url += ('/++resource++selenium/TestRunner.html'
- '?test=%%2F@@zc.selenium.suite&'
- 'baseUrl=%s&'
- 'resultsUrl=%s/@@zc.selenium.results' % (url,url,))
+ base_url = base_url % {'port': port}
+ url = base_url + '/++resource++selenium/TestRunner.html?'
+ url += urllib.urlencode(
+ dict(test='/@@zc.selenium.suite', baseUrl=base_url,
+ resultsUrl='http://localhost:%s' % (RESULTS_PORT)))
time.sleep(1)
while zope_thread.isAlive():
try:
@@ -118,7 +122,7 @@
if exit_now:
return False
- if int(results['numTestPasses']) == 0:
+ if int(results['numTestPasses']) == int(results['numTestFailures']) == 0:
print
print "no tests were run"
print
@@ -218,6 +222,9 @@
if options.random_port:
options.port = random_port()
+ results_thread = zc.selenium.http.ServerThread(RESULTS_PORT)
+ results_thread.start()
+
selectTestsToRun(options.tests)
runner = globals()['run_' + options.runner]
Modified: zc.selenium/branches/wosc-zope2/src/zc/selenium/tests.py
===================================================================
--- zc.selenium/branches/wosc-zope2/src/zc/selenium/tests.py 2009-02-18 08:59:59 UTC (rev 96682)
+++ zc.selenium/branches/wosc-zope2/src/zc/selenium/tests.py 2009-02-18 09:19:24 UTC (rev 96683)
@@ -16,21 +16,43 @@
$Id: tests.py 12897 2006-07-26 20:11:41Z fred $
"""
+from zope.testing import doctest
+import Queue
+import time
import unittest
+import urllib
+import urllib2
+import zc.selenium.http
import zc.selenium.pytest
-from zope.testing import doctest
+import zc.selenium.selenium
class TestSelenium(zc.selenium.pytest.Test):
- """docstring."""
+ """Selenium self-test."""
def test_open(self):
self.selenium.open('http://%s/' % self.selenium.server)
- self.selenium.verifyTextPresent('Login')
+ self.selenium.verifyTextPresent('Zope')
+class HTTPTest(unittest.TestCase):
+
+ def test_request(self):
+ messages = zc.selenium.selenium.messages = Queue.Queue()
+ s = zc.selenium.http.ServerThread(39589)
+ s.start()
+ time.sleep(1)
+ params = dict(result='passed')
+ response = urllib2.urlopen('http://localhost:39589/',
+ urllib.urlencode(params))
+ self.assertNotEqual(-1, response.read().find('Passed!'))
+ self.assertEquals(params, messages.get(True))
+ self.assertRaises(Queue.Empty, lambda: messages.get(False))
+
+
def test_suite():
return unittest.TestSuite([
+ unittest.makeSuite(HTTPTest),
doctest.DocFileSuite('pytest.txt',
optionflags=doctest.ELLIPSIS|doctest.REPORT_NDIFF),
doctest.DocTestSuite('zc.selenium.pytest'),
More information about the Checkins
mailing list