[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/HTTP/tests - testHTTP.py:1.1.2.2
Martijn Pieters
mj@zope.com
Wed, 28 Nov 2001 14:57:48 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/HTTP/tests
In directory cvs.zope.org:/tmp/cvs-serv27820/lib/python/Zope/Publisher/HTTP/tests
Modified Files:
Tag: Zope-3x-branch
testHTTP.py
Log Message:
HTTP environment tests
=== Zope3/lib/python/Zope/Publisher/HTTP/tests/testHTTP.py 1.1.2.1 => 1.1.2.2 ===
class HTTPTests(unittest.TestCase):
+ _testEnv = {
+ 'PATH_INFO': '/folder/item',
+ 'QUERY_STRING': 'a=5&b:int=6',
+ 'SERVER_URL': 'http://foobar.com',
+ 'HTTP_HOST': 'foobar.com',
+ 'CONTENT_LENGTH': '0',
+ 'HTTP_AUTHORIZATION': 'Should be in accessible',
+ 'GATEWAY_INTERFACE': 'TestFooInterface/1.0',
+ 'HTTP_OFF_THE_WALL': "Spam 'n eggs",
+ }
+
def setUp(self):
class AppRoot:
" "
@@ -39,28 +50,67 @@
self.app.folder = Folder()
self.app.folder.item = Item()
- def _createRequest(self, environ, body=""):
+ def _createRequest(self, environ={}, body=""):
+ env = self._testEnv.copy()
+ env.update(environ)
+ if len(body):
+ env['CONTENT_LENGTH'] = str(len(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)
+ request = HTTPRequest(req_payload, response, instream, env)
return request
- def _publisherResults(self, environ, body=""):
+ 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)
+ res = self._publisherResults()
self.failUnlessEqual(res, "'5', 6")
+
+ def testRequestEnvironment(self):
+ req = self._createRequest()
+ publish(req)
+
+ self.assertEquals(req['URL0'], 'http://foobar.com/folder/item')
+ self.assertEquals(req['URL1'], 'http://foobar.com/folder')
+ self.assertEquals(req['URL2'], 'http://foobar.com')
+ self.assertRaises(KeyError, req.__getitem__, 'URL3')
+
+ self.assertEquals(req['BASE0'], 'http://foobar.com')
+ self.assertEquals(req['BASE1'], 'http://foobar.com')
+ self.assertEquals(req['BASE2'], 'http://foobar.com/folder')
+ self.assertEquals(req['BASE3'], 'http://foobar.com/folder/item')
+ self.assertRaises(KeyError, req.__getitem__, 'BASE4')
+
+ self.assertEquals(req['URLPATH0'], '/folder/item')
+ self.assertEquals(req['URLPATH1'], '/folder')
+ self.assertEquals(req['URLPATH2'], '')
+ self.assertRaises(KeyError, req.__getitem__, 'URLPATH3')
+
+ self.assertEquals(req['BASEPATH0'], '')
+ self.assertEquals(req['BASEPATH1'], '')
+ self.assertEquals(req['BASEPATH2'], '/folder')
+ self.assertEquals(req['BASEPATH3'], '/folder/item')
+ self.assertRaises(KeyError, req.__getitem__, 'BASEPATH4')
+
+ self.assertEquals(req['URL'], 'http://foobar.com/folder/item')
+ self.assertEquals(req['SERVER_URL'], 'http://foobar.com')
+ self.assertEquals(req['HTTP_HOST'], 'foobar.com')
+ self.assertEquals(req['PATH_INFO'], '/folder/item')
+ self.assertEquals(req['RESPONSE'], req.response)
+ self.assertEquals(req['CONTENT_LENGTH'], '0')
+ self.assertEquals(req['HTTP_AUTHORIZATION'], '')
+ self.assertEquals(req['GATEWAY_INTERFACE'], 'TestFooInterface/1.0')
+ self.assertEquals(req['HTTP_OFF_THE_WALL'], "Spam 'n eggs")
+
+ self.assertEquals(req['HTTP_WE_DID_NOT_PROVIDE_THIS'], '')
def test_suite():