Log message for revision 66583: Merged makerequest fixes from trunk (collector 2057).
Changed: U Zope/branches/2.9/doc/CHANGES.txt U Zope/branches/2.9/lib/python/Testing/ZopeTestCase/utils.py U Zope/branches/2.9/lib/python/Testing/makerequest.py A Zope/branches/2.9/lib/python/Testing/tests/ -=- Modified: Zope/branches/2.9/doc/CHANGES.txt =================================================================== --- Zope/branches/2.9/doc/CHANGES.txt 2006-04-05 20:52:39 UTC (rev 66582) +++ Zope/branches/2.9/doc/CHANGES.txt 2006-04-05 21:13:42 UTC (rev 66583) @@ -14,6 +14,14 @@ to the rules for such a type laid out in the Python docs: http://docs.python.org/api/supporting-cycle-detection.html + Zope 2.9.3 (UNRELEASED) + + Bugs fixed + + - Collector #2057: Allow Testing.makerequest to work with + any acquisition-supporting root object, not just Zope2.app. + Formerly, if you did that, getPhysicalPath() was broken. + Zope 2.9.2 (2006/03/27) Bugs fixed Modified: Zope/branches/2.9/lib/python/Testing/ZopeTestCase/utils.py =================================================================== --- Zope/branches/2.9/lib/python/Testing/ZopeTestCase/utils.py 2006-04-05 20:52:39 UTC (rev 66582) +++ Zope/branches/2.9/lib/python/Testing/ZopeTestCase/utils.py 2006-04-05 21:13:42 UTC (rev 66583) @@ -127,26 +127,14 @@ def makerequest(app, stdout=sys.stdout): '''Wraps the app into a fresh REQUEST.''' - from ZPublisher.BaseRequest import RequestContainer - from ZPublisher.Request import Request - from ZPublisher.Response import Response - response = Response(stdout=stdout) + from Testing.makerequest import makerequest as _makerequest environ = {} environ['SERVER_NAME'] = _Z2HOST or 'nohost' environ['SERVER_PORT'] = '%d' % (_Z2PORT or 80) environ['REQUEST_METHOD'] = 'GET' - request = Request(sys.stdin, environ, response) - request._steps = ['noobject'] # Fake a published object - request['ACTUAL_URL'] = request.get('URL') # Zope 2.7.4 + app = _makerequest(app, stdout=stdout, environ=environ) + return app - # 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): '''Calls a function passing 'app' as first argument.''' from base import app, close Modified: Zope/branches/2.9/lib/python/Testing/makerequest.py =================================================================== --- Zope/branches/2.9/lib/python/Testing/makerequest.py 2006-04-05 20:52:39 UTC (rev 66582) +++ Zope/branches/2.9/lib/python/Testing/makerequest.py 2006-04-05 21:13:42 UTC (rev 66583) @@ -19,27 +19,50 @@ import makerequest app = makerequest.makerequest(Zope2.app()) +You can optionally pass stdout to be used by the response, +and an environ mapping to be used in the request. +Defaults are sys.stdout and os.environ. + +If you don't want to start a zope app in your test, you can wrap other +objects, but they must support acquisition and you should only wrap +your root object. + + $Id$ """ import os -from os import environ from sys import stdin, stdout from ZPublisher.HTTPRequest import HTTPRequest from ZPublisher.HTTPResponse import HTTPResponse from ZPublisher.BaseRequest import RequestContainer -def makerequest(app, stdout=stdout): +def makerequest(app, stdout=stdout, environ=None): resp = HTTPResponse(stdout=stdout) - environ['SERVER_NAME']='foo' - environ['SERVER_PORT']='80' - environ['REQUEST_METHOD'] = 'GET' + if environ is None: + environ = os.environ + environ.setdefault('SERVER_NAME', 'foo') + environ.setdefault('SERVER_PORT', '80') + environ.setdefault('REQUEST_METHOD', 'GET') req = HTTPRequest(stdin, environ, resp) - + req._steps = ['noobject'] # Fake a published object. + req['ACTUAL_URL'] = req.get('URL') # Zope 2.7.4 + # set Zope3-style default skin so that the request is usable for - # Zope3-style view look-ups + # Zope3-style view look-ups. from zope.app.publication.browser import setDefaultSkin setDefaultSkin(req) - return app.__of__(RequestContainer(REQUEST = req)) + requestcontainer = RequestContainer(REQUEST = req) + # Workaround for collector 2057: ensure that we don't break + # getPhysicalPath if app has that method. + # We could instead fix Traversable.getPhysicalPath() to check for + # existence of p.getPhysicalPath before calling it; but it's such + # a commonly called method that I don't want to impact performance + # for something that AFAICT only affects makerequest() in + # practice. + if getattr(app, 'getPhysicalPath', None) is not None: + requestcontainer.getPhysicalPath = lambda: () + + return app.__of__(requestcontainer) Copied: Zope/branches/2.9/lib/python/Testing/tests (from rev 66582, Zope/trunk/lib/python/Testing/tests) _______________________________________________ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins