[Zope-Checkins] SVN: Zope/branches/elro-remove-request-container/src/Testing/ Leave makerequest using a RequestContainer to support legacy tests; make ZopeTestCase set the global request instead. All tests pass.
Laurence Rowe
l at lrowe.co.uk
Sat Jan 22 12:11:33 EST 2011
Log message for revision 119843:
Leave makerequest using a RequestContainer to support legacy tests; make ZopeTestCase set the global request instead. All tests pass.
Changed:
U Zope/branches/elro-remove-request-container/src/Testing/ZopeTestCase/base.py
U Zope/branches/elro-remove-request-container/src/Testing/ZopeTestCase/utils.py
U Zope/branches/elro-remove-request-container/src/Testing/makerequest.py
-=-
Modified: Zope/branches/elro-remove-request-container/src/Testing/ZopeTestCase/base.py
===================================================================
--- Zope/branches/elro-remove-request-container/src/Testing/ZopeTestCase/base.py 2011-01-22 16:59:32 UTC (rev 119842)
+++ Zope/branches/elro-remove-request-container/src/Testing/ZopeTestCase/base.py 2011-01-22 17:11:33 UTC (rev 119843)
@@ -107,7 +107,11 @@
def _app(self):
'''Returns the app object for a test.'''
- return app()
+ app = Zope2.app()
+ req = utils.newrequest()
+ setRequest(req)
+ connections.register(app)
+ return app
def _setup(self):
'''Sets up the fixture. Framework authors may
Modified: Zope/branches/elro-remove-request-container/src/Testing/ZopeTestCase/utils.py
===================================================================
--- Zope/branches/elro-remove-request-container/src/Testing/ZopeTestCase/utils.py 2011-01-22 16:59:32 UTC (rev 119842)
+++ Zope/branches/elro-remove-request-container/src/Testing/ZopeTestCase/utils.py 2011-01-22 17:11:33 UTC (rev 119843)
@@ -118,8 +118,8 @@
return _makerequest(app, stdout=stdout, environ=environ)
-def makerequest(stdout=sys.stdout):
- '''Wraps the app into a fresh REQUEST.'''
+def newrequest(stdout=sys.stdout):
+ '''Creates a new request for testing'''
from Testing.makerequest import newrequest as _newrequest
environ = {}
environ['SERVER_NAME'] = _Z2HOST or 'nohost'
@@ -160,6 +160,7 @@
'importObjectFromFile',
'appcall',
'makerequest',
+ 'newrequest',
'makelist',
]
Modified: Zope/branches/elro-remove-request-container/src/Testing/makerequest.py
===================================================================
--- Zope/branches/elro-remove-request-container/src/Testing/makerequest.py 2011-01-22 16:59:32 UTC (rev 119842)
+++ Zope/branches/elro-remove-request-container/src/Testing/makerequest.py 2011-01-22 17:11:33 UTC (rev 119843)
@@ -19,8 +19,41 @@
from sys import stdin, stdout
from ZPublisher.HTTPRequest import HTTPRequest
from ZPublisher.HTTPResponse import HTTPResponse
-from ZPublisher.BaseRequest import RequestContainer
+from ExtensionClass import Base
+class RequestContainer(Base):
+ __roles__=None
+ def __init__(self,**kw):
+ for k,v in kw.items(): self.__dict__[k]=v
+
+
+def newrequest(stdout=stdout, environ=None):
+ """
+ Creates a new request for testing.
+
+ *stdout* is an optional file-like object and is used by
+ REQUEST.RESPONSE. The default is sys.stdout.
+
+ *environ* is an optional mapping to be used in the request.
+ Default is a fresh dictionary. Passing os.environ is not
+ recommended; tests should not pollute the real os.environ.
+ """
+ if environ is None:
+ environ = {}
+ resp = HTTPResponse(stdout=stdout)
+ 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.
+ from zope.publisher.browser import setDefaultSkin
+ setDefaultSkin(req)
+ return req
+
def makerequest(app, stdout=stdout, environ=None):
"""
Adds an HTTPRequest at app.REQUEST, and returns
@@ -47,20 +80,6 @@
Default is a fresh dictionary. Passing os.environ is not
recommended; tests should not pollute the real os.environ.
"""
- if environ is None:
- environ = {}
- resp = HTTPResponse(stdout=stdout)
- 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.
- from zope.publisher.browser import setDefaultSkin
- setDefaultSkin(req)
-
+ req = newrequest(stdout, environ)
requestcontainer = RequestContainer(REQUEST = req)
return app.__of__(requestcontainer)
More information about the Zope-Checkins
mailing list