Log message for revision 113396:
  Qui custodiet custodiens?

Changed:
  U   Zope/branches/2.12/src/Testing/ZopeTestCase/zopedoctest/functional.py
  U   
Zope/branches/2.12/src/Testing/ZopeTestCase/zopedoctest/testFunctionalDocTest.py

-=-
Modified: Zope/branches/2.12/src/Testing/ZopeTestCase/zopedoctest/functional.py
===================================================================
--- Zope/branches/2.12/src/Testing/ZopeTestCase/zopedoctest/functional.py       
2010-06-12 13:36:25 UTC (rev 113395)
+++ Zope/branches/2.12/src/Testing/ZopeTestCase/zopedoctest/functional.py       
2010-06-12 14:15:49 UTC (rev 113396)
@@ -39,6 +39,8 @@
 class HTTPHeaderOutput:
 
     # zope.interface.implements(zope.server.interfaces.IHeaderOutput)
+    status = '200'
+    reason = 'OK'
 
     def __init__(self, protocol, omit):
         self.headers = {}
@@ -57,7 +59,10 @@
         ))
 
     def appendResponseHeaders(self, lst):
-        headers = [split_header(header) for header in lst]
+        if lst and isinstance(lst[0], basestring):
+            headers = [split_header(header) for header in lst]
+        else:
+            headers = lst
         self.headersl.extend(
             [('-'.join([s.capitalize() for s in name.split('-')]), v)
              for name, v in headers

Modified: 
Zope/branches/2.12/src/Testing/ZopeTestCase/zopedoctest/testFunctionalDocTest.py
===================================================================
--- 
Zope/branches/2.12/src/Testing/ZopeTestCase/zopedoctest/testFunctionalDocTest.py
    2010-06-12 13:36:25 UTC (rev 113395)
+++ 
Zope/branches/2.12/src/Testing/ZopeTestCase/zopedoctest/testFunctionalDocTest.py
    2010-06-12 14:15:49 UTC (rev 113396)
@@ -11,18 +11,86 @@
 #
 ##############################################################################
 """Example functional doctest
-
-$Id$
 """
+import unittest
 
-from unittest import TestSuite
 from Testing.ZopeTestCase import installProduct
 from Testing.ZopeTestCase import FunctionalDocTestSuite
 from Testing.ZopeTestCase import FunctionalDocFileSuite
 
 installProduct('PythonScripts')
 
+class HTTPHeaderOutputTests(unittest.TestCase):
 
+    def _getTargetClass(self):
+        from Testing.ZopeTestCase.zopedoctest.functional \
+            import HTTPHeaderOutput
+        return HTTPHeaderOutput
+
+    def _makeOne(self, protocol, omit):
+        return self._getTargetClass()(protocol, omit)
+
+    def test_ctor(self):
+        hho = self._makeOne('HTTP/1.0', ())
+        self.assertEqual(hho.protocol, 'HTTP/1.0')
+        self.assertEqual(hho.omit, ())
+        self.assertEqual(hho.status, '200')
+        self.assertEqual(hho.reason, 'OK')
+        self.assertEqual(hho.headers, {})
+        self.assertEqual(hho.headersl, [])
+
+    def test_setResponseStatus(self):
+        hho = self._makeOne('HTTP/1.0', ())
+        hho.setResponseStatus('401', 'Unautnorized')
+        self.assertEqual(hho.status, '401')
+        self.assertEqual(hho.reason, 'Unautnorized')
+
+    def test_setResponseHeaders_no_omit(self):
+        hho = self._makeOne('HTTP/1.0', ())
+        hho.setResponseHeaders({'Content-Type': 'text/html'})
+        self.assertEqual(hho.headers, {'Content-Type': 'text/html'})
+        self.assertEqual(hho.headersl, [])
+
+    def test_setResponseHeaders_w_omit(self):
+        hho = self._makeOne('HTTP/1.0', ('content-type',))
+        hho.setResponseHeaders({'Content-Type': 'text/html'})
+        self.assertEqual(hho.headers, {})
+        self.assertEqual(hho.headersl, [])
+
+    def test_appendResponseHeaders_no_omit_tuples(self):
+        hho = self._makeOne('HTTP/1.0', ())
+        hho.appendResponseHeaders([('Content-Type', 'text/html')])
+        self.assertEqual(hho.headers, {})
+        self.assertEqual(hho.headersl, [('Content-Type', 'text/html')])
+
+    def test_appendResponseHeaders_no_omit_strings(self):
+        # Some Zope versions passed around headers as lists of strings.
+        hho = self._makeOne('HTTP/1.0', ())
+        hho.appendResponseHeaders([('Content-Type: text/html')])
+        self.assertEqual(hho.headers, {})
+        self.assertEqual(hho.headersl, [('Content-Type', 'text/html')])
+
+    def test_appendResponseHeaders_w_omit(self):
+        hho = self._makeOne('HTTP/1.0', ('content-type',))
+        hho.appendResponseHeaders([('Content-Type', 'text/html')])
+        self.assertEqual(hho.headers, {})
+        self.assertEqual(hho.headersl, [])
+
+    def test___str___no_headers(self):
+        hho = self._makeOne('HTTP/1.0', ('content-type',))
+        self.assertEqual(str(hho), 'HTTP/1.0 200 OK')
+
+    def test___str___w_headers(self):
+        hho = self._makeOne('HTTP/1.0', ('content-type',))
+        hho.headers['Content-Type'] = 'text/html'
+        hho.headersl.append(('Content-Length', '23'))
+        self.assertEqual(str(hho),
+                         'HTTP/1.0 200 OK\n'
+                         'Content-Length: 23\n'
+                         'Content-Type: text/html'
+                        )
+
+
 def setUp(self):
     '''This method will run after the test_class' setUp.
 
@@ -58,7 +126,8 @@
 
 
 def test_suite():
-    return TestSuite((
+    return unittest.TestSuite((
+        unittest.makeSuite(HTTPHeaderOutputTests),
         FunctionalDocTestSuite(setUp=setUp),
         FunctionalDocFileSuite('FunctionalDocTest.txt', setUp=setUp),
     ))

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
https://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to