[Zope3-checkins]
SVN: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/
- implement .addHeaders
Benji York
benji at zope.com
Tue Aug 15 23:23:56 EDT 2006
Log message for revision 69555:
- implement .addHeaders
- comment out .headers tests (may not implement for real browsers)
- minor cleanup
Changed:
U Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/proxy.py
U Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.py
U Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.txt
-=-
Modified: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/proxy.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/proxy.py 2006-08-16 03:07:53 UTC (rev 69554)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/proxy.py 2006-08-16 03:23:56 UTC (rev 69555)
@@ -30,13 +30,12 @@
UNDEFINED = Constant('undefined')
class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
-# server_version = "TinyHTTPProxy/" + __version__
- rbufsize = 0
def __init__(self, request, client_address, server):
self.caller = functional.HTTPCaller()
self.command_queue = server.command_queue
self.result_queue = server.result_queue
+ self.additional_headers = server.additional_headers
BaseHTTPServer.BaseHTTPRequestHandler.__init__(
self, request, client_address, server)
@@ -119,7 +118,10 @@
urlparse.urlunparse(('', '', path, params, query, '')),
self.request_version))
- for key_val in self.headers.items():
+ headers = {}
+ headers.update(self.headers)
+ headers.update(self.additional_headers)
+ for key_val in headers.items():
request.write("%s: %s\r\n" % key_val)
request.write("\r\n")
response = self.caller(request.getvalue())
@@ -145,6 +147,7 @@
self.command_queue = Queue.Queue()
self.result_queue = Queue.Queue()
self.threads = []
+ self.additional_headers = {}
BaseHTTPServer.HTTPServer.__init__(self, *args, **kws)
self.setUp()
@@ -157,6 +160,9 @@
# in the thread that will eventually clean it up.
FunctionalTestSetup().getRootFolder()
+ def addHeader(self, key, value):
+ self.additional_headers[key] = value
+
def serve_forever(self):
"""Handle one request at a time until stopped."""
while not self.stop:
@@ -198,3 +204,6 @@
def executeCommand(self, command, *args):
self.server.command_queue.put( ('_tb_'+command, simplejson.dumps(args)) )
return self.server.result_queue.get()
+
+ def addHeader(self, key, value):
+ self.server.addHeader(key, value)
Modified: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.py 2006-08-16 03:07:53 UTC (rev 69554)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.py 2006-08-16 03:23:56 UTC (rev 69555)
@@ -151,7 +151,7 @@
def addHeader(self, key, value):
"""See zope.testbrowser.interfaces.IBrowser"""
- raise NotImplementedError
+ self.serverManager.addHeader(key, value)
def getLink(self, text=None, url=None, id=None, index=None):
"""See zope.testbrowser.interfaces.IBrowser"""
Modified: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.txt
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.txt 2006-08-16 03:07:53 UTC (rev 69554)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.txt 2006-08-16 03:23:56 UTC (rev 69555)
@@ -13,8 +13,14 @@
>>> browser.url
'http://localhost/@@/testbrowser/simple.html'
-<<<snip addHeader calls>>>
+The browser can send arbitrary headers; this is helpful for setting the
+"Authorization" header or a language value, so that your tests format values
+the way you expect in your tests, if you rely on zope.i18n locale-based
+formatting or a similar approach.
+ >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+ >>> browser.addHeader('Accept-Language', 'en-US')
+
An existing browser instance can also `open` web pages:
>>> browser.open('http://localhost/@@/testbrowser/simple.html')
@@ -113,33 +119,33 @@
# BrowserStateError: not viewing HTML
-Headers
--------
+#Headers
+#-------
+#
+#As you can see, the `contents` of the browser does not return any HTTP
+#headers. The headers are accessible via a separate attribute, which is an
+#``httplib.HTTPMessage`` instance (httplib is a part of Python's standard
+#library):
+#
+# >>> browser.open('http://localhost/@@/testbrowser/simple.html')
+# >>> browser.headers
+# <httplib.HTTPMessage instance...>
+#
+#The headers can be accessed as a string:
+#
+# >>> print browser.headers
+# Status: 200 Ok
+# Content-Length: ...
+# Content-Type: text/html;charset=utf-8
+# X-Content-Type-Warning: guessed from content
+# X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+#
+#Or as a mapping:
+#
+# >>> browser.headers['content-type']
+# 'text/html;charset=utf-8'
-As you can see, the `contents` of the browser does not return any HTTP
-headers. The headers are accessible via a separate attribute, which is an
-``httplib.HTTPMessage`` instance (httplib is a part of Python's standard
-library):
- >>> browser.open('http://localhost/@@/testbrowser/simple.html')
- >>> browser.headers
- <httplib.HTTPMessage instance...>
-
-The headers can be accessed as a string:
-
- >>> print browser.headers
- Status: 200 Ok
- Content-Length: ...
- Content-Type: text/html;charset=utf-8
- X-Content-Type-Warning: guessed from content
- X-Powered-By: Zope (www.zope.org), Python (www.python.org)
-
-Or as a mapping:
-
- >>> browser.headers['content-type']
- 'text/html;charset=utf-8'
-
-
Navigation and Link Objects
---------------------------
More information about the Zope3-Checkins
mailing list