[Zope-Checkins] SVN: Zope/branches/2.9/lib/python/Testing/ Reverting refactoring of ZopeTestCase.utils.makerequest,

Paul Winkler pw_lists at slinkp.com
Thu Apr 6 17:30:59 EDT 2006


Log message for revision 66621:
  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.
  

Changed:
  U   Zope/branches/2.9/lib/python/Testing/ZopeTestCase/utils.py
  U   Zope/branches/2.9/lib/python/Testing/makerequest.py
  U   Zope/branches/2.9/lib/python/Testing/tests/test_makerequest.py

-=-
Modified: Zope/branches/2.9/lib/python/Testing/ZopeTestCase/utils.py
===================================================================
--- Zope/branches/2.9/lib/python/Testing/ZopeTestCase/utils.py	2006-04-06 21:23:23 UTC (rev 66620)
+++ Zope/branches/2.9/lib/python/Testing/ZopeTestCase/utils.py	2006-04-06 21:30:58 UTC (rev 66621)
@@ -127,14 +127,26 @@
 
 def makerequest(app, stdout=sys.stdout):
     '''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['SERVER_NAME'] = _Z2HOST or 'nohost'
     environ['SERVER_PORT'] = '%d' % (_Z2PORT or 80)
     environ['REQUEST_METHOD'] = 'GET'
-    app = _makerequest(app, stdout=stdout, environ=environ)
-    return app
+    request = Request(sys.stdin, environ, response)
+    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):
     '''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-06 21:23:23 UTC (rev 66620)
+++ Zope/branches/2.9/lib/python/Testing/makerequest.py	2006-04-06 21:30:58 UTC (rev 66621)
@@ -38,13 +38,12 @@
 from ZPublisher.HTTPResponse import HTTPResponse
 from ZPublisher.BaseRequest import RequestContainer
 
-def makerequest(app, stdout=stdout, environ=None):
+def makerequest(app, stdout=stdout):
     resp = HTTPResponse(stdout=stdout)
-    if environ is None:
-        environ = os.environ
-    environ.setdefault('SERVER_NAME', 'foo')
-    environ.setdefault('SERVER_PORT', '80')
-    environ.setdefault('REQUEST_METHOD',  'GET')
+    environ = os.environ
+    environ['SERVER_NAME'] = 'foo'
+    environ['SERVER_PORT'] = '80'
+    environ['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

Modified: Zope/branches/2.9/lib/python/Testing/tests/test_makerequest.py
===================================================================
--- Zope/branches/2.9/lib/python/Testing/tests/test_makerequest.py	2006-04-06 21:23:23 UTC (rev 66620)
+++ Zope/branches/2.9/lib/python/Testing/tests/test_makerequest.py	2006-04-06 21:30:58 UTC (rev 66621)
@@ -50,11 +50,6 @@
         self.failUnless(written.startswith('Status: 200 OK\n'))
         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():
     suite = unittest.TestSuite()



More information about the Zope-Checkins mailing list