[Zope3-checkins] CVS: Zope3/src/zope/app/services/tests - test_pagefolder.py:1.8.6.2 iregistry.py:1.2.6.1 test_auth.py:1.19.6.1 test_eventservice.py:1.28.6.1 test_objecthub.py:1.13.6.1 test_principalannotation.py:1.8.30.1 test_registrationstack.py:1.3.6.1 test_surrogates.py:1.1.2.3

Jim Fulton cvs-admin at zope.org
Tue Nov 18 17:27:18 EST 2003


Update of /cvs-repository/Zope3/src/zope/app/services/tests
In directory cvs.zope.org:/tmp/cvs-serv19243/src/zope/app/services/tests

Modified Files:
      Tag: adaptergeddon-branch
	iregistry.py test_auth.py test_eventservice.py 
	test_objecthub.py test_principalannotation.py 
	test_registrationstack.py test_surrogates.py 
Added Files:
      Tag: adaptergeddon-branch
	test_pagefolder.py 
Log Message:
Implemented local presentation services.


=== Zope3/src/zope/app/services/tests/test_pagefolder.py 1.8.6.1 => 1.8.6.2 ===
--- /dev/null	Tue Nov 18 17:27:08 2003
+++ Zope3/src/zope/app/services/tests/test_pagefolder.py	Tue Nov 18 17:26:37 2003
@@ -0,0 +1,118 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Page folder tests.
+
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from zope.app import zapi
+from zope.app.tests import setup
+from zope.app.services.tests.placefulsetup import PlacefulSetup
+from zope.app.services.pagefolder import PageFolder, IPageFolder
+from zope.app.services.zpt import ZPTTemplate
+from zope.app.services.presentation import LocalPresentationService
+from zope.app.interfaces.services.registration import ActiveStatus
+from zope.interface import Interface
+from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.app.services.tests.test_registrationmanager \
+     import RegistrationManagerContainerTests
+from zope.component.servicenames import Presentation
+
+class I(Interface):
+    pass
+
+class I2(Interface):
+    pass
+
+class Test(RegistrationManagerContainerTests, PlacefulSetup, TestCase):
+
+    def setUp(self):
+        sm = PlacefulSetup.setUp(self, site=True)
+        zapi.getService(None, Presentation).defineLayer('debug')
+        setup.addService(sm, Presentation, LocalPresentationService(),
+                         suffix='service')
+        default = zapi.traverse(self.rootFolder, '++etc++site/default')
+        default["PF"] = PageFolder()
+        pagefolder = zapi.traverse(default, "PF")
+        pagefolder.required = I
+        pagefolder.factoryName = None
+        pagefolder.permission = 'zope.View'
+
+        self.__pagefolder = pagefolder
+
+    def test___setitem__(self):
+
+        pagefolder = self.__pagefolder
+
+        pagefolder['foo.html'] = ZPTTemplate()
+
+        rm = pagefolder.getRegistrationManager()
+        name = rm.keys()[-1]
+        registration = zapi.traverse(pagefolder.getRegistrationManager(), name)
+        self.assertEqual(registration.status, ActiveStatus)
+        self.assertEqual(registration.required, I)
+        self.assertEqual(registration.requestType, IBrowserRequest)
+        self.assertEqual(registration.name, u'foo.html')
+        self.assertEqual(registration.layer, 'default')
+        self.assertEqual(registration.factoryName, None)
+        self.assertEqual(registration.permission, 'zope.View')
+        self.assertEqual(registration.attribute, None)
+
+        self.assertRaises(TypeError,
+                          pagefolder.__setitem__, 'bar.html', PageFolder())
+
+    def test_applyDefaults(self):
+
+        pagefolder = self.__pagefolder
+
+        pagefolder['foo.html'] = ZPTTemplate()
+
+        rm = pagefolder.getRegistrationManager()
+        name = rm.keys()[-1]
+        registration = zapi.traverse(pagefolder.getRegistrationManager(), name)
+        self.assertEqual(registration.status, ActiveStatus)
+        self.assertEqual(registration.required, I)
+        self.assertEqual(registration.requestType, IBrowserRequest)
+        self.assertEqual(registration.name, u'foo.html')
+        self.assertEqual(registration.layer, 'default')
+        self.assertEqual(registration.factoryName, None)
+        self.assertEqual(registration.permission, 'zope.View')
+        self.assertEqual(registration.attribute, None)
+
+        pagefolder.required = I2
+        pagefolder.permission = 'zope.ManageContent'
+        pagefolder.layer = 'debug'
+
+        pagefolder.applyDefaults()
+
+        registration = zapi.traverse(pagefolder.getRegistrationManager(), name)
+        self.assertEqual(registration.status, ActiveStatus)
+        self.assertEqual(registration.required, I2)
+        self.assertEqual(registration.requestType, IBrowserRequest)
+        self.assertEqual(registration.name, u'foo.html')
+        self.assertEqual(registration.layer, 'debug')
+        self.assertEqual(registration.factoryName, None)
+        self.assertEqual(registration.permission, 'zope.ManageContent')
+        self.assertEqual(registration.attribute, None)
+
+        
+
+def test_suite():
+    return TestSuite((
+        makeSuite(Test),
+        ))
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')


