[Checkins] SVN: zope.app.publication/trunk/ No more dependency on zope.app.testing.ztapi. This is a first
Martijn Faassen
faassen at startifact.com
Wed Jan 20 10:31:25 EST 2010
Log message for revision 108332:
No more dependency on zope.app.testing.ztapi. This is a first
step to get rid of a dependency on zope.app.testing altogether..
Changed:
U zope.app.publication/trunk/CHANGES.txt
U zope.app.publication/trunk/setup.py
A zope.app.publication/trunk/src/zope/app/publication/tests/support.py
U zope.app.publication/trunk/src/zope/app/publication/tests/test_browserpublication.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_httpfactory.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-01-20 15:30:31 UTC (rev 108331)
+++ zope.app.publication/trunk/CHANGES.txt 2010-01-20 15:31:25 UTC (rev 108332)
@@ -2,10 +2,10 @@
CHANGES
=======
-3.10.3 (unreleased)
--------------------
+3.11 (unreleased)
+-----------------
-- Nothing changed yet.
+- Don't depend on zope.app.testing.ztapi anymore in the tests.
3.10.2 (2010-01-08)
Modified: zope.app.publication/trunk/setup.py
===================================================================
--- zope.app.publication/trunk/setup.py 2010-01-20 15:30:31 UTC (rev 108331)
+++ zope.app.publication/trunk/setup.py 2010-01-20 15:31:25 UTC (rev 108332)
@@ -17,7 +17,7 @@
# Zope Toolkit policies as described by this documentation.
##############################################################################
-version = '3.10.3dev'
+version = '3.11dev'
import os
from setuptools import setup, find_packages
Added: zope.app.publication/trunk/src/zope/app/publication/tests/support.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/tests/support.py (rev 0)
+++ zope.app.publication/trunk/src/zope/app/publication/tests/support.py 2010-01-20 15:31:25 UTC (rev 108332)
@@ -0,0 +1,29 @@
+# an API to help us do some component registrations for
+# the publisher to help with the testing.
+# This functionality is also implemented in zope.app.testing.
+# this functionality has two problems:
+# * the code is extremely hard to understand as it papers over
+# the zope.component APIs
+# * we want to lift the dependency on zope.app.testing for other reasons
+# it's possible that this code should end up in published test support modules
+# in other packages deeper down (zope.publisher, zope.traversing). The
+# fact that we have to import interfaces from these gives us this
+# clue. We will investigate pushing them down to these packages
+# later.
+from zope import component
+from zope.traversing.interfaces import ITraversable
+from zope.publisher.interfaces import IDefaultViewName
+from zope.publisher.interfaces.browser import (IDefaultBrowserLayer,
+ IBrowserRequest)
+
+def provideNamespaceHandler(name, handler):
+ component.provideAdapter(handler, (None,), ITraversable,
+ name=name)
+ component.provideAdapter(handler, (None, None), ITraversable,
+ name=name)
+
+def setDefaultViewName(for_, name, layer=IDefaultBrowserLayer,
+ type=IBrowserRequest):
+ if layer is None:
+ layer = type
+ component.provideAdapter(name, (for_, layer), IDefaultViewName)
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-01-20 15:30:31 UTC (rev 108331)
+++ zope.app.publication/trunk/src/zope/app/publication/tests/test_browserpublication.py 2010-01-20 15:31:25 UTC (rev 108332)
@@ -17,16 +17,16 @@
"""
import unittest
-from zope.app.testing import ztapi
from StringIO import StringIO
+from zope import component
from zope.security.interfaces import ForbiddenAttribute
from zope.interface import Interface, implements
from zope.publisher.publish import publish
from zope.publisher.browser import TestRequest, BrowserView
-from zope.publisher.interfaces.browser import IBrowserPublisher
-
+from zope.publisher.interfaces.browser import (IBrowserPublisher,
+ IDefaultBrowserLayer)
from zope.proxy import getProxiedObject
from zope.security.proxy import Proxy, removeSecurityProxy
from zope.security.checker import defineChecker, NamesChecker
@@ -38,6 +38,7 @@
from zope.app.publication.traversers import TestTraverser
from zope.app.publication.tests.test_zopepublication \
import BasePublicationTests as BasePublicationTests_
+from zope.app.publication.tests import support
from persistent import Persistent
@@ -119,9 +120,12 @@
pub = BrowserPublication(self.db)
- ztapi.browserView(I1, 'view', DummyView)
- ztapi.setDefaultViewName(I1, 'view')
- ztapi.browserViewProviding(None, TestTraverser, IBrowserPublisher)
+ component.provideAdapter(DummyView, (I1, IDefaultBrowserLayer),
+ Interface, name='view')
+
+ support.setDefaultViewName(I1, 'view')
+ component.provideAdapter(TestTraverser, (None, IDefaultBrowserLayer),
+ IBrowserPublisher)
ob = O1()
@@ -170,7 +174,9 @@
self.counter += 1
return self.context[name]
- ztapi.browserViewProviding(I1, Adapter, IBrowserPublisher)
+ component.provideAdapter(Adapter, (I1, IDefaultBrowserLayer),
+ IBrowserPublisher)
+
ob = mydict()
ob['bruce'] = SimpleObject('bruce')
ob['bruce2'] = SimpleObject('bruce2')
@@ -189,7 +195,10 @@
def browserDefault(self, request):
return (self.context['bruce'], 'dummy')
- ztapi.browserViewProviding(I1, Adapter, IBrowserPublisher)
+ component.provideAdapter(Adapter,
+ (I1, IDefaultBrowserLayer),
+ IBrowserPublisher)
+
ob = mydict()
ob['bruce'] = SimpleObject('bruce')
ob['bruce2'] = SimpleObject('bruce2')
@@ -205,7 +214,9 @@
x = SimpleObject(1)
ob = C()
r = self._createRequest('/x',pub)
- ztapi.browserViewProviding(None, TestTraverser, IBrowserPublisher)
+ component.provideAdapter(TestTraverser,
+ (None, IDefaultBrowserLayer),
+ IBrowserPublisher)
ob2 = pub.traverseName(r, ob, 'x')
self.assertRaises(ForbiddenAttribute, getattr, ob2, 'v')
self.assertEqual(removeSecurityProxy(ob2).v, 1)
@@ -220,7 +231,8 @@
class V(object):
def __init__(self, context, request): pass
r = self._createRequest('/@@spam',pub)
- ztapi.browserView(I, 'spam', V)
+ component.provideAdapter(V, (I, IDefaultBrowserLayer), Interface,
+ name='spam')
ob2 = pub.traverseName(r, ob, '@@spam')
self.assertEqual(ob2.__class__, V)
@@ -239,7 +251,9 @@
from zope.app.applicationcontrol.applicationcontrol \
import applicationController, applicationControllerRoot
from zope.traversing.interfaces import IEtcNamespace
- ztapi.provideUtility(IEtcNamespace, applicationController, 'process')
+ component.provideUtility(applicationController,
+ IEtcNamespace, name='process')
+
pub = self.klass(self.db)
r = self._createRequest('/++etc++process',pub)
ac = pub.traverseName(r,
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-01-20 15:30:31 UTC (rev 108331)
+++ zope.app.publication/trunk/src/zope/app/publication/tests/test_http.py 2010-01-20 15:31:25 UTC (rev 108332)
@@ -23,7 +23,7 @@
from zope.publisher.interfaces.http import IHTTPRequest
import zope.app.publication.http
-from zope.app.testing import ztapi
+from zope import component
from zope.app.testing.placelesssetup import PlacelessSetup
class I(Interface):
@@ -50,8 +50,8 @@
request = HTTPRequest(StringIO(''), {})
request.method = 'SPAM'
- ztapi.provideView(I, IHTTPRequest, Interface, 'SPAM', V)
-
+ 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_httpfactory.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/tests/test_httpfactory.py 2010-01-20 15:30:31 UTC (rev 108331)
+++ zope.app.publication/trunk/src/zope/app/publication/tests/test_httpfactory.py 2010-01-20 15:31:25 UTC (rev 108332)
@@ -13,7 +13,7 @@
##############################################################################
"""Tests for the HTTP Publication Request Factory.
-$Id: test_httpfactory.py 38357 2005-09-07 20:14:34Z srichter $
+$Id$
"""
from unittest import TestCase, TestSuite, main, makeSuite
@@ -29,7 +29,6 @@
from zope.app.publication.browser import BrowserPublication
from zope.app.publication.http import HTTPPublication
from zope.app.publication.xmlrpc import XMLRPCPublication
-from zope.app.testing import ztapi
from zope.app.publication import interfaces
from zope.app.publication.requestpublicationregistry import factoryRegistry
from zope.app.publication.requestpublicationfactories import \
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-01-20 15:30:31 UTC (rev 108331)
+++ zope.app.publication/trunk/src/zope/app/publication/tests/test_simplecomponenttraverser.py 2010-01-20 15:31:25 UTC (rev 108332)
@@ -21,7 +21,7 @@
from zope.app.publication.traversers import SimpleComponentTraverser
from zope.app.testing.placelesssetup import PlacelessSetup
-from zope.app.testing import ztapi
+from zope import component
class I(Interface):
pass
@@ -69,7 +69,8 @@
req = Request(I)
T = SimpleComponentTraverser(c, req)
- ztapi.provideView(None, I, Interface, 'foo', View)
+ component.provideAdapter(View, (None, I), Interface,
+ name='foo')
self.failUnless(T.publishTraverse(req, 'foo').__class__ is View)
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-01-20 15:30:31 UTC (rev 108331)
+++ zope.app.publication/trunk/src/zope/app/publication/tests/test_xmlrpcpublication.py 2010-01-20 15:31:25 UTC (rev 108332)
@@ -29,9 +29,9 @@
from zope.publisher.interfaces.xmlrpc import IXMLRPCRequest
from zope.publisher.interfaces.xmlrpc import IXMLRPCPublisher
from zope.publisher.xmlrpc import TestRequest
-from zope.app.testing import ztapi
+from zope.app.publication.tests import support
+from zope import component
-
class SimpleObject(object):
def __init__(self, v):
self.v = v
@@ -52,8 +52,9 @@
x = SimpleObject(1)
ob = C()
r = self._createRequest('/x', pub)
- ztapi.provideView(None, IXMLRPCRequest, IXMLRPCPublisher,
- '', TestTraverser)
+ component.provideAdapter(TestTraverser, (None, IXMLRPCRequest),
+ IXMLRPCPublisher)
+
ob2 = pub.traverseName(r, ob, 'x')
self.assertEqual(removeAllProxies(ob2).v, 1)
@@ -76,8 +77,10 @@
ob = C()
r = self._createRequest('/foo', pub)
- ztapi.provideView(I, IXMLRPCView, Interface, 'view', V)
- ztapi.setDefaultViewName(I, 'view', type=IXMLRPCView)
+ component.provideAdapter(V, (I, IXMLRPCView), Interface,
+ name='view')
+
+ support.setDefaultViewName(I, 'view', type=IXMLRPCView)
self.assertRaises(NotFound, pub.traverseName, r, ob, 'foo')
@@ -99,11 +102,13 @@
# Register the simple traverser so we can traverse without @@
- ztapi.provideView(Interface, IXMLRPCRequest, IXMLRPCPublisher, '',
- SimpleComponentTraverser)
+ component.provideAdapter(SimpleComponentTraverser,
+ (Interface, IXMLRPCRequest),
+ IXMLRPCPublisher)
r = self._createRequest('/@@spam', pub)
- ztapi.provideView(I, IXMLRPCRequest, Interface, 'spam', V)
+ component.provideAdapter(V, (I, IXMLRPCRequest), Interface,
+ name='spam')
ob2 = pub.traverseName(r, ob, '@@spam')
self.assertEqual(removeAllProxies(ob2).__class__, V)
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-01-20 15:30:31 UTC (rev 108331)
+++ zope.app.publication/trunk/src/zope/app/publication/tests/test_zopepublication.py 2010-01-20 15:31:25 UTC (rev 108332)
@@ -24,7 +24,6 @@
from ZODB.DemoStorage import DemoStorage
import transaction
-import zope.component
from zope.interface.verify import verifyClass
from zope.interface import implements, classImplements, implementedBy
from zope.component.interfaces import ComponentLookupError
@@ -39,7 +38,9 @@
from zope.location.interfaces import ILocation
from zope.app.testing.placelesssetup import PlacelessSetup
-from zope.app.testing import setup, ztapi
+from zope.app.testing import setup
+from zope import component
+from zope.app.publication.tests import support
from zope.authentication.interfaces import IAuthentication
from zope.authentication.interfaces import IFallbackUnauthenticatedPrincipal
@@ -116,7 +117,7 @@
self.storage = DemoStorage('test_storage')
self.db = db = DB(self.storage)
- ztapi.provideUtility(IAuthentication, principalRegistry)
+ component.provideUtility(principalRegistry, IAuthentication)
connection = db.open()
root = connection.root()
@@ -132,10 +133,11 @@
self.app = app
from zope.traversing.namespace import view, resource, etc
- ztapi.provideNamespaceHandler('view', view)
- ztapi.provideNamespaceHandler('resource', resource)
- ztapi.provideNamespaceHandler('etc', etc)
+ support.provideNamespaceHandler('view', view)
+ support.provideNamespaceHandler('resource', resource)
+ support.provideNamespaceHandler('etc', etc)
+
self.request = TestRequest('/f1/f2')
self.user = Principal('test.principal')
self.request.setPrincipal(self.user)
@@ -217,12 +219,17 @@
class E1(Exception):
pass
- ztapi.setDefaultViewName(E1, 'name',
- layer=None,
- type=self.presentation_type)
+ support.setDefaultViewName(E1, 'name',
+ layer=None,
+ type=self.presentation_type)
view_text = 'You had a conflict error'
- ztapi.provideView(E1, self.presentation_type, Interface,
- 'name', lambda obj, request: lambda: view_text)
+
+ def _view(obj, request):
+ return lambda: view_text
+
+ component.provideAdapter(_view, (E1, self.presentation_type),
+ Interface, name='name')
+
try:
raise E1
except:
@@ -259,9 +266,9 @@
class E2(Exception):
pass
- ztapi.setDefaultViewName(E2, 'name',
- layer=self.presentation_type,
- type=self.presentation_type)
+ support.setDefaultViewName(E2, 'name',
+ layer=self.presentation_type,
+ type=self.presentation_type)
view_text = 'You had a conflict error'
from zope.browser.interfaces import ISystemErrorView
@@ -276,8 +283,9 @@
def __call__(self):
return view_text
- ztapi.provideView(E2, self.presentation_type, Interface,
- 'name', MyView)
+ component.provideAdapter(MyView, (E2, self.presentation_type),
+ Interface, name='name')
+
try:
raise E2
except:
@@ -305,10 +313,14 @@
class IClassicError(Interface):
pass
classImplements(ClassicError, IClassicError)
- ztapi.setDefaultViewName(IClassicError, 'name', self.presentation_type)
+ support.setDefaultViewName(IClassicError, 'name',
+ self.presentation_type)
view_text = 'You made a classic error ;-)'
- ztapi.provideView(IClassicError, self.presentation_type, Interface,
- 'name', lambda obj,request: lambda: view_text)
+ def _view(obj, request):
+ return lambda: view_text
+ component.provideAdapter(
+ _view, (ClassicError, self.presentation_type), Interface,
+ name='name')
try:
raise ClassicError
except:
@@ -341,7 +353,8 @@
class IConflictError(Interface):
pass
classImplements(ConflictError, IConflictError)
- ztapi.provideAdapter(IConflictError, IExceptionSideEffects, factory)
+ component.provideAdapter(factory, (IConflictError,),
+ IExceptionSideEffects)
exception = ConflictError()
try:
raise exception
@@ -385,7 +398,7 @@
def testAbortTransactionWithErrorReportingUtility(self):
# provide our fake error reporting utility
- zope.component.provideUtility(ErrorReportingUtility())
+ component.provideUtility(ErrorReportingUtility())
class FooError(Exception):
pass
@@ -403,7 +416,7 @@
self.assertEqual(last_txn_info, new_txn_info)
# instead, we expect a message in our logging utility
- error_log = zope.component.getUtility(IErrorReportingUtility)
+ error_log = component.getUtility(IErrorReportingUtility)
self.assertEqual(len(error_log.exceptions), 1)
error_info, request = error_log.exceptions[0]
self.assertEqual(error_info[0], FooError)
@@ -415,7 +428,7 @@
# been experienced) transaction.abort fails, we really want to know
# what happened before that abort.
# (Set up:)
- zope.component.provideUtility(ErrorReportingUtility())
+ component.provideUtility(ErrorReportingUtility())
abort = transaction.abort
class AbortError(Exception):
pass
@@ -439,7 +452,7 @@
else:
self.fail('Aborting should have failed')
# we expect a message in our logging utility
- error_log = zope.component.getUtility(IErrorReportingUtility)
+ error_log = component.getUtility(IErrorReportingUtility)
self.assertEqual(len(error_log.exceptions), 1)
error_info, request = error_log.exceptions[0]
self.assertEqual(error_info[0], AnEarlierError)
@@ -456,8 +469,8 @@
# Replace the global registry with a stub that doesn't return an
# unauthenticated principal.
authentication = AuthUtility3()
- ztapi.provideUtility(IAuthentication, authentication)
-
+ component.provideUtility(authentication, IAuthentication)
+
# We need a fallback unauthenticated principal, otherwise we'll get a
# ComponentLookupError:
self.assertRaises(ComponentLookupError,
@@ -465,7 +478,8 @@
# Let's register an unauthenticated principal instance for the lookup:
principal = UnauthenticatedPrincipal('fallback')
- ztapi.provideUtility(IFallbackUnauthenticatedPrincipal, principal)
+ component.provideUtility(principal, IFallbackUnauthenticatedPrincipal)
+
self.publication.beforeTraversal(self.request)
self.failUnless(self.request.principal is principal)
@@ -490,9 +504,10 @@
from zope.app.container.interfaces import ISimpleReadContainer
from zope.app.container.traversal import ContainerTraverser
- ztapi.provideView(ISimpleReadContainer, IRequest, IPublishTraverse,
- '', 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))
@@ -550,8 +565,8 @@
from zope.location.interfaces import ILocation
from zope.traversing.interfaces import IPhysicallyLocatable
from zope.traversing.interfaces import IContainmentRoot
- ztapi.provideAdapter(ILocation, IPhysicallyLocatable,
- LocationPhysicallyLocatable)
+ component.provideAdapter(LocationPhysicallyLocatable,
+ (ILocation,), IPhysicallyLocatable)
def get_txn_info():
if hasattr(self.storage, 'iterator'):
@@ -598,9 +613,10 @@
set = []
clear = []
- ztapi.subscribe([IBeforeTraverseEvent], None, set.append)
- ztapi.subscribe([IEndRequestEvent], None, clear.append)
+ component.provideHandler(set.append, (IBeforeTraverseEvent,))
+ component.provideHandler(clear.append, (IEndRequestEvent,))
+
ob = object()
# This should fire the BeforeTraverseEvent
More information about the checkins
mailing list