[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/HTTP/tests - testHTTP.py:1.1.2.1
Shane Hathaway
shane@digicool.com
Wed, 28 Nov 2001 11:57:10 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/HTTP/tests
In directory cvs.zope.org:/tmp/cvs-serv5079/lib/python/Zope/Publisher/HTTP/tests
Added Files:
Tag: Zope-3x-branch
testHTTP.py
Log Message:
Rearranged arguments to HTTPRequest and added a simple Publisher.HTTP test.
=== Added File Zope3/lib/python/Zope/Publisher/HTTP/tests/testHTTP.py ===
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 1.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
import unittest
from Zope.Publisher.HTTP.HTTPRequest import HTTPRequest
from Zope.Publisher.HTTP.HTTPResponse import HTTPResponse
from Zope.Publisher.HTTP.BrowserPayload import BrowserRequestPayload, \
BrowserResponsePayload
from Zope.Publisher.Publish import publish
from Zope.Publisher.DefaultPublication import DefaultPublication
from Interface import verify, instancesOfObjectImplements
from StringIO import StringIO
class HTTPTests(unittest.TestCase):
def setUp(self):
class AppRoot:
" "
class Folder:
" "
class Item:
" "
def __call__(self, a, b):
return "%s, %s" % (`a`, `b`)
self.app = AppRoot()
self.app.folder = Folder()
self.app.folder.item = Item()
def _createRequest(self, environ, body=""):
publication = DefaultPublication(self.app)
outstream = StringIO()
resp_payload = BrowserResponsePayload()
response = HTTPResponse(resp_payload, outstream)
instream = StringIO(body)
req_payload = BrowserRequestPayload(publication)
request = HTTPRequest(req_payload, response, instream, environ)
return request
def _publisherResults(self, environ, body=""):
request = self._createRequest(environ, body)
publish(request)
return request.response.body
def testTraversalToItem(self):
env = {
'PATH_INFO': '/folder/item',
'QUERY_STRING': 'a=5&b:int=6'
}
res = self._publisherResults(env)
self.failUnlessEqual(res, "'5', 6")
def test_suite():
loader = unittest.TestLoader()
return loader.loadTestsFromTestCase(HTTPTests)
if __name__=='__main__':
unittest.TextTestRunner().run( test_suite() )