=== Zope3/src/zope/app/services/tests/iregistry.py 1.2 => 1.2.6.1 ===
--- Zope3/src/zope/app/services/tests/iregistry.py:1.2	Sun Sep 21 13:31:13 2003
+++ Zope3/src/zope/app/services/tests/iregistry.py	Tue Nov 18 17:26:37 2003
@@ -19,6 +19,7 @@
 """
 from zope.app.interfaces.services.registration import IRegistry
 from zope.interface.verify import verifyObject
+from zope.app.location import inside
 
 class TestingIRegistry:
     """Base class for testing implementors of IRegistry
@@ -43,8 +44,7 @@
         have some context.
 
         """
-        self.assertEqual(ob.__parent__, parent)
-        self.failIf(ob.__parent__.__parent__ is None)
+        self.assert_(inside(ob, parent))
 
     def test_implements_IRegistry(self):
         verifyObject(IRegistry, self.createTestingRegistry())
@@ -63,13 +63,13 @@
         registration = self.createTestingRegistration()
         stack = registry.createRegistrationsFor(registration)
 
-        self.assertEqual(stack.__parent__, registry)
+        self.assert_(inside(stack, registry))
 
         # If we call it again, we should get the same object
         self.assertEqual(registry.createRegistrationsFor(registration),
                          stack)
 
-        self._assertInContext(stack, registry)
+        self.assert_(inside(stack, registry))
 
         return stack
 


=== Zope3/src/zope/app/services/tests/test_auth.py 1.19 => 1.19.6.1 ===
--- Zope3/src/zope/app/services/tests/test_auth.py:1.19	Sun Sep 21 13:30:46 2003
+++ Zope3/src/zope/app/services/tests/test_auth.py	Tue Nov 18 17:26:37 2003
@@ -28,6 +28,7 @@
 from zope.app.container.tests.test_icontainer import BaseTestIContainer
 from zope.interface import implements
 from zope.app.tests import setup
+from zope.app.tests import ztapi
 
 class Request:
 
@@ -52,7 +53,7 @@
         from zope.component import getService
         from zope.app.security.basicauthadapter import BasicAuthAdapter
         from zope.app.interfaces.security import ILoginPassword
-        getService(None, Adapters).provideAdapter(
+        ztapi.provideAdapter(
             IHTTPCredentials, ILoginPassword, BasicAuthAdapter)
 
         sm = traverse(self.rootFolder, '++etc++site')


=== Zope3/src/zope/app/services/tests/test_eventservice.py 1.28 => 1.28.6.1 ===
--- Zope3/src/zope/app/services/tests/test_eventservice.py:1.28	Sun Sep 21 13:33:15 2003
+++ Zope3/src/zope/app/services/tests/test_eventservice.py	Tue Nov 18 17:26:37 2003
@@ -37,7 +37,7 @@
 from zope.app.interfaces.services.registration import RegisteredStatus
 from zope.app.services.tests.eventsetup import EventSetup
 from zope.component.tests.components import RecordingAdapter
-from zope.component.adapter import provideAdapter
+from zope.app.tests import ztapi
 from zope.app.interfaces.services.service import ISimpleService
 from zope.app.services.event import EventService
 from zope.app.tests import setup
@@ -922,9 +922,9 @@
 
     def testSubscriptionAwareInteraction(self):
         adapter = SubscribingAwareAdapter()
-        provideAdapter(IHasSubscribingAwareAdapter,
-                       ISubscribingAware,
-                       adapter)
+        ztapi.provideAdapter(IHasSubscribingAwareAdapter,
+                             ISubscribingAware,
+                             adapter)
         self.rootFolder["mySubscriber"] = HasSubscribingAwareAdapter()
         self.mySubscriber = self.rootFolder["mySubscriber"]
         filter = DummyFilter()


=== Zope3/src/zope/app/services/tests/test_objecthub.py 1.13 => 1.13.6.1 ===
--- Zope3/src/zope/app/services/tests/test_objecthub.py:1.13	Sun Sep 21 13:33:15 2003
+++ Zope3/src/zope/app/services/tests/test_objecthub.py	Tue Nov 18 17:26:37 2003
@@ -18,6 +18,7 @@
 """
 
 import unittest
