[Zope-Checkins] SVN: Zope/branches/tseaver-fix_wsgi/src/ZPublisher/ Coverage for __str__ (not complete).
Tres Seaver
tseaver at palladion.com
Mon Dec 21 23:45:51 EST 2009
Log message for revision 106845:
Coverage for __str__ (not complete).
Changed:
U Zope/branches/tseaver-fix_wsgi/src/ZPublisher/HTTPResponse.py
U Zope/branches/tseaver-fix_wsgi/src/ZPublisher/tests/testHTTPResponse.py
-=-
Modified: Zope/branches/tseaver-fix_wsgi/src/ZPublisher/HTTPResponse.py
===================================================================
--- Zope/branches/tseaver-fix_wsgi/src/ZPublisher/HTTPResponse.py 2009-12-22 04:01:11 UTC (rev 106844)
+++ Zope/branches/tseaver-fix_wsgi/src/ZPublisher/HTTPResponse.py 2009-12-22 04:45:49 UTC (rev 106845)
@@ -924,9 +924,9 @@
append = chunks.append
# status header must come first.
- append("Status: %s" % headers.get('status', '200 OK'))
+ append("Status: %s" % headers.get('status', '200 OK')) # WTF
append("X-Powered-By: Zope (www.zope.org), Python (www.python.org)")
- if headers.has_key('status'):
+ if headers.has_key('status'): # WTF
del headers['status']
for key, value in headers.items():
if key.lower() == key:
@@ -942,7 +942,8 @@
chunks.extend(self._cookie_list())
for key, value in self.accumulated_headers:
append("%s: %s" % (key, value))
- append(body) # WTF?
+ append('') # RFC 2616 mandates empty line between headers and payload
+ append(body)
return '\r\n'.join(chunks)
def write(self,data):
Modified: Zope/branches/tseaver-fix_wsgi/src/ZPublisher/tests/testHTTPResponse.py
===================================================================
--- Zope/branches/tseaver-fix_wsgi/src/ZPublisher/tests/testHTTPResponse.py 2009-12-22 04:01:11 UTC (rev 106844)
+++ Zope/branches/tseaver-fix_wsgi/src/ZPublisher/tests/testHTTPResponse.py 2009-12-22 04:45:49 UTC (rev 106845)
@@ -911,9 +911,113 @@
#TODO
- # def test_exception*
- # def test__cookie_list ?
- # def test___str__*
+ # def test_exception_* WAAAAAA!
+
+ #TODO
+ def test___str__empty(self):
+ response = self._makeOne()
+ result = str(response)
+ lines = result.split('\r\n')
+ self.assertEqual(len(lines), 5)
+ self.assertEqual(lines[0], 'Status: 200 OK')
+ self.assertEqual(lines[1], 'X-Powered-By: Zope (www.zope.org), '
+ 'Python (www.python.org)')
+ self.assertEqual(lines[2], 'Content-Length: 0')
+ self.assertEqual(lines[3], '')
+ self.assertEqual(lines[4], '')
+
+ def test___str__after_setHeader(self):
+ response = self._makeOne()
+ response.setHeader('X-Consistency', 'Foolish')
+ result = str(response)
+ lines = result.split('\r\n')
+ self.assertEqual(len(lines), 6)
+ self.assertEqual(lines[0], 'Status: 200 OK')
+ self.assertEqual(lines[1], 'X-Powered-By: Zope (www.zope.org), '
+ 'Python (www.python.org)')
+ self.assertEqual(lines[2], 'Content-Length: 0')
+ self.assertEqual(lines[3], 'X-Consistency: Foolish')
+ self.assertEqual(lines[4], '')
+ self.assertEqual(lines[5], '')
+
+ def test___str__after_redirect(self):
+ response = self._makeOne()
+ response.redirect('http://example.com/')
+ result = str(response)
+ lines = result.split('\r\n')
+ self.assertEqual(len(lines), 6)
+ self.assertEqual(lines[0], 'Status: 302 Moved Temporarily')
+ self.assertEqual(lines[1], 'X-Powered-By: Zope (www.zope.org), '
+ 'Python (www.python.org)')
+ self.assertEqual(lines[2], 'Content-Length: 0')
+ self.assertEqual(lines[3], 'Location: http://example.com/')
+ self.assertEqual(lines[4], '')
+ self.assertEqual(lines[5], '')
+
+ def test___str__after_setCookie_appendCookie(self):
+ response = self._makeOne()
+ response.setCookie('foo', 'bar', path='/')
+ response.appendCookie('foo', 'baz')
+ result = str(response)
+ lines = result.split('\r\n')
+ self.assertEqual(len(lines), 6)
+ self.assertEqual(lines[0], 'Status: 200 OK')
+ self.assertEqual(lines[1], 'X-Powered-By: Zope (www.zope.org), '
+ 'Python (www.python.org)')
+ self.assertEqual(lines[2], 'Content-Length: 0')
+ self.assertEqual(lines[3], 'Set-Cookie: foo="bar%3Abaz"; '
+ 'Path=/')
+ self.assertEqual(lines[4], '')
+ self.assertEqual(lines[5], '')
+
+ def test___str__after_expireCookie(self):
+ response = self._makeOne()
+ response.expireCookie('qux', path='/')
+ result = str(response)
+ lines = result.split('\r\n')
+ self.assertEqual(len(lines), 6)
+ self.assertEqual(lines[0], 'Status: 200 OK')
+ self.assertEqual(lines[1], 'X-Powered-By: Zope (www.zope.org), '
+ 'Python (www.python.org)')
+ self.assertEqual(lines[2], 'Content-Length: 0')
+ self.assertEqual(lines[3], 'Set-Cookie: qux="deleted"; '
+ 'Path=/; '
+ 'Expires=Wed, 31-Dec-97 23:59:59 GMT; '
+ 'Max-Age=0')
+ self.assertEqual(lines[4], '')
+ self.assertEqual(lines[5], '')
+
+ def test___str__after_addHeader(self):
+ response = self._makeOne()
+ response.addHeader('X-Consistency', 'Foolish')
+ response.addHeader('X-Consistency', 'Oatmeal')
+ result = str(response)
+ lines = result.split('\r\n')
+ self.assertEqual(len(lines), 7)
+ self.assertEqual(lines[0], 'Status: 200 OK')
+ self.assertEqual(lines[1], 'X-Powered-By: Zope (www.zope.org), '
+ 'Python (www.python.org)')
+ self.assertEqual(lines[2], 'Content-Length: 0')
+ self.assertEqual(lines[3], 'X-Consistency: Foolish')
+ self.assertEqual(lines[4], 'X-Consistency: Oatmeal')
+ self.assertEqual(lines[5], '')
+ self.assertEqual(lines[6], '')
+
+ def test___str__w_body(self):
+ response = self._makeOne()
+ response.setBody('BLAH')
+ result = str(response)
+ lines = result.split('\r\n')
+ self.assertEqual(len(lines), 6)
+ self.assertEqual(lines[0], 'Status: 200 OK')
+ self.assertEqual(lines[1], 'X-Powered-By: Zope (www.zope.org), '
+ 'Python (www.python.org)')
+ self.assertEqual(lines[2], 'Content-Length: 4')
+ self.assertEqual(lines[3],
+ 'Content-Type: text/plain; charset=iso-8859-15')
+ self.assertEqual(lines[4], '')
+ self.assertEqual(lines[5], 'BLAH')
+
# def test_write_already_wrote
# def test_write_not_already_wrote
More information about the Zope-Checkins
mailing list