[Zope-Checkins] SVN: Zope/trunk/ Fixed collector 2057: Testing.makequest broke getPhysicalPath()

2006-04-05 Thread Paul Winkler
Log message for revision 66581:
  Fixed collector 2057: Testing.makequest broke getPhysicalPath()
  when used on anything other than an app object.
  Also added an 'environ' argument if you want to use something
  other than os.environ, and added a couple trivial tweaks from 
  ZopeTestCase.makereqeust.
  Added unit tests for this stuff.
  
  

Changed:
  U   Zope/trunk/doc/CHANGES.txt
  U   Zope/trunk/lib/python/Testing/makerequest.py
  A   Zope/trunk/lib/python/Testing/tests/
  A   Zope/trunk/lib/python/Testing/tests/__init__.py
  A   Zope/trunk/lib/python/Testing/tests/test_makerequest.py

-=-
Modified: Zope/trunk/doc/CHANGES.txt
===
--- Zope/trunk/doc/CHANGES.txt  2006-04-05 20:04:59 UTC (rev 66580)
+++ Zope/trunk/doc/CHANGES.txt  2006-04-05 20:51:21 UTC (rev 66581)
@@ -46,6 +46,9 @@
 
 Features added
 
+  - Testing.makerequest: Added an 'environ' argument so
+clients can use mappings other than os.environ.
+
   - Updated to Docutils 0.4.0 
 
   - reStructuredText: The default value for the 'stylesheet'
@@ -202,6 +205,10 @@
 
 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.
+
   - Collector #2051: Applied patch by Yoshinori Okuji to fix some
 XML export/import problems, including tests for that feature.
 

Modified: Zope/trunk/lib/python/Testing/makerequest.py
===
--- Zope/trunk/lib/python/Testing/makerequest.py2006-04-05 20:04:59 UTC 
(rev 66580)
+++ Zope/trunk/lib/python/Testing/makerequest.py2006-04-05 20:51:21 UTC 
(rev 66581)
@@ -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)

Added: Zope/trunk/lib/python/Testing/tests/__init__.py
===
--- Zope/trunk/lib/python/Testing/tests/__init__.py 2006-04-05 20:04:59 UTC 
(rev 66580)
+++ Zope/trunk/lib/python/Testing/tests/__init__.py 2006-04-05 20:51:21 UTC 
(rev 66581)
@@ -0,0 +1 @@
+#


Property changes on: Zope/trunk/lib/python/Testing/tests/__init__.py
___
Name: svn:keywords
   + Author Date Revision

Added: Zope/trunk/lib/python/Testing/tests/test_makerequest.py
===
--- Zope/trunk/lib/python/Testing/tests/test_makerequest.py 2006-04-05 
20:04:59 UTC (rev 66580)
+++ Zope/trunk/lib/python/Testing/tests/test_makerequest.py 2006-04-05 
20:51:21 UTC (rev 66581)
@@ -0,0 +1,65 @@
+##
+#
+# Copyright (c) 2006 Zope Corporation and Contributors. All Rights Reserved.
+#
+# This software is 

[Zope-Checkins] SVN: Zope/trunk/lib/python/Testing/ZopeTestCase/utils.py Removed duplicate code from ZopeTestCase.utils.makerequest;

2006-04-05 Thread Paul Winkler
Log message for revision 66582:
  Removed duplicate code from ZopeTestCase.utils.makerequest;
  it now wraps Testing.makerequest.makerequest().
  
  

Changed:
  U   Zope/trunk/lib/python/Testing/ZopeTestCase/utils.py

-=-
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/utils.py
===
--- Zope/trunk/lib/python/Testing/ZopeTestCase/utils.py 2006-04-05 20:51:21 UTC 
(rev 66581)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/utils.py 2006-04-05 20:52:39 UTC 
(rev 66582)
@@ -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

___
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins


[Zope-Checkins] SVN: Zope/branches/2.9/ Merged makerequest fixes from trunk (collector 2057).

2006-04-05 Thread Paul Winkler
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: