Commit ac81f0db authored by Tres Seaver's avatar Tres Seaver

Qui custodiet custodiens?

parent bae502cb
...@@ -39,6 +39,8 @@ from Testing.ZopeTestCase.functional import savestate ...@@ -39,6 +39,8 @@ from Testing.ZopeTestCase.functional import savestate
class HTTPHeaderOutput: class HTTPHeaderOutput:
# zope.interface.implements(zope.server.interfaces.IHeaderOutput) # zope.interface.implements(zope.server.interfaces.IHeaderOutput)
status = '200'
reason = 'OK'
def __init__(self, protocol, omit): def __init__(self, protocol, omit):
self.headers = {} self.headers = {}
...@@ -57,7 +59,10 @@ class HTTPHeaderOutput: ...@@ -57,7 +59,10 @@ class HTTPHeaderOutput:
)) ))
def appendResponseHeaders(self, lst): 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( self.headersl.extend(
[('-'.join([s.capitalize() for s in name.split('-')]), v) [('-'.join([s.capitalize() for s in name.split('-')]), v)
for name, v in headers for name, v in headers
......
...@@ -11,17 +11,85 @@ ...@@ -11,17 +11,85 @@
# #
############################################################################## ##############################################################################
"""Example functional doctest """Example functional doctest
$Id$
""" """
import unittest
from unittest import TestSuite
from Testing.ZopeTestCase import installProduct from Testing.ZopeTestCase import installProduct
from Testing.ZopeTestCase import FunctionalDocTestSuite from Testing.ZopeTestCase import FunctionalDocTestSuite
from Testing.ZopeTestCase import FunctionalDocFileSuite from Testing.ZopeTestCase import FunctionalDocFileSuite
installProduct('PythonScripts') 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): def setUp(self):
'''This method will run after the test_class' setUp. '''This method will run after the test_class' setUp.
...@@ -58,7 +126,8 @@ def setUp(self): ...@@ -58,7 +126,8 @@ def setUp(self):
def test_suite(): def test_suite():
return TestSuite(( return unittest.TestSuite((
unittest.makeSuite(HTTPHeaderOutputTests),
FunctionalDocTestSuite(setUp=setUp), FunctionalDocTestSuite(setUp=setUp),
FunctionalDocFileSuite('FunctionalDocTest.txt', setUp=setUp), FunctionalDocFileSuite('FunctionalDocTest.txt', setUp=setUp),
)) ))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment