[Checkins] SVN: zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/ Refactor test
Brian Sutherland
jinty at web.de
Wed Dec 15 11:40:43 EST 2010
Log message for revision 118936:
Refactor test
Changed:
U zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/README.txt
U zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/ftests/__init__.py
-=-
Modified: zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/README.txt
===================================================================
--- zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/README.txt 2010-12-15 16:12:56 UTC (rev 118935)
+++ zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/README.txt 2010-12-15 16:40:42 UTC (rev 118936)
@@ -1217,16 +1217,16 @@
Let's visit a page that echos it's request:
>>> browser.open('http://localhost/@@echo.html')
- >>> print browser.contents,
- HTTP_USER_AGENT: Python-urllib/2.4
+ >>> print browser.contents
+ HTTP_ACCEPT_LANGUAGE: en-US
HTTP_CONNECTION: close
HTTP_COOKIE:
- HTTP_ACCEPT_LANGUAGE: en-US
- REQUEST_METHOD: GET
HTTP_HOST: localhost
+ HTTP_USER_AGENT: Python-urllib/2.4
PATH_INFO: /@@echo.html
+ QUERY_STRING:
+ REQUEST_METHOD: GET
SERVER_PROTOCOL: HTTP/1.1
- QUERY_STRING:
Body: ''
Now, we'll try a post. The post method takes a URL, a data string,
@@ -1234,20 +1234,20 @@
a URL-encoded query string is assumed:
>>> browser.post('http://localhost/@@echo.html', 'x=1&y=2')
- >>> print browser.contents,
+ >>> print browser.contents
CONTENT_LENGTH: 7
- HTTP_USER_AGENT: Python-urllib/2.4
+ CONTENT_TYPE: application/x-www-form-urlencoded
+ HTTP_ACCEPT_LANGUAGE: en-US
HTTP_CONNECTION: close
HTTP_COOKIE:
- HTTP_ACCEPT_LANGUAGE: en-US
- y: 2
- REQUEST_METHOD: POST
HTTP_HOST: localhost
+ HTTP_USER_AGENT: Python-urllib/2.4
PATH_INFO: /@@echo.html
- CONTENT_TYPE: application/x-www-form-urlencoded
+ QUERY_STRING:
+ REQUEST_METHOD: POST
SERVER_PROTOCOL: HTTP/1.1
- QUERY_STRING:
x: 1
+ y: 2
Body: ''
@@ -1257,16 +1257,16 @@
>>> browser.post('http://localhost/@@echo.html',
... '{"x":1,"y":2}', 'application/x-javascipt')
- >>> print browser.contents,
+ >>> print browser.contents # doctest: +REPORT_NDIFF
CONTENT_LENGTH: 13
- HTTP_USER_AGENT: Python-urllib/2.4
+ CONTENT_TYPE: application/x-javascipt
+ HTTP_ACCEPT_LANGUAGE: en-US
HTTP_CONNECTION: close
HTTP_COOKIE:
- HTTP_ACCEPT_LANGUAGE: en-US
- REQUEST_METHOD: POST
HTTP_HOST: localhost
+ HTTP_USER_AGENT: Python-urllib/2.4
PATH_INFO: /@@echo.html
- CONTENT_TYPE: application/x-javascipt
+ REQUEST_METHOD: POST
SERVER_PROTOCOL: HTTP/1.1
Body: '{"x":1,"y":2}'
Modified: zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/ftests/__init__.py
===================================================================
--- zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/ftests/__init__.py 2010-12-15 16:12:56 UTC (rev 118935)
+++ zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/ftests/__init__.py 2010-12-15 16:40:42 UTC (rev 118936)
@@ -18,12 +18,31 @@
self.context = context
self.request = request
+_interesting_environ = ('CONTENT_LENGTH',
+ 'CONTENT_TYPE',
+ 'HTTP_ACCEPT_LANGUAGE',
+ 'HTTP_CONNECTION',
+ 'HTTP_COOKIE',
+ 'HTTP_HOST',
+ 'HTTP_USER_AGENT',
+ 'PATH_INFO',
+ 'QUERY_STRING',
+ 'REQUEST_METHOD',
+ 'SERVER_PROTOCOL')
+
class Echo(View):
- """Simply echo the contents of the request"""
+ """Simply echo the interesting parts of the request"""
def __call__(self):
- return ('\n'.join('%s: %s' % x for x in self.request.items()) +
- '\nBody: %r' % self.request.bodyStream.read())
+ items = []
+ for k in _interesting_environ:
+ v = self.request.get(k, None)
+ if v is None:
+ continue
+ items.append('%s: %s' % (k, v))
+ items.extend('%s: %s' % x for x in sorted(self.request.form.items()))
+ items.append('Body: %r' % self.request.bodyStream.read())
+ return '\n'.join(items)
class GetCookie(View):
"""Gets cookie value"""
More information about the checkins
mailing list