Log message for revision 119842:
  revert changes to makerequest, need a different approach here

Changed:
  U   
Zope/branches/elro-remove-request-container/src/Testing/ZopeTestCase/sandbox.py
  U   
Zope/branches/elro-remove-request-container/src/Testing/ZopeTestCase/utils.py
  U   Zope/branches/elro-remove-request-container/src/Testing/makerequest.py
  U   
Zope/branches/elro-remove-request-container/src/Testing/tests/test_makerequest.py

-=-
Modified: 
Zope/branches/elro-remove-request-container/src/Testing/ZopeTestCase/sandbox.py
===================================================================
--- 
Zope/branches/elro-remove-request-container/src/Testing/ZopeTestCase/sandbox.py 
    2011-01-22 16:49:26 UTC (rev 119841)
+++ 
Zope/branches/elro-remove-request-container/src/Testing/ZopeTestCase/sandbox.py 
    2011-01-22 16:59:32 UTC (rev 119842)
@@ -19,7 +19,9 @@
 import utils
 import connections
 
+from zope.globalrequest import setRequest, clearRequest
 
+
 class Sandboxed:
     '''Derive from this class and an xTestCase to make each test
        run in its own ZODB sandbox::
@@ -32,7 +34,8 @@
         '''Returns the app object for a test.'''
         app = Zope2.app(Zope2.sandbox().open())
         AppZapper().set(app)
-        app = utils.makerequest(app)
+        req = utils.newrequest()
+        setRequest(req)
         connections.register(app)
         return app
 
@@ -41,6 +44,7 @@
         AppZapper().clear()
         transaction.abort()
         connections.closeAll()
+        clearRequest()
 
 
 class AppZapper:

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:49:26 UTC (rev 119841)
+++ 
Zope/branches/elro-remove-request-container/src/Testing/ZopeTestCase/utils.py   
    2011-01-22 16:59:32 UTC (rev 119842)
@@ -118,6 +118,16 @@
     return _makerequest(app, stdout=stdout, environ=environ)
 
 
+def makerequest(stdout=sys.stdout):
+    '''Wraps the app into a fresh REQUEST.'''
+    from Testing.makerequest import newrequest as _newrequest
+    environ = {}
+    environ['SERVER_NAME'] = _Z2HOST or 'nohost'
+    environ['SERVER_PORT'] = '%d' % (_Z2PORT or 80)
+    environ['REQUEST_METHOD'] = 'GET'
+    return _newrequest(stdout=stdout, environ=environ)
+
+
 def appcall(func, *args, **kw):
     '''Calls a function passing 'app' as first argument.'''
     from base import app, close

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:49:26 UTC (rev 119841)
+++ Zope/branches/elro-remove-request-container/src/Testing/makerequest.py      
2011-01-22 16:59:32 UTC (rev 119842)
@@ -19,7 +19,7 @@
 from sys import stdin, stdout
 from ZPublisher.HTTPRequest import HTTPRequest
 from ZPublisher.HTTPResponse import HTTPResponse
-from zope.globalrequest import setRequest
+from ZPublisher.BaseRequest import RequestContainer
 
 def makerequest(app, stdout=stdout, environ=None):
     """
@@ -61,6 +61,6 @@
     # Zope3-style view look-ups.
     from zope.publisher.browser import setDefaultSkin
     setDefaultSkin(req)
-    setRequest(req)
 
-    return app
+    requestcontainer = RequestContainer(REQUEST = req)
+    return app.__of__(requestcontainer)

Modified: 
Zope/branches/elro-remove-request-container/src/Testing/tests/test_makerequest.py
===================================================================
--- 
Zope/branches/elro-remove-request-container/src/Testing/tests/test_makerequest.py
   2011-01-22 16:49:26 UTC (rev 119841)
+++ 
Zope/branches/elro-remove-request-container/src/Testing/tests/test_makerequest.py
   2011-01-22 16:59:32 UTC (rev 119842)
@@ -17,29 +17,24 @@
 
 from Acquisition import Implicit
 from Testing.makerequest import makerequest
-from OFS.Application import Application
-from zope.globalrequest import getRequest, clearRequest
+from OFS.SimpleItem import SimpleItem
 
 class MakerequestTests(unittest.TestCase):
 
-    def tearDown(self):
-        clearRequest()
-
     def test_makerequest(self):
         # The argument must support acquisition.
-        #self.assertRaises(AttributeError, makerequest, object())
+        self.assertRaises(AttributeError, makerequest, object())
         # After the call, it will have a REQUEST attribute.
-        app = Application()
-        self.assertFalse(hasattr(app, 'REQUEST'))
-        app = makerequest(app)
-        self.failUnless(getRequest() is not None)
-        self.assertTrue(hasattr(app, 'REQUEST'))
+        item = Implicit()
+        self.assertFalse(hasattr(item, 'REQUEST'))
+        item = makerequest(item)
+        self.assertTrue(hasattr(item, 'REQUEST'))
     
     def test_dont_break_getPhysicalPath(self):
         # see http://www.zope.org/Collectors/Zope/2057.  If you want
         # to call getPhysicalPath() on the wrapped object, be sure
         # that it provides a non-recursive getPhysicalPath().
-        class FakeRoot(Application):
+        class FakeRoot(SimpleItem):
             def getPhysicalPath(self):
                 return ('foo',)
         item = FakeRoot()
@@ -50,8 +45,8 @@
         # You can pass a stdout arg and it's used by the response.
         import cStringIO
         out = cStringIO.StringIO()
-        app = makerequest(Application(), stdout=out)
-        app.REQUEST.RESPONSE.write('aaa')
+        item = makerequest(SimpleItem(), stdout=out)
+        item.REQUEST.RESPONSE.write('aaa')
         out.seek(0)
         written = out.read()
         self.assertTrue(written.startswith('Status: 200 OK\r\n'))
@@ -60,8 +55,8 @@
     def test_environ(self):
         # You can pass an environ argument to use in the request.
         environ = {'foofoo': 'barbar'}
-        app = makerequest(Application(), environ=environ)
-        self.assertEqual(app.REQUEST.environ['foofoo'], 'barbar')
+        item = makerequest(SimpleItem(), environ=environ)
+        self.assertEqual(item.REQUEST.environ['foofoo'], 'barbar')
 
 def test_suite():
     suite = unittest.TestSuite()

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
https://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to