[Zope3-checkins] SVN: Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/publication/tests/test_ Updated a test to reflect new apis

Jim Fulton jim at zope.com
Fri Sep 2 19:37:06 EDT 2005


Log message for revision 38277:
  Updated a test to reflect new apis
  

Changed:
  U   Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/publication/tests/test_browserpublication.py
  U   Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/publication/tests/test_zopepublication.py

-=-
Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/publication/tests/test_browserpublication.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/publication/tests/test_browserpublication.py	2005-09-02 23:20:49 UTC (rev 38276)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/publication/tests/test_browserpublication.py	2005-09-02 23:37:06 UTC (rev 38277)
@@ -256,39 +256,19 @@
             id = 'bob'
 
         # With a normal request, we should get a body:
-        output = StringIO()
-        request = TestRequest(StringIO(''), output, {'PATH_INFO': '/'})
+        request = TestRequest(StringIO(''), {'PATH_INFO': '/'})
         request.setPrincipal(User())
-        request.response.setBody("spam")
+        request.response.setBody(u"spam")
         pub.afterCall(request, None)
-        request.response.outputBody()
-        self.assertEqual(
-            output.getvalue(),
-            'Status: 200 Ok\r\n'
-            'Content-Length: 4\r\n'
-            'Content-Type: text/plain;charset=utf-8\r\n'
-            'X-Content-Type-Warning: guessed from content\r\n'
-            'X-Powered-By: Zope (www.zope.org), Python (www.python.org)\r\n'
-            '\r\nspam'
-            )
+        self.assertEqual(request.response.testBody(), 'spam' )
 
         # But with a HEAD request, the body should be empty
-        output = StringIO()
-        request = TestRequest(StringIO(''), output, {'PATH_INFO': '/'})
+        request = TestRequest(StringIO(''), {'PATH_INFO': '/'})
         request.setPrincipal(User())
         request.method = 'HEAD'
-        request.response.setBody("spam")
+        request.response.setBody(u"spam")
         pub.afterCall(request, None)
-        request.response.outputBody()
-        self.assertEqual(
-            output.getvalue(),
-            'Status: 200 Ok\r\n'
-            'Content-Length: 0\r\n'
-            'Content-Type: text/plain;charset=utf-8\r\n'
-            'X-Content-Type-Warning: guessed from content\r\n'
-            'X-Powered-By: Zope (www.zope.org), Python (www.python.org)\r\n'
-            '\r\n'
-            )
+        self.assertEqual(request.response.testBody(), '')
 
     def testUnicode_NO_HTTP_CHARSET(self):
         # Test so that a unicode body doesn't cause a UnicodeEncodeError

Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/publication/tests/test_zopepublication.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/publication/tests/test_zopepublication.py	2005-09-02 23:20:49 UTC (rev 38276)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/publication/tests/test_zopepublication.py	2005-09-02 23:37:06 UTC (rev 38277)
@@ -327,21 +327,20 @@
         self.assertEqual(self.request, adapter.request)
 
     def testExceptionResetsResponse(self):
-        self.request._response = BrowserResponse(
-            self.request.response._outstream)
-        self.request.response.setHeader('Content-Type', 'application/pdf')
-        self.request.response.setCookie('spam', 'eggs')
+        from zope.publisher.browser import TestRequest
+        request = TestRequest()
+        request.response.setHeader('Content-Type', 'application/pdf')
+        request.response.setCookie('spam', 'eggs')
         from ZODB.POSException import ConflictError
         try:
             raise ConflictError
         except:
             pass
         self.publication.handleException(
-            self.object, self.request, sys.exc_info(), retry_allowed=False)
-        self.request.response.outputBody()
-        self.assertEqual(self.request.response.getHeader('Content-Type'),
+            self.object, request, sys.exc_info(), retry_allowed=False)
+        self.assertEqual(request.response.getHeader('Content-Type'),
                          'text/html;charset=utf-8')
-        self.assertEqual(self.request.response._cookies, {})
+        self.assertEqual(request.response._cookies, {})
 
     def testAbortOrCommitTransaction(self):
         txn = transaction.get()



More information about the Zope3-Checkins mailing list