[prev in list] [next in list] [prev in thread] [next in thread] 

List:       zope-cvs
Subject:    [Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/AddableService/tests - AddableSetup.py:1
From:       Gary Poster <garyposter () earthlink ! net>
Date:       2002-04-29 23:20:38
[Download RAW message or body]

Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/AddableService/tests
In directory cvs.zope.org:/tmp/cvs-serv1556/App/OFS/Services/AddableService/tests

Modified Files:
      Tag: Zope-3x-branch
	testAddable.py 
Added Files:
      Tag: Zope-3x-branch
	AddableSetup.py 
Log Message:
ComponentArchitecture reorganization; addition of for_container; addition of \
IWriteContainer.isAddable.

good news: all tests pass; bad news: after the new security system, my changes have \
some problems.  I had to punt on the default contents view of all folders for \
instance--hasServiceManager is causing a problem for some reason I couldn't divine, \
even with Shane's Checker tool.  I commented out the offending code on the \
contents.pt just to keep things up.

I tagged before committing: gary_CA-reorganization

changes more in depth (as I understand it, all or most approved :-) ):

(in ComponentArchitecture:)
 * changing implementation names to Global* (i.e., AdapterService becomes 
GlobalAdapterService) and giving each its own file (many are clumped together 
in hooks.py)
 * removing hooks.py in ComponentArchitecture, putting all functions in appropriate \
                module above (i.e. getAdapter will be in the adapter module)
 * largely removing indirection (_hook) except for getService and 
getNextService
 * changing IServiceService.py to IServiceManager
 * changing Service.py to GlobalServiceManager.py (and class name too)
 * removing "provide*" functions (i.e., provideAdapter, provideUtility, etc.) 
and "defineService" from the __init__.py imports
 * change all global services to classes with appropriate methods as per 
interfaces
 * update all tests 
 * remove all of the "provide*" functions from the interfaces
 * renamed IComponentArchitecture to IPlacefulComponentArchitecture (hereafter IPCA), \
                after long discussion with SteveA 
 * list Resources as one of core CA services in IPlacefulComponentArchitecture
 * build actual IPCA interface, not just import of service interfaces (because we \
                want IPCA to be placeful, but the service interfaces do not need to \
                be)
 * place functions implementing ICA actually in __init__
 * explicitly setting up services in zcml
 * created Global service interfaces, and placed the "provides" and "set" and \
"define" functions there: however, to keep the main interfaces clean and clear, I \
placed these global interfaces in the same file as the global implementations, hoping \
to clarify that these are not reusable interfaces but descriptive, one-time \
                interfaces
 * built PlacefulSetup in Zope.ComponentArchitecture.tests for more specific CleanUp \
(a subclass).  PlacefulSetup is in the tests folder of the local ServiceManager.  \
AddableSetup also is available, in the AddableService tests.

(elsewhere in Zope3)
 * built for_container in addables
 * built isAddable for containers (after discussion with Jim, we decided an addable \
"contains" attribute in the zcml might not be the way to go.  I chose the isAddable \
                approach for a number of reasons)
 * addableservice does some more checks in getting the addable list, pertinent to the \
                above and to whether it can find the appropriate factories
 * a few more tests: a start of one in the local event service, and some more here \
and there

I'm sorry to add to the confusion of the big security changes, but I needed to either \
trash these changes or commit them: I'm a bit out of time for the moment.  If all \
else fails, again, I did tag the previous version.



=== Added File Zope3/lib/python/Zope/App/OFS/Services/AddableService/tests/AddableSetup.py \
=== ##############################################################################
#
# 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.
# 
##############################################################################
"""

Revision information:
$Id: AddableSetup.py,v 1.1.2.1 2002/04/29 23:20:07 poster Exp $
"""

from Zope.App.OFS.ServiceManager.tests.PlacefulSetup import PlacefulSetup

class AddableSetup(PlacefulSetup):
    
    def setUp(self):
        PlacefulSetup.setUp(self)
        from Zope.App.OFS.Services.AddableService.IAddableService import \
           IAddableService
        from Zope.ComponentArchitecture import getServiceManager
        sm=getServiceManager(None)
        defineService=sm.defineService
        provideService=sm.provideService
        defineService('AddableContent',IAddableService)
        defineService('AddableServices',IAddableService)
        from Zope.App.OFS.Services.AddableService.GlobalAddableService import \
           addableContent, addableServices
        provideService('AddableContent',addableContent)
        provideService('AddableServices',addableServices)



=== Zope3/lib/python/Zope/App/OFS/Services/AddableService/tests/testAddable.py \
1.1.2.1 => 1.1.2.2 ===  
 import unittest, sys
+from Zope.ComponentArchitecture import getService
 from Zope.App.OFS.Services.AddableService.Addable import Addable
-from Zope.App.OFS.Services.AddableService.GlobalAddableService import addableContent
-from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
+from Zope.App.OFS.Services.AddableService import getAddableContent, \
+     getAddableServices
+from AddableSetup import AddableSetup
+
+def membership_check(group, item):
+    if type(group) is tuple:
+        for inter in group:
+            if membership_check(inter, item):
+                return 1
+        return 0
+    if type(item) is tuple:
+        for inter in item:
+            if membership_check(group, inter):
+                return 1
+        return 0
+    return group is item or issubclass(item, group)
 
