Commit cedcc3ac authored by Paul Winkler's avatar Paul Winkler

Reverting refactoring of ZopeTestCase.utils.makerequest,

and the related addition of an environ argument to
Testing.makerequest.  This was not a bugfix, thus inappropriate
for the stable branch.  Apologies.
parent 61035255
...@@ -127,13 +127,25 @@ def startZServer(number_of_threads=1, log=None): ...@@ -127,13 +127,25 @@ def startZServer(number_of_threads=1, log=None):
def makerequest(app, stdout=sys.stdout): def makerequest(app, stdout=sys.stdout):
'''Wraps the app into a fresh REQUEST.''' '''Wraps the app into a fresh REQUEST.'''
from Testing.makerequest import makerequest as _makerequest from ZPublisher.BaseRequest import RequestContainer
from ZPublisher.Request import Request
from ZPublisher.Response import Response
response = Response(stdout=stdout)
environ = {} environ = {}
environ['SERVER_NAME'] = _Z2HOST or 'nohost' environ['SERVER_NAME'] = _Z2HOST or 'nohost'
environ['SERVER_PORT'] = '%d' % (_Z2PORT or 80) environ['SERVER_PORT'] = '%d' % (_Z2PORT or 80)
environ['REQUEST_METHOD'] = 'GET' environ['REQUEST_METHOD'] = 'GET'
app = _makerequest(app, stdout=stdout, environ=environ) request = Request(sys.stdin, environ, response)
return app request._steps = ['noobject'] # Fake a published object
request['ACTUAL_URL'] = request.get('URL') # Zope 2.7.4
# set Zope3-style default skin so that the request is usable for
# Zope3-style view look-ups
from zope.app.publication.browser import setDefaultSkin
setDefaultSkin(request)
return app.__of__(RequestContainer(REQUEST=request))
def appcall(function, *args, **kw): def appcall(function, *args, **kw):
'''Calls a function passing 'app' as first argument.''' '''Calls a function passing 'app' as first argument.'''
......
...@@ -38,13 +38,12 @@ from ZPublisher.HTTPRequest import HTTPRequest ...@@ -38,13 +38,12 @@ from ZPublisher.HTTPRequest import HTTPRequest
from ZPublisher.HTTPResponse import HTTPResponse from ZPublisher.HTTPResponse import HTTPResponse
from ZPublisher.BaseRequest import RequestContainer from ZPublisher.BaseRequest import RequestContainer
def makerequest(app, stdout=stdout, environ=None): def makerequest(app, stdout=stdout):
resp = HTTPResponse(stdout=stdout) resp = HTTPResponse(stdout=stdout)
if environ is None: environ = os.environ
environ = os.environ environ['SERVER_NAME'] = 'foo'
environ.setdefault('SERVER_NAME', 'foo') environ['SERVER_PORT'] = '80'
environ.setdefault('SERVER_PORT', '80') environ['REQUEST_METHOD'] = 'GET'
environ.setdefault('REQUEST_METHOD', 'GET')
req = HTTPRequest(stdin, environ, resp) req = HTTPRequest(stdin, environ, resp)
req._steps = ['noobject'] # Fake a published object. req._steps = ['noobject'] # Fake a published object.
req['ACTUAL_URL'] = req.get('URL') # Zope 2.7.4 req['ACTUAL_URL'] = req.get('URL') # Zope 2.7.4
......
...@@ -50,11 +50,6 @@ class MakerequestTests(unittest.TestCase): ...@@ -50,11 +50,6 @@ class MakerequestTests(unittest.TestCase):
self.failUnless(written.startswith('Status: 200 OK\n')) self.failUnless(written.startswith('Status: 200 OK\n'))
self.failUnless(written.endswith('\naaa')) self.failUnless(written.endswith('\naaa'))
def test_environ(self):
# You can pass an environ argument to use in the request.
environ = {'foofoo': 'barbar'}
item = makerequest(SimpleItem(), environ=environ)
self.assertEqual(item.REQUEST.environ['foofoo'], 'barbar')
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
......
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