[Zope3-checkins] SVN: Zope3/branches/benji-testbrowser-with-real-browsers/src/zope/testbrowser/ add a test layer that sets up a server on a known port

Benji York benji at zope.com
Sun Jun 4 23:34:03 EDT 2006


Log message for revision 68489:
  add a test layer that sets up a server on a known port
  

Changed:
  A   Zope3/branches/benji-testbrowser-with-real-browsers/src/zope/testbrowser/ftests/reallayer.py
  U   Zope3/branches/benji-testbrowser-with-real-browsers/src/zope/testbrowser/ftests/testdoc.py
  U   Zope3/branches/benji-testbrowser-with-real-browsers/src/zope/testbrowser/real.txt
  U   Zope3/branches/benji-testbrowser-with-real-browsers/src/zope/testbrowser/realproxy.py

-=-
Added: Zope3/branches/benji-testbrowser-with-real-browsers/src/zope/testbrowser/ftests/reallayer.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers/src/zope/testbrowser/ftests/reallayer.py	2006-06-04 17:22:57 UTC (rev 68488)
+++ Zope3/branches/benji-testbrowser-with-real-browsers/src/zope/testbrowser/ftests/reallayer.py	2006-06-05 03:34:01 UTC (rev 68489)
@@ -0,0 +1,38 @@
+from zope.app.server.main import setup, load_options, run
+import ThreadedAsync.LoopCallback
+import threading
+from zope.testbrowser.realproxy import TARGET_PORT
+
+class TestbrowserRealClass:
+
+    __bases__ = ()
+
+    def __init__(self):
+        self.__name__ = self.__class__.__name__[:-5]
+        self.__module__ = self.__class__.__module__
+
+    def setUp(self):
+        self.startZope()
+
+    def tearDown(self):
+        self.stopZope()
+
+    def startZope(self, fg=None):
+        """start Zope in a daemon thread"""
+        def go():
+            # force the server to run on a known port
+            args = ['-X', 'server/address=%s' % TARGET_PORT,
+                    '-X', 'site-definition=ftesting.zcml']
+            setup(load_options(args))
+            run()
+
+        self.zope_thread = threading.Thread(target=go)
+        self.zope_thread.setDaemon(True)
+        self.zope_thread.start()
+
+    def stopZope(self):
+        """tell Zope to stop and wait for it to do so"""
+        ThreadedAsync.LoopCallback.exit_status = 0
+        self.zope_thread.join()
+
+TestbrowserReal = TestbrowserRealClass()


Property changes on: Zope3/branches/benji-testbrowser-with-real-browsers/src/zope/testbrowser/ftests/reallayer.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: Zope3/branches/benji-testbrowser-with-real-browsers/src/zope/testbrowser/ftests/testdoc.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers/src/zope/testbrowser/ftests/testdoc.py	2006-06-04 17:22:57 UTC (rev 68488)
+++ Zope3/branches/benji-testbrowser-with-real-browsers/src/zope/testbrowser/ftests/testdoc.py	2006-06-05 03:34:01 UTC (rev 68489)
@@ -18,12 +18,14 @@
 import unittest
 import doctest
 from zope.app.testing.functional import FunctionalDocFileSuite
+from reallayer import TestbrowserReal
 
 def test_suite():
     flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
     readme = FunctionalDocFileSuite('../README.txt', optionflags=flags)
     real = doctest.DocFileSuite('../real.txt', optionflags=flags)
     real.level = 2
+    real.layer = TestbrowserReal
     wire = FunctionalDocFileSuite('../over_the_wire.txt', optionflags=flags)
     wire.level = 2
     return unittest.TestSuite((readme, wire, real))

Modified: Zope3/branches/benji-testbrowser-with-real-browsers/src/zope/testbrowser/real.txt
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers/src/zope/testbrowser/real.txt	2006-06-04 17:22:57 UTC (rev 68488)
+++ Zope3/branches/benji-testbrowser-with-real-browsers/src/zope/testbrowser/real.txt	2006-06-05 03:34:01 UTC (rev 68489)
@@ -8,12 +8,15 @@
     >>> from zope.testbrowser.real import Browser
     >>> browser = Browser()
 
-We can open pages.
+We can open pages and look at their contents.
 
     >>> browser.open('http://localhost/')
-    >>> browser.getLink('buddies')
-    <Link text='buddies' url=u'http://localhost:8000/buddies'>
+    >>> browser.contents
+    u'...</head>...'
 
+    >>> browser.getLink('[top]', index=0)
+    <Link text='[top]' url=u'http://localhost:23123/@@SelectedManagementView.html'>
+
 If a link doesn't exist, we get an exception.
 
     >>> browser.getLink('does not exist')
@@ -23,19 +26,13 @@
 
 Links can be clicked.
 
-    >>> browser.getLink('buddies').click()
+    >>> browser.getLink('[top]', index=0).click()
 
 We can retrieve the current address.
 
     >>> browser.url
-    u'http://localhost:8000/buddies'
+    u'http://localhost:23123/'
 
-We can also view the contents of the page.
-
-    >>> browser.getLink('brian').click()
-    >>> browser.contents
-    u'...</head>...'
-
 When we're done with the browser we have to close it.
 
     >>> browser.close()

Modified: Zope3/branches/benji-testbrowser-with-real-browsers/src/zope/testbrowser/realproxy.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers/src/zope/testbrowser/realproxy.py	2006-06-04 17:22:57 UTC (rev 68488)
+++ Zope3/branches/benji-testbrowser-with-real-browsers/src/zope/testbrowser/realproxy.py	2006-06-05 03:34:01 UTC (rev 68489)
@@ -12,8 +12,11 @@
 
 base_dir = os.path.dirname(__file__)
 allowed_resources = ['MochiKit', 'shim.js', 'commands.js', 'start.html']
-PROXY_PORT = 8000
 
+PROXY_PORT = 23123
+PROXY_HOST = '127.0.0.1'
+TARGET_PORT = 23124
+
 class Constant(object):
     def __init__(self, name):
         self.name = name
@@ -26,7 +29,7 @@
 class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
 #    server_version = "TinyHTTPProxy/" + __version__
     rbufsize = 0
-    remote_host = 'localhost:8080' # TODO needs to be configurable
+    remote_host = 'localhost:%d' % TARGET_PORT
 
     def __init__(self, request, client_address, server):
         self.command_queue = server.command_queue
@@ -195,8 +198,9 @@
 
 class ServerManager(object):
     def __init__(self):
+        self.host = PROXY_HOST
         self.port = PROXY_PORT
-        self.server = HttpServer(('127.0.0.1', self.port), RequestHandler)
+        self.server = HttpServer((self.host, self.port), RequestHandler)
 
     def start(self):
         self.server_thread = threading.Thread(
@@ -206,7 +210,7 @@
 
     def stop(self):
         self.executeCommand('stop')
-        conn = httplib.HTTPConnection('localhost:%d' % self.port)
+        conn = httplib.HTTPConnection('%s:%d' % (self.host, self.port))
         conn.request('NOOP', '/')
         conn.getresponse()
 



More information about the Zope3-Checkins mailing list