[Zope3-checkins] CVS: Zope3/lib/python/Zope/ComponentArchitecture/tests - testAPI.py:1.3

Jim Fulton jim@zope.com
Wed, 4 Dec 2002 03:39:27 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/ComponentArchitecture/tests
In directory cvs.zope.org:/tmp/cvs-serv1493/tests

Modified Files:
	testAPI.py 
Log Message:
Added the getRegisteredMatching method to support adapter browsing.



=== Zope3/lib/python/Zope/ComponentArchitecture/tests/testAPI.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/ComponentArchitecture/tests/testAPI.py:1.2	Mon Jun 10 19:29:23 2002
+++ Zope3/lib/python/Zope/ComponentArchitecture/tests/testAPI.py	Wed Dec  4 03:39:26 2002
@@ -11,12 +11,14 @@
 # FOR A PARTICULAR PURPOSE.
 # 
 ##############################################################################
-import unittest, sys, Interface
+import unittest, sys
+from Interface import Interface
 from Request import Request
 
-class I1(Interface.Interface): pass
-class I2(Interface.Interface): pass
-class I3(Interface.Interface): pass
+
+class I1(Interface): pass
+class I2(Interface): pass
+class I3(Interface): pass
 class Comp:
     __implements__ = I2
     def __init__(self, context, request=None): self.context = context
@@ -30,7 +32,22 @@
     __implements__ = I1
 
 ob = Ob()
-    
+
+
+class R1(Interface): pass
+class R12(Interface): pass
+class R2(R1): pass
+class R3(R2): pass
+class R4(R3): pass
+
+class P1(Interface): pass
+class P2(P1): pass
+class P3(P2): pass
+class P4(P3): pass
+
+class default_P3: pass
+class any_P3: pass
+class R2_P3: pass
 
 from PlacelessSetup import PlacelessSetup
 
@@ -125,6 +142,151 @@
         self.assertRaises(NotFoundError,
                           viewService.getDefaultViewName,
                           ob, Request(I1))
+
+
+
+
+    # The following tests are copied from
+    # Interface.Registry.tests.IAdapterRegistry
+
+    
+    def __registery(self):
+        from Zope.ComponentArchitecture.GlobalAdapterService \
+             import GlobalAdapterService
+        
+        registry = GlobalAdapterService()
+        
+
+        registry.provideAdapter(None, P3, [default_P3])
+        registry.provideAdapter(Interface, P3, [any_P3])
+        registry.provideAdapter(R2, P3, [R2_P3])
+
+        return registry
+
+
+    def test_getRegisteredMatching_all(self):
+        registry = self.__registery()
+        
+        got = list(registry.getRegisteredMatching())
+        got.sort()
+        expect = [
+            (None, P3, [default_P3]),
+            (Interface, P3, [any_P3]),
+            (R2, P3, [R2_P3]),
+            ]
+        expect.sort()
+        self.assertEqual(got, expect)
+
+    def test_getRegisteredMatching_required_R1(self):
+        registry = self.__registery()
+        
+        got = list(registry.getRegisteredMatching(
+            required_interfaces = (R1, )
+            ))
+        got.sort()
+        expect = [
+            (None, P3, [default_P3]),
+            (Interface, P3, [any_P3]),
+            ]
+        expect.sort()
+        self.assertEqual(got, expect)
+
+    def test_getRegisteredMatching_required_multiple(self):
+        registry = self.__registery()
+        
+        got = list(registry.getRegisteredMatching(
+            required_interfaces = (R12, R2)
+            ))
+        got.sort()
+        expect = [
+            (None, P3, [default_P3]),
+            (Interface, P3, [any_P3]),
+            (R2, P3, [R2_P3]),
+            ]
+        expect.sort()
+        self.assertEqual(got, expect)
+
+    def test_getRegisteredMatching_provided_P1(self):
+        registry = self.__registery()
+        
+        got = list(registry.getRegisteredMatching(
+            provided_interfaces = (P1, )
+            ))
+        got.sort()
+        expect = [
+            (None, P3, [default_P3]),
+            (Interface, P3, [any_P3]),
+            (R2, P3, [R2_P3]),
+            ]
+        expect.sort()
+        self.assertEqual(got, expect)
+
+    def test_getRegisteredMatching_provided_P2(self):
+        registry = self.__registery()
+        
+        got = list(registry.getRegisteredMatching(
+            provided_interfaces = (P3, )
+            ))
+        got.sort()
+        expect = [
+            (None, P3, [default_P3]),
+            (Interface, P3, [any_P3]),
+            (R2, P3, [R2_P3]),
+            ]
+        expect.sort()
+        self.assertEqual(got, expect)
+
+    def test_getRegisteredMatching_required_and_provided_1(self):
+        registry = self.__registery()
+        
+        got = list(registry.getRegisteredMatching(
+            required_interfaces = (R4, R12),
+            provided_interfaces = (P1, ),
+            ))
+        got.sort()
+        expect = [
+            (None, P3, [default_P3]),
+            (Interface, P3, [any_P3]),
+            (R2, P3, [R2_P3]),
+            ]
+        expect.sort()
+        self.assertEqual(got, expect)
+
+    def test_getRegisteredMatching_required_and_provided_2(self):
+        registry = self.__registery()
+        
+        got = list(registry.getRegisteredMatching(
+            required_interfaces = (R4, R12),
+            provided_interfaces = (P3, ),
+            ))
+        got.sort()
+        expect = [
+            (None, P3, [default_P3]),
+            (Interface, P3, [any_P3]),
+            (R2, P3, [R2_P3]),
+            ]
+        expect.sort()
+        self.assertEqual(got, expect)
+        
+
+    def test_getRegisteredMatching_required_and_provided_exact(self):
+        registry = self.__registery()
+        
+        got = list(registry.getRegisteredMatching(
+            required_interfaces = (R2, ),
+            provided_interfaces = (P3, ),
+            ))
+        got.sort()
+        expect = [
+            (None, P3, [default_P3]),
+            (Interface, P3, [any_P3]),
+            (R2, P3, [R2_P3]),
+            ]
+        expect.sort()
+        self.assertEqual(got, expect)
+
+
+
         
 
 def test_suite():