[Checkins] SVN: zope.app.publication/trunk/ merge sylvain-testlayers into trunk.
Sylvain Viollon
sylvain at infrae.com
Tue Apr 13 12:30:31 EDT 2010
Log message for revision 110812:
merge sylvain-testlayers into trunk.
Changed:
U zope.app.publication/trunk/CHANGES.txt
U zope.app.publication/trunk/setup.py
U zope.app.publication/trunk/src/zope/app/publication/ftesting.zcml
U zope.app.publication/trunk/src/zope/app/publication/httpfactory.txt
U zope.app.publication/trunk/src/zope/app/publication/methodnotallowed.txt
U zope.app.publication/trunk/src/zope/app/publication/testing.py
U zope.app.publication/trunk/src/zope/app/publication/tests/ftest_zcml_dependencies.zcml
U zope.app.publication/trunk/src/zope/app/publication/tests/test_browserpublication.py
U zope.app.publication/trunk/src/zope/app/publication/tests/test_dependencies.py
U zope.app.publication/trunk/src/zope/app/publication/tests/test_functional.py
U zope.app.publication/trunk/src/zope/app/publication/tests/test_http.py
U zope.app.publication/trunk/src/zope/app/publication/tests/test_simplecomponenttraverser.py
U zope.app.publication/trunk/src/zope/app/publication/tests/test_xmlrpcpublication.py
U zope.app.publication/trunk/src/zope/app/publication/tests/test_zopepublication.py
-=-
Modified: zope.app.publication/trunk/CHANGES.txt
===================================================================
--- zope.app.publication/trunk/CHANGES.txt 2010-04-13 16:27:34 UTC (rev 110811)
+++ zope.app.publication/trunk/CHANGES.txt 2010-04-13 16:30:31 UTC (rev 110812)
@@ -2,12 +2,12 @@
CHANGES
=======
-3.11 (unreleased)
------------------
+3.11.0 (unreleased)
+-------------------
-- Don't depend on zope.app.testing.ztapi anymore in the tests.
+- Don't depend on zope.app.testing and zope.app.zcmlfiles anymore in
+ the tests.
-
3.10.2 (2010-01-08)
-------------------
Modified: zope.app.publication/trunk/setup.py
===================================================================
--- zope.app.publication/trunk/setup.py 2010-04-13 16:27:34 UTC (rev 110811)
+++ zope.app.publication/trunk/setup.py 2010-04-13 16:30:31 UTC (rev 110812)
@@ -17,7 +17,7 @@
# Zope Toolkit policies as described by this documentation.
##############################################################################
-version = '3.11dev'
+version = '3.11.0dev'
import os
from setuptools import setup, find_packages
@@ -52,15 +52,19 @@
package_dir = {'': 'src'},
namespace_packages=['zope', 'zope.app'],
extras_require = dict(
- test=['zope.app.testing',
- 'zope.app.securitypolicy',
- 'zope.app.zcmlfiles>=3.5.4',
- 'zope.app.dav',
+ test=['zope.annotation',
+ 'zope.app.appsetup',
+ 'zope.app.exception',
+ 'zope.app.http',
+ 'zope.app.wsgi',
+ 'zope.applicationcontrol>=3.5.0',
+ 'zope.browserpage',
+ 'zope.login',
+ 'zope.password',
'zope.principalregistry',
- 'zope.app.applicationcontrol>=3.5.0',
- 'zope.site',
- 'zope.login',
- ]),
+ 'zope.security',
+ 'zope.securitypolicy',
+ 'zope.site']),
install_requires=['zope.interface',
'ZODB3',
'zope.authentication',
Modified: zope.app.publication/trunk/src/zope/app/publication/ftesting.zcml
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/ftesting.zcml 2010-04-13 16:27:34 UTC (rev 110811)
+++ zope.app.publication/trunk/src/zope/app/publication/ftesting.zcml 2010-04-13 16:30:31 UTC (rev 110812)
@@ -1,42 +1,53 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:meta="http://namespaces.zope.org/meta"
+ xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="zope"
- package="zope.app.publication"
- >
+ package="zope.app.publication">
- <!-- This file is the equivalent of site.zcml and it is -->
- <!-- used for functional testing setup -->
- <include package="zope.app.dav" file="meta.zcml"/>
+ <include package="zope.component" file="meta.zcml"/>
+ <include package="zope.app.publication" file="meta.zcml" />
+ <include package="zope.browserpage" file="meta.zcml" />
+
+ <include package="zope.app.publication" />
+
+ <include package="zope.security" file="meta.zcml" />
+ <include package="zope.publisher" file="meta.zcml" />
+ <include package="zope.principalregistry" file="meta.zcml" />
+ <include package="zope.browserpage" file="meta.zcml" />
+ <include package="zope.app.publication" file="meta.zcml" />
<include package="zope.securitypolicy" file="meta.zcml" />
- <include package="zope.app.zcmlfiles" />
- <include package="zope.app.dav"/>
- <include package="zope.app.authentication" />
- <include package="zope.app.securitypolicy" />
<include package="zope.login" />
+ <include package="zope.security" />
+ <include package="zope.authentication" />
+ <include package="zope.securitypolicy" />
+ <include package="zope.principalregistry" />
+ <include package="zope.app.publication" />
+ <include package="zope.app.appsetup" file="ftesting.zcml"/>
+ <include package="zope.app.exception.browser" />
+ <include package="zope.app.http" />
+ <include package="zope.annotation" />
+ <include package="zope.publisher" />
+ <include package="zope.password" />
+ <include package="zope.browserpage" />
+ <include package="zope.app.wsgi" />
<securityPolicy
- component="zope.securitypolicy.zopepolicy.ZopeSecurityPolicy" />
+ component="zope.securitypolicy.zopepolicy.ZopeSecurityPolicy" />
- <role id="zope.Anonymous" title="Everybody"
- description="All users have this role implicitly" />
<role id="zope.Manager" title="Site Manager" />
- <!-- Replace the following directive if you don't want public access -->
- <grant permission="zope.View"
- role="zope.Anonymous" />
-
<grantAll role="zope.Manager" />
- <include package="zope.app.securitypolicy.browser.tests" file="functional.zcml" />
-
<!-- Principals -->
-
<unauthenticatedPrincipal
id="zope.anybody"
title="Unauthenticated User" />
+ <grant
+ permission="zope.View"
+ principal="zope.anybody" />
<!-- Principal that tests generally run as -->
<principal
@@ -45,13 +56,14 @@
login="mgr"
password="mgrpw" />
- <!-- 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.mgr" />
- <grant role="zope.Manager" principal="zope.globalmgr" />
+ <browser:defaultView name="test.html" />
+ <browser:page
+ for="*"
+ class=".testing.DefaultTestView"
+ name="test.html"
+ permission="zope.View" />
+
</configure>
Modified: zope.app.publication/trunk/src/zope/app/publication/httpfactory.txt
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/httpfactory.txt 2010-04-13 16:27:34 UTC (rev 110811)
+++ zope.app.publication/trunk/src/zope/app/publication/httpfactory.txt 2010-04-13 16:30:31 UTC (rev 110812)
@@ -10,24 +10,29 @@
A regular GET, POST or HEAD
+ >>> from zope.app.wsgi.testlayer import http
+
>>> print http(r"""
... GET / HTTP/1.1
... """)
- HTTP/1.1 200 OK
- Content-Length: 4322
+ HTTP/1.0 200 OK
+ X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+ Content-Length: ...
Content-Type: text/html;charset=utf-8
...
>>> print http(r"""
... POST / HTTP/1.1
... """)
- HTTP/1.1 200 OK
- Content-Length: 4322
+ HTTP/1.0 200 OK
+ X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+ Content-Length: ...
Content-Type: text/html;charset=utf-8
...
>>> print http(r"""
... HEAD / HTTP/1.1
... """)
- HTTP/1.1 200 OK
+ HTTP/1.0 200 OK
+ X-Powered-By: Zope (www.zope.org), Python (www.python.org)
Content-Length: 0
Content-Type: text/html;charset=utf-8
<BLANKLINE>
@@ -39,6 +44,7 @@
... Content-Type: text/xml
... """)
HTTP/1.0 200 OK
+ X-Powered-By: Zope (www.zope.org), Python (www.python.org)
Content-Length: ...
Content-Type: text/xml;charset=utf-8
...
@@ -54,6 +60,7 @@
... HTTP_SOAPACTION: soap#action
... """)
HTTP/1.0 200 OK
+ X-Powered-By: Zope (www.zope.org), Python (www.python.org)
Content-Length: ...
Content-Type: text/xml;charset=utf-8
...
Modified: zope.app.publication/trunk/src/zope/app/publication/methodnotallowed.txt
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/methodnotallowed.txt 2010-04-13 16:27:34 UTC (rev 110811)
+++ zope.app.publication/trunk/src/zope/app/publication/methodnotallowed.txt 2010-04-13 16:30:31 UTC (rev 110812)
@@ -4,22 +4,25 @@
If we get a request with a method that does not have a corresponding
view, HTTP 405 Method Not Allowed response is returned:
+ >>> from zope.app.wsgi.testlayer import http
+
>>> print http(r"""
... FROG / HTTP/1.1
... """)
- HTTP/1.1 405 Method Not Allowed
- Allow: DELETE, MKCOL, OPTIONS, PROPFIND, PROPPATCH, PUT
+ HTTP/1.0 405 Method Not Allowed
+ X-Powered-By: Zope (www.zope.org), Python (www.python.org)
Content-Length: 18
- <BLANKLINE>
- Method Not Allowed
+ Allow: DELETE, OPTIONS, PUT
+ ...
>>> print http(r"""
... DELETE / HTTP/1.1
- ... Authorization: Basic mgr:mgrpw
+ ... Authorization: Basic bWdyOm1ncnB3
... """)
- HTTP/1.1 405 Method Not Allowed
+ HTTP/1.0 405 Method Not Allowed
...
+
The request below should return 405, but instead crashes with a TypeError,
when the view tries to adapt context to IWriteFile.
Modified: zope.app.publication/trunk/src/zope/app/publication/testing.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/testing.py 2010-04-13 16:27:34 UTC (rev 110811)
+++ zope.app.publication/trunk/src/zope/app/publication/testing.py 2010-04-13 16:30:31 UTC (rev 110812)
@@ -18,10 +18,18 @@
__docformat__ = "reStructuredText"
-import os
-from zope.app.testing.functional import ZCMLLayer
+from zope.app.wsgi.testlayer import BrowserLayer
+from zope.publisher.browser import BrowserPage
+import zope.app.publication
-PublicationLayer = ZCMLLayer(
- os.path.join(os.path.split(__file__)[0], 'ftesting.zcml'),
- __name__, 'PublicationLayer', allow_teardown=True)
+class DefaultTestView(BrowserPage):
+
+ def __call__(self):
+ self.request.response.setHeader(
+ 'Content-Type', 'text/html;charset=utf-8')
+ return "<html><body>Test</body></html>"
+
+
+PublicationLayer = BrowserLayer(zope.app.publication, name='PublicationLayer')
+
Modified: zope.app.publication/trunk/src/zope/app/publication/tests/ftest_zcml_dependencies.zcml
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/tests/ftest_zcml_dependencies.zcml 2010-04-13 16:27:34 UTC (rev 110811)
+++ zope.app.publication/trunk/src/zope/app/publication/tests/ftest_zcml_dependencies.zcml 2010-04-13 16:30:31 UTC (rev 110812)
@@ -3,8 +3,8 @@
<include package="zope.component" file="meta.zcml"/>
<include package="zope.app.publication" file="meta.zcml" />
- <include package="zope.app.publisher.browser" file="meta.zcml" />
+ <include package="zope.browserpage" file="meta.zcml" />
- <include package="zope.app.publication"/>
+ <include package="zope.app.publication" />
</configure>
Modified: zope.app.publication/trunk/src/zope/app/publication/tests/test_browserpublication.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/tests/test_browserpublication.py 2010-04-13 16:27:34 UTC (rev 110811)
+++ zope.app.publication/trunk/src/zope/app/publication/tests/test_browserpublication.py 2010-04-13 16:30:31 UTC (rev 110812)
@@ -248,7 +248,7 @@
self.assertEqual(removeSecurityProxy(ob2).v, 1)
def testTraverseNameApplicationControl(self):
- from zope.app.applicationcontrol.applicationcontrol \
+ from zope.applicationcontrol.applicationcontrol \
import applicationController, applicationControllerRoot
from zope.traversing.interfaces import IEtcNamespace
component.provideUtility(applicationController,
Modified: zope.app.publication/trunk/src/zope/app/publication/tests/test_dependencies.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/tests/test_dependencies.py 2010-04-13 16:27:34 UTC (rev 110811)
+++ zope.app.publication/trunk/src/zope/app/publication/tests/test_dependencies.py 2010-04-13 16:30:31 UTC (rev 110812)
@@ -1,20 +1,20 @@
import os
import unittest
-from zope.interface import implements
+from zope.app.publication.traversers import SimpleComponentTraverser
from zope.component import getMultiAdapter
-from zope.app.testing import functional
+from zope.component.testlayer import ZCMLFileLayer
+from zope.interface import implements
from zope.publisher.browser import TestRequest
-
from zope.publisher.interfaces.browser import IBrowserPublisher
-from zope.app.publication.traversers import SimpleComponentTraverser
-PublicationDependenciesLayer = functional.ZCMLLayer(
- os.path.join(os.path.dirname(__file__), 'ftest_zcml_dependencies.zcml'),
- __name__, 'PublicationDependenciesLayer', allow_teardown=True)
+import zope.app.publication.tests
-class ZCMLDependencies(functional.BrowserTestCase):
+class ZCMLDependencies(unittest.TestCase):
+ layer = ZCMLFileLayer(zope.app.publication.tests,
+ zcml_file='ftest_zcml_dependencies.zcml',
+ name='PublicationDependenciesLayer')
def test_zcml_can_load_with_only_zope_component_meta(self):
# this is just an example. It is supposed to show that the
@@ -28,12 +28,9 @@
self.failUnless(isinstance(res, SimpleComponentTraverser))
self.failUnless(res.context is sample)
+
def test_suite():
suite = unittest.TestSuite()
- ZCMLDependencies.layer = PublicationDependenciesLayer
suite.addTest(unittest.makeSuite(ZCMLDependencies))
return suite
-
-if __name__ == '__main__':
- unittest.main()
Modified: zope.app.publication/trunk/src/zope/app/publication/tests/test_functional.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/tests/test_functional.py 2010-04-13 16:27:34 UTC (rev 110811)
+++ zope.app.publication/trunk/src/zope/app/publication/tests/test_functional.py 2010-04-13 16:30:31 UTC (rev 110812)
@@ -18,31 +18,35 @@
import re
import unittest
+
from zope.testing import renormalizing
-from zope.app.testing import functional
from zope.app.publication.testing import PublicationLayer
+from zope.testing import doctest
checker = renormalizing.RENormalizing([
(re.compile(r"HTTP/1\.([01]) (\d\d\d) .*"), r"HTTP/1.\1 \2 <MESSAGE>"),
])
+optionflags = doctest.ELLIPSIS+doctest.NORMALIZE_WHITESPACE
def test_suite():
- methodnotallowed = functional.FunctionalDocFileSuite(
- '../methodnotallowed.txt')
+ methodnotallowed = doctest.DocFileSuite(
+ '../methodnotallowed.txt',
+ optionflags=optionflags)
methodnotallowed.layer = PublicationLayer
- httpfactory = functional.FunctionalDocFileSuite(
- '../httpfactory.txt', checker=checker)
+ httpfactory = doctest.DocFileSuite(
+ '../httpfactory.txt', checker=checker,
+ optionflags=optionflags)
httpfactory.layer = PublicationLayer
- site = functional.FunctionalDocFileSuite(
- '../site.txt')
+ site = doctest.DocFileSuite(
+ '../site.txt',
+ optionflags=optionflags)
site.layer = PublicationLayer
return unittest.TestSuite((
methodnotallowed,
httpfactory,
- site,
- ))
+ site,))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
Modified: zope.app.publication/trunk/src/zope/app/publication/tests/test_http.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/tests/test_http.py 2010-04-13 16:27:34 UTC (rev 110811)
+++ zope.app.publication/trunk/src/zope/app/publication/tests/test_http.py 2010-04-13 16:30:31 UTC (rev 110812)
@@ -24,7 +24,6 @@
import zope.app.publication.http
from zope import component
-from zope.app.testing.placelesssetup import PlacelessSetup
class I(Interface):
pass
@@ -42,7 +41,7 @@
self.context.spammed += 1
-class Test(PlacelessSetup, TestCase):
+class Test(TestCase):
# Note that zope publication tests cover all of the code but callObject
def test_callObject(self):
@@ -51,7 +50,7 @@
request.method = 'SPAM'
component.provideAdapter(V, (I, IHTTPRequest), Interface, name='SPAM')
-
+
ob = C()
pub.callObject(request, ob)
self.assertEqual(ob.spammed, 1)
Modified: zope.app.publication/trunk/src/zope/app/publication/tests/test_simplecomponenttraverser.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/tests/test_simplecomponenttraverser.py 2010-04-13 16:27:34 UTC (rev 110811)
+++ zope.app.publication/trunk/src/zope/app/publication/tests/test_simplecomponenttraverser.py 2010-04-13 16:30:31 UTC (rev 110812)
@@ -20,7 +20,6 @@
from zope.interface import Interface, directlyProvides
from zope.app.publication.traversers import SimpleComponentTraverser
-from zope.app.testing.placelesssetup import PlacelessSetup
from zope import component
class I(Interface):
@@ -50,7 +49,8 @@
self._comp = comp
-class Test(PlacelessSetup, unittest.TestCase):
+class Test(unittest.TestCase):
+
def testAttr(self):
# test container traver
foo = Container()
Modified: zope.app.publication/trunk/src/zope/app/publication/tests/test_xmlrpcpublication.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/tests/test_xmlrpcpublication.py 2010-04-13 16:27:34 UTC (rev 110811)
+++ zope.app.publication/trunk/src/zope/app/publication/tests/test_xmlrpcpublication.py 2010-04-13 16:30:31 UTC (rev 110812)
@@ -25,7 +25,7 @@
from zope.interface import Interface, implements
from zope.proxy import removeAllProxies
from zope.publisher.interfaces import NotFound
-from zope.app.publisher.interfaces.xmlrpc import IXMLRPCView
+from zope.publisher.interfaces.xmlrpc import IXMLRPCView
from zope.publisher.interfaces.xmlrpc import IXMLRPCRequest
from zope.publisher.interfaces.xmlrpc import IXMLRPCPublisher
from zope.publisher.xmlrpc import TestRequest
Modified: zope.app.publication/trunk/src/zope/app/publication/tests/test_zopepublication.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/tests/test_zopepublication.py 2010-04-13 16:27:34 UTC (rev 110811)
+++ zope.app.publication/trunk/src/zope/app/publication/tests/test_zopepublication.py 2010-04-13 16:30:31 UTC (rev 110812)
@@ -26,7 +26,7 @@
from zope.interface.verify import verifyClass
from zope.interface import implements, classImplements, implementedBy
-from zope.component.interfaces import ComponentLookupError
+from zope.component.interfaces import ComponentLookupError, ISite
from zope.error.interfaces import IErrorReportingUtility
from zope.location import Location
from zope.publisher.base import TestPublication, TestRequest
@@ -36,9 +36,9 @@
from zope.security.management import endInteraction
from zope.traversing.interfaces import IPhysicallyLocatable
from zope.location.interfaces import ILocation
+from zope.testing.cleanup import cleanUp
+from zope.site.site import LocalSiteManager
-from zope.app.testing.placelesssetup import PlacelessSetup
-from zope.app.testing import setup
from zope import component
from zope.app.publication.tests import support
@@ -48,7 +48,7 @@
from zope.security.interfaces import IPrincipal
from zope.principalregistry.principalregistry import principalRegistry
from zope.app.publication.zopepublication import ZopePublication
-from zope.app.folder import Folder, rootFolder
+from zope.site.folder import Folder, rootFolder
class Principal(object):
@@ -105,10 +105,23 @@
class TestRequest(TestRequest):
URL='http://test.url'
-class BasePublicationTests(PlacelessSetup, unittest.TestCase):
+def addUtility(sitemanager, name, iface, utility, suffix=''):
+ """Add a utility to a site manager
+
+ This helper function is useful for tests that need to set up utilities.
+ """
+ folder_name = (name or (iface.__name__ + 'Utility')) + suffix
+ default = sitemanager['default']
+ default[folder_name] = utility
+ utility = default[folder_name]
+ sitemanager.registerUtility(utility, iface, name)
+ return utility
+
+
+class BasePublicationTests(unittest.TestCase):
+
def setUp(self):
- super(BasePublicationTests, self).setUp()
from zope.security.management import endInteraction
endInteraction()
self.policy = setSecurityPolicy(
@@ -124,7 +137,7 @@
app = getattr(root, ZopePublication.root_name, None)
if app is None:
- from zope.app.folder import rootFolder
+ from zope.site.folder import rootFolder
app = rootFolder()
root[ZopePublication.root_name] = app
transaction.commit()
@@ -151,15 +164,15 @@
# Close the request, otherwise a Cleanup object will start logging
# messages from its __del__ method at some inappropriate moment.
self.request.close()
- super(BasePublicationTests, self).tearDown()
+ cleanUp()
+
+class ZopePublicationErrorHandling(BasePublicationTests):
+
def testInterfacesVerify(self):
for interface in implementedBy(ZopePublication):
verifyClass(interface, TestPublication)
-
-class ZopePublicationErrorHandling(BasePublicationTests):
-
def testRetryAllowed(self):
from ZODB.POSException import ConflictError
from zope.publisher.interfaces import Retry
@@ -226,10 +239,10 @@
def _view(obj, request):
return lambda: view_text
-
+
component.provideAdapter(_view, (E1, self.presentation_type),
Interface, name='name')
-
+
try:
raise E1
except:
@@ -285,7 +298,7 @@
component.provideAdapter(MyView, (E2, self.presentation_type),
Interface, name='name')
-
+
try:
raise E2
except:
@@ -470,7 +483,7 @@
# unauthenticated principal.
authentication = AuthUtility3()
component.provideUtility(authentication, IAuthentication)
-
+
# We need a fallback unauthenticated principal, otherwise we'll get a
# ComponentLookupError:
self.assertRaises(ComponentLookupError,
@@ -483,53 +496,6 @@
self.publication.beforeTraversal(self.request)
self.failUnless(self.request.principal is principal)
- def testPlacefulAuth(self):
- setup.setUpTraversal()
- setup.setUpSiteManagerLookup()
- principalRegistry.defineDefaultPrincipal('anonymous', '')
-
- root = self.db.open().root()
- app = root[ZopePublication.root_name]
- app['f1'] = rootFolder()
- f1 = app['f1']
- f1['f2'] = Folder()
- sm1 = setup.createSiteManager(f1)
- setup.addUtility(sm1, '', IAuthentication, AuthUtility1())
-
- f2 = f1['f2']
- sm2 = setup.createSiteManager(f2)
- setup.addUtility(sm2, '', IAuthentication, AuthUtility2())
- transaction.commit()
-
- from zope.app.container.interfaces import ISimpleReadContainer
- from zope.app.container.traversal import ContainerTraverser
-
- component.provideAdapter(ContainerTraverser,
- (ISimpleReadContainer, IRequest),
- IPublishTraverse, name='')
-
- from zope.app.folder.interfaces import IFolder
- from zope.security.checker import defineChecker, InterfaceChecker
- defineChecker(Folder, InterfaceChecker(IFolder))
-
- self.publication.beforeTraversal(self.request)
- self.assertEqual(list(queryInteraction().participations),
- [self.request])
- self.assertEqual(self.request.principal.id, 'anonymous')
- root = self.publication.getApplication(self.request)
- self.publication.callTraversalHooks(self.request, root)
- self.assertEqual(self.request.principal.id, 'anonymous')
- ob = self.publication.traverseName(self.request, root, 'f1')
- self.publication.callTraversalHooks(self.request, ob)
- self.assertEqual(self.request.principal.id, 'test.anonymous')
- ob = self.publication.traverseName(self.request, ob, 'f2')
- self.publication.afterTraversal(self.request, ob)
- self.assertEqual(self.request.principal.id, 'test.bob')
- self.assertEqual(list(queryInteraction().participations),
- [self.request])
- self.publication.endRequest(self.request, ob)
- self.assertEqual(queryInteraction(), None)
-
def testTransactionCommitAfterCall(self):
root = self.db.open().root()
txn = transaction.get()
@@ -616,7 +582,7 @@
component.provideHandler(set.append, (IBeforeTraverseEvent,))
component.provideHandler(clear.append, (IEndRequestEvent,))
-
+
ob = object()
# This should fire the BeforeTraverseEvent
@@ -647,9 +613,64 @@
self.assertEqual(conn.db(), self.db)
+class AuthZopePublicationTests(BasePublicationTests):
+
+ def setUp(self):
+ super(AuthZopePublicationTests, self).setUp()
+ principalRegistry.defineDefaultPrincipal('anonymous', '')
+
+ root = self.db.open().root()
+ app = root[ZopePublication.root_name]
+ app['f1'] = rootFolder()
+ f1 = app['f1']
+ f1['f2'] = Folder()
+ if not ISite.providedBy(f1):
+ f1.setSiteManager(LocalSiteManager(f1))
+ sm1 = f1.getSiteManager()
+ addUtility(sm1, '', IAuthentication, AuthUtility1())
+
+ f2 = f1['f2']
+ if not ISite.providedBy(f2):
+ f2.setSiteManager(LocalSiteManager(f2))
+ sm2 = f2.getSiteManager()
+ addUtility(sm2, '', IAuthentication, AuthUtility2())
+ transaction.commit()
+
+ from zope.container.interfaces import ISimpleReadContainer
+ from zope.container.traversal import ContainerTraverser
+
+ component.provideAdapter(ContainerTraverser,
+ (ISimpleReadContainer, IRequest),
+ IPublishTraverse, name='')
+
+ from zope.site.interfaces import IFolder
+ from zope.security.checker import defineChecker, InterfaceChecker
+ defineChecker(Folder, InterfaceChecker(IFolder))
+
+ def testPlacefulAuth(self):
+ self.publication.beforeTraversal(self.request)
+ self.assertEqual(list(queryInteraction().participations),
+ [self.request])
+ self.assertEqual(self.request.principal.id, 'anonymous')
+ root = self.publication.getApplication(self.request)
+ self.publication.callTraversalHooks(self.request, root)
+ self.assertEqual(self.request.principal.id, 'anonymous')
+ ob = self.publication.traverseName(self.request, root, 'f1')
+ self.publication.callTraversalHooks(self.request, ob)
+ self.assertEqual(self.request.principal.id, 'test.anonymous')
+ ob = self.publication.traverseName(self.request, ob, 'f2')
+ self.publication.afterTraversal(self.request, ob)
+ self.assertEqual(self.request.principal.id, 'test.bob')
+ self.assertEqual(list(queryInteraction().participations),
+ [self.request])
+ self.publication.endRequest(self.request, ob)
+ self.assertEqual(queryInteraction(), None)
+
+
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(ZopePublicationTests),
+ unittest.makeSuite(AuthZopePublicationTests),
unittest.makeSuite(ZopePublicationErrorHandling),
))
More information about the checkins
mailing list