+from zope.app.tests import ztapi
 from zope.app import zapi
 from zope.app.services.tests.objecthubsetup import ObjectHubSetup
 
@@ -235,8 +236,7 @@
                 else:
                     return Traverser.traverse(self, location, *args, **kw)
 
-        from zope.component.adapter import provideAdapter
-        provideAdapter(None, ITraverser, DummyTraverser)
+        ztapi.provideAdapter(None, ITraverser, DummyTraverser)
 
         object_hub = self.object_hub
         location_hubid_object = [(location,


=== Zope3/src/zope/app/services/tests/test_principalannotation.py 1.8 => 1.8.30.1 ===
--- Zope3/src/zope/app/services/tests/test_principalannotation.py:1.8	Sat Jun  7 01:32:01 2003
+++ Zope3/src/zope/app/services/tests/test_principalannotation.py	Tue Nov 18 17:26:37 2003
@@ -24,7 +24,7 @@
      PrincipalAnnotationService, AnnotationsForPrincipal
 from zope.app.interfaces.services.principalannotation import \
      IPrincipalAnnotationService
-from zope.component.adapter import provideAdapter
+from zope.app.tests import ztapi
 from zope.component import getAdapter
 from zope.app.interfaces.annotation import IAnnotations
 from zope.app.interfaces.security import IPrincipal
@@ -100,8 +100,8 @@
 
     def testAdapter(self):
         p = Principal('somebody')
-        provideAdapter(IPrincipal, IAnnotations,
-                       AnnotationsForPrincipal(self.svc))
+        ztapi.provideAdapter(IPrincipal, IAnnotations,
+                             AnnotationsForPrincipal(self.svc))
         annotations = getAdapter(p, IAnnotations)
         annotations["test"] = "bar"
         annotations = getAdapter(p, IAnnotations)


=== Zope3/src/zope/app/services/tests/test_registrationstack.py 1.3 => 1.3.6.1 ===
--- Zope3/src/zope/app/services/tests/test_registrationstack.py:1.3	Sun Sep 21 13:33:24 2003
+++ Zope3/src/zope/app/services/tests/test_registrationstack.py	Tue Nov 18 17:26:37 2003
@@ -26,11 +26,17 @@
 class Registration:
 
     active = 0
+    registry = None
 
     def activated(self):
+        if (self.registry is not None) and (self.registry.active() != self):
+            raise AssertionError("Told active but not the active registration")
         self.active += 1
 
     def deactivated(self):
+        if (self.registry is not None) and (self.registry.active() == self):
+            raise AssertionError(
+                "Told deactivated but still the active registration")
         self.active -= 1
 
 
@@ -53,6 +59,7 @@
 
         self.failIf(registry)
         self.__c1 = c1 = self.__config("1")
+        c1.registry = registry
         registry.register(c1)
         self.failUnless(registry)
         self.failUnless(registry.registered(c1))
@@ -61,6 +68,7 @@
         self.assertEqual(registry.active(), None)
 
         self.__c2 = c2 = self.__config("2")
+        c2.registry = registry
         self.failIf(registry.registered(c2))
         registry.register(c2)
         self.failUnless(registry)


=== Zope3/src/zope/app/services/tests/test_surrogates.py 1.1.2.2 => 1.1.2.3 ===
--- Zope3/src/zope/app/services/tests/test_surrogates.py:1.1.2.2	Thu Nov 13 12:32:58 2003
+++ Zope3/src/zope/app/services/tests/test_surrogates.py	Tue Nov 18 17:26:37 2003
@@ -728,14 +728,171 @@
     >>> db.close()
     """
 
+
+def test_local_default():
+    """
+    >>> G = SurrogateRegistry()
+    >>> L1 = LocalSurrogateRegistry(G)
+    >>> r = Registration(required = None, provided=IB1, factory=Adapter)
+    >>> L1.createRegistrationsFor(r).activate(r)
+    >>> f2 = F2()
+    >>> L1.queryAdapter(f2, IB1).__class__.__name__
+    'Adapter'
+    """
+
+
+def test_changing_next():
+    """
+    >>> G = SurrogateRegistry()
+    >>> L1 = LocalSurrogateRegistry(G)
+    >>> L2 = LocalSurrogateRegistry(G, L1)
+    >>> f2 = F2()
+
+    >>> L2.queryAdapter(f2, IB1).__class__.__name__
+    'NoneType'
+
+    >>> G.provideAdapter(IF1, IB1, [A11G])
+    >>> L2.queryAdapter(f2, IB1).__class__.__name__
+    'A11G'
+
+
+    >>> class A111(Adapter):
+    ...     pass
+    >>> ra111 = Registration(required = IF1, provided=IB1, factory=A111)
+    >>> L1.createRegistrationsFor(ra111).activate(ra111)
+    >>> L2.queryAdapter(f2, IB1).__class__.__name__
+    'A111'
+
+    >>> L1.next
+    >>> L2.next == L1
+    True
+    >>> L1.subs == (L2,)
+    True
+    >>> L3 = LocalSurrogateRegistry(G, L1)
+    >>> L2.setNext(L3)
+    >>> L2.next == L3
+    True
+    >>> L3.next == L1
+    True
+    >>> L1.subs == (L3,)
+    True
+    >>> L3.subs == (L2,)
+    True
+
+    >>> class A113(Adapter):
+    ...     pass
+    >>> ra113 = Registration(required = IF1, provided=IB1, factory=A113)
+    >>> L3.createRegistrationsFor(ra113).activate(ra113)
+
+    >>> L2.queryAdapter(f2, IB1).__class__.__name__
+    'A113'
+    >>> L2.setNext(L1)
+    >>> L2.next == L1
+    True
+    >>> L3.next == L1
+    True
+    >>> L1.subs == (L3, L2)
+    True
+    >>> L3.subs == ()
+    True
+    >>> L2.queryAdapter(f2, IB1).__class__.__name__
+    'A111'
+
+    """
+
+def test_LocalSurrogateBasedService():
+    """
+    Setup folders and service managers:
+    
+    >>> from zope.app.tests import setup
+    >>> setup.placefulSetUp()
+    >>> root = setup.buildSampleFolderTree()
+    >>> sm = setup.createServiceManager(root)
+    >>> sm1 = setup.createServiceManager(root['folder1'])
+    >>> sm1_1 = setup.createServiceManager(root['folder1']['folder1_1'])
+    >>> sm1_1_1 = setup.createServiceManager(
+    ...                         root['folder1']['folder1_1']['folder1_1_1'])
+
+    Define the service
+
+    >>> gsm = zapi.getServiceManager(None)
+    >>> gsm.defineService('F', IF1)
+
+    Create the global service
+
+    >>> g = F2()
+    >>> gsm.provideService('F', g)
+
+    Create a local service class, which must define setNext:
+
+    >>> import zope.app.interfaces.services.service
+    >>> class LocalF(LocalSurrogateBasedService):
+    ...     zope.interface.implements(
+    ...         IF2,
+    ...         zope.app.interfaces.services.service.ISimpleService,
+    ...         )
+    ...     def setNext(self, next, global_):
+    ...         self.next, self.global_ = next, global_
+
+    If we add a local service, It gets it's next and global_ attrs set:
+
+    >>> f1 = LocalF()
+    >>> hasattr(f1, 'next') or hasattr(f1, 'global_')
+    False
+    >>> setup.addService(sm1, 'F', f1) is f1
+    True
+    >>> (f1.next, f1.global_) == (None, g)
+    True
+
+    If we add another service below, it's next will point to the one
+    above:
+    
+    >>> f1_1_1 = LocalF()
+    >>> setup.addService(sm1_1_1, 'F', f1_1_1) is f1_1_1
+    True
+    >>> (f1_1_1.next, f1_1_1.global_) == (f1, g)
+    True
+
+    We can insert a service in an intermediate site:
+    
+    >>> f1_1 = LocalF()
+    >>> setup.addService(sm1_1, 'F', f1_1) is f1_1
+    True
+    >>> (f1_1.next, f1_1.global_) == (f1, g)
+    True
+    >>> (f1_1_1.next, f1_1_1.global_) == (f1_1, g)
+    True
+
+    Deactivating services adjust the relevant next pointers
+
+    >>> default = zapi.traverse(sm1_1, 'default')
+    >>> rm = default.getRegistrationManager()
+    >>> rm.values()[0].status = RegisteredStatus
+    >>> (f1_1_1.next, f1_1_1.global_) == (f1, g)
+    True
+
+    >>> default = zapi.traverse(sm1, 'default')
+    >>> rm = default.getRegistrationManager()
+    >>> rm.values()[0].status = RegisteredStatus
+    >>> (f1_1_1.next, f1_1_1.global_) == (None, g)
+    True
+    
+    >>> setup.placefulTearDown()
+    """
+
+
+
 import unittest
 from zope.testing.doctestunit import DocTestSuite
 from zope.interface.surrogate import SurrogateRegistry
 from zope.app.services.surrogate import LocalSurrogateRegistry
+from zope.app.services.surrogate import LocalSurrogateBasedService
 import zope.interface
 from zodb.storage.memory import MemoryFullStorage
 from zodb.db import DB
 from transaction import get_transaction
+from zope.app import zapi
+from zope.app.interfaces.services.registration import RegisteredStatus
 
 class IF0(zope.interface.Interface):
     pass
@@ -797,8 +954,13 @@
     
     def __init__(self, **kw):
         self.__dict__.update(kw)
-    def __call__(self, *args):
-        return self.factory(*args)
+
+    def __repr__(self):
+        return "<Registration %s>" % self.__dict__
+
+    def factories(self):
+        return self.factory,
+    factories = property(factories)
 
 # Create a picklable global registry. The pickleability of other
 # global surrogate registries is beyond the scope of these tests:




More information about the Zope3-Checkins mailing list