[Zope3-checkins] SVN: Zope3/trunk/ Merged from ZopeX3-3.0 branch:
Jim Fulton
jim at zope.com
Fri Aug 27 17:06:15 EDT 2004
Log message for revision 27310:
Merged from ZopeX3-3.0 branch:
r27289 | jim | 2004-08-27 10:28:18 -0400 (Fri, 27 Aug 2004) | 14 lines
Added code to create a local grant for the test user.
Later, we need to figure out a way to avoid this depenency on
the security policy.
Added a flag to the http function to disable error handling. This is
useful for debugging failures. (Maybe we should make this the
default when a 200 status is expected.)
Added code to unquote the url path. (Perhaps later we
should add logic to utf-8 decode it too.)
Fixed handling of certain headers that don't get an HTTP_ prefix in
the request. This makes xml-rpc requests work
Changed:
U Zope3/trunk/ftesting.zcml
U Zope3/trunk/src/zope/app/tests/functional.py
-=-
Modified: Zope3/trunk/ftesting.zcml
===================================================================
--- Zope3/trunk/ftesting.zcml 2004-08-27 21:01:06 UTC (rev 27309)
+++ Zope3/trunk/ftesting.zcml 2004-08-27 21:06:15 UTC (rev 27310)
@@ -19,6 +19,7 @@
id="zope.anybody"
title="Unauthenticated User" />
+ <!-- Principal that tests generally run as -->
<principal
id="zope.mgr"
title="Manager"
@@ -27,6 +28,15 @@
<grant role="zope.Manager" principal="zope.mgr" />
+ <!-- Bootstrap principal used to make local grant to the principal above -->
+ <principal
+ id="zope.globalmgr"
+ title="Manager"
+ login="globalmgr"
+ password="globalmgrpw" />
+
+ <grant role="zope.Manager" principal="zope.globalmgr" />
+
<includeOverrides file="overrides_ftesting.zcml" />
</configure>
Modified: Zope3/trunk/src/zope/app/tests/functional.py
===================================================================
--- Zope3/trunk/src/zope/app/tests/functional.py 2004-08-27 21:01:06 UTC (rev 27309)
+++ Zope3/trunk/src/zope/app/tests/functional.py 2004-08-27 21:06:15 UTC (rev 27310)
@@ -23,6 +23,7 @@
import sys
import traceback
import unittest
+import urllib
from StringIO import StringIO
from Cookie import SimpleCookie
@@ -41,6 +42,7 @@
from zope.testing import doctest
from zope.app.debug import Debugger
+import zope.app.pluggableauth
from zope.app.publication.http import HTTPPublication
from zope.app.publication.browser import BrowserPublication
from zope.app.publication.xmlrpc import XMLRPCPublication
@@ -79,6 +81,16 @@
def __getattr__(self, attr):
return getattr(self._response, attr)
+
+grant_request = r"""
+POST /@@PrincipalRoles.html HTTP/1.1
+Authorization: Basic Z2xvYmFsbWdyOmdsb2JhbG1ncnB3
+Content-Length: 97
+Content-Type: application/x-www-form-urlencoded
+Referer: http://localhost:8081/@@PrincipalRoles.html
+
+grid.zope.Manager.zope.mgr=Allow&principals%3Alist=zope.mgr&roles%3Alist=zope.Manager&APPLY=Apply"""
+
class FunctionalTestSetup(object):
"""Keeps shared state across several functional test cases."""
@@ -108,6 +120,10 @@
self.connection = None
self._config_file = config_file
self._init = True
+
+ # Make a local grant for the test user
+ response = http(grant_request, handle_errors=False)
+
elif config_file and config_file != self._config_file:
# Running different tests with different configurations is not
# supported at the moment
@@ -430,7 +446,7 @@
return "%s\n\n%s" % (self.header_output, body)
return "%s\n" % (self.header_output)
-def http(request_string):
+def http(request_string, handle_errors=True):
"""Execute an HTTP request string via the publisher
This is used for HTTP doc tests.
@@ -446,6 +462,7 @@
command_line = request_string[:l].rstrip()
request_string = request_string[l+1:]
method, path, protocol = command_line.split()
+ path = urllib.unquote(path)
instream = StringIO(request_string)
@@ -458,7 +475,9 @@
headers = [split_header(header)
for header in rfc822.Message(instream).headers]
for name, value in headers:
- name = 'HTTP_' + ('_'.join(name.upper().split('-')))
+ name = ('_'.join(name.upper().split('-')))
+ if name not in ('CONTENT_TYPE', 'CONTENT_LENGTH'):
+ name = 'HTTP_' + name
environment[name] = value.rstrip()
outstream = HTTPTaskStub()
@@ -490,7 +509,7 @@
response = DocResponseWrapper(request.response, outstream, path,
header_output)
- publish(request)
+ publish(request, handle_errors=handle_errors)
setSite(old_site)
# sync Python connection:
More information about the Zope3-Checkins
mailing list