Commit 72994a7d authored by Jens Vagelpohl's avatar Jens Vagelpohl

- LP #193122: New method getVirtualRoot added to the Request class

parent ff2e6d82
......@@ -15,6 +15,8 @@ Bugs Fixed
Features Added
++++++++++++++
- LP #193122: New method getVirtualRoot added to the Request class
- Updated test assertions to use unittest's ``assert*`` methods in favor of
their deprecated `fail*` aliases.
......
......@@ -230,6 +230,13 @@ class HTTPRequest(BaseRequest):
other['VirtualRootPhysicalPath'] = parents[-1].getPhysicalPath()
self._resetURLS()
def getVirtualRoot(self):
""" Return a slash-separated virtual root.
If it is same as the physical root, return ''.
"""
return '/'.join([''] + self._script)
def physicalPathToVirtualPath(self, path):
""" Remove the path to the VirtualRoot from a physical path """
if type(path) is type(''):
......
......@@ -1036,6 +1036,16 @@ class HTTPRequestTests(unittest.TestCase):
'{"intkey":123,"stringkey":"blah"}')
self.assertEquals(req.cookies['anothercookie'], 'boring')
def test_getVirtualRoot(self):
# https://bugs.launchpad.net/zope2/+bug/193122
req = self._makeOne()
req._script = []
self.assertEquals(req.getVirtualRoot(), '')
req._script = ['foo', 'bar']
self.assertEquals(req.getVirtualRoot(), '/foo/bar')
TEST_ENVIRON = {
'CONTENT_TYPE': 'multipart/form-data; boundary=12345',
'REQUEST_METHOD': 'POST',
......
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