-class Test(CleanUp, unittest.TestCase):
+class Test(AddableSetup, unittest.TestCase):
 
     def testService(self):
 
-        self.assertEqual(addableContent.getAddables(None), [])
+        self.assertEqual(getAddableContent(None), [])
 
-        addableContent.provideAddable('Contact', 'Personal Contact',
+        getService(None, 'AddableContent').provideAddable('Contact', 'Personal \
Contact',  'blah\nblah')
 
-        self.assertEqual(addableContent.getAddables(None), [
+        # you must provide a matching factory for the addable to be returned
+        self.assertEqual(getAddableContent(None), [])
+
+        from Interface import Interface
+        class IA(Interface):
+            pass
+        class A:
+            __implements__=IA
+        from Zope.ComponentArchitecture.tests.TestFactory import ClassFactoryWrapper
+        fA=ClassFactoryWrapper(A)
+        getService(None, 'Factories').provideFactory('Contact', fA)
+
+        self.assertEqual(getAddableContent(None), [
             Addable('Contact', 'Personal Contact', 'blah\nblah'),
             ])
 
-        addableContent.provideAddable('spam', 'junk mail', 'spam\nspam')
+        getService(None, 'Factories').provideFactory('spam', fA)
+        getService(None,'AddableContent').provideAddable('spam', 'junk mail', \
'spam\nspam')  
-        self.assertEqual(addableContent.getAddables(None), [
+        self.assertEqual(getAddableContent(None), [
             Addable('Contact', 'Personal Contact', 'blah\nblah'),
             Addable('spam', 'junk mail', 'spam\nspam'),
-            ])
+            ]) # ought to change to some kind of sort for more robust check
+    
+    def testGetAddable(self):
+        self.buildFolders()
+        from Interface import Interface
+
+        # objects
+
+        class IA(Interface):
+            pass
+        class A:
+            __implements__=IA
+        class IB(Interface):
+            pass
+        class B:
+            __implements__=IB
+        class IBC(IB):
+            pass
+        class C:
+            __implements__=IBC
+        class D:
+            __implements__=(IA, (IBC,))
+        class E:
+            __implements__=IA
+
+        # factories
+        from Zope.ComponentArchitecture.tests.TestFactory import ClassFactoryWrapper
+
+        fA=ClassFactoryWrapper(A)
+        fB=ClassFactoryWrapper(B)
+        fC=ClassFactoryWrapper(C)
+        fD=ClassFactoryWrapper(D)
+        fE=ClassFactoryWrapper(E)
+
+        #containers
+
+        class IX(Interface):
+            pass
+        class IX1(Interface):
+            pass
+        self.folder1.__implements__+= (IX, IX1)
+        class IY(IX):
+            pass
+        self.folder1_1.__implements__+= (IY,)
+        # (the fancy one...)
+        class IZ(Interface):
+            pass
+        from Zope.App.OFS.Folder.Folder import Folder
+        from Zope.ContextWrapper import Wrapper
+        class DummyFolder(Folder):
+            __implements__=Folder.__implements__, (IZ,)
+            def isAddable(self, interfaces):
+                return membership_check(IB, interfaces)
+        self.folder3=DummyFolder()
+        self.rootFolder.setObject("folder3",self.folder3)
+        self.folder3=Wrapper(self.folder3, self.rootFolder, name="folder3")
+        
+        # set up the services with the factories and addables...
+        provideFactory=getService(None, 'Factories').provideFactory
+        provideAddable=getService(None, 'AddableServices').provideAddable
+        provideFactory('A', fA)
+        provideAddable('A', 'Dummy A', 'Desc A', IX) # should be available in 1 and \
1_1 (for_container) +        provideFactory('B', fB)
+        provideAddable('B', 'Dummy B', 'Desc B', (IX1, IZ)) # should be in 1 and 3 \
(for_container) +        provideFactory('C', fC)
+        provideAddable('C', 'DummyC', 'Desc C', IX1) # should be in 1 \
(for_container) +        provideFactory('D', fD)
+        provideAddable('D', 'Dummy D', 'Desc D') # should be in ALL
+        provideFactory('E', fE)
+        provideAddable('E', 'Dummy E', 'Desc E') # should be in 1 and 1_1 \
(isAddable) +        AAd=Addable('A', 'Dummy A', 'Desc A', IX)
+        BAd=Addable('B', 'Dummy B', 'Desc B', (IX1, IZ))
+        CAd=Addable('C', 'DummyC', 'Desc C', IX1)
+        DAd=Addable('D', 'Dummy D', 'Desc D')
+        EAd=Addable('E', 'Dummy E', 'Desc E')
+        
+        # and test!
+        self.assertEqual(getAddableServices(self.folder1),
+                         [AAd, BAd, CAd, DAd, EAd]) # sort for more robust test
+        self.assertEqual(getAddableServices(self.folder1_1),
+                         [AAd, DAd, EAd]) # sort
+        self.assertEqual(getAddableServices(self.folder3),
+                         [BAd, DAd]) # sort
+        
         
     def setAValue(self, add,val):
         add.id=val



_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://lists.zope.org/mailman/listinfo/zope-checkins


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic