[Zope3-checkins] CVS: Zope3/src/zope/app/component/tests - test_directives.py:1.31

Mark McEahern mark at mceahern.com
Mon Mar 22 12:44:51 EST 2004


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

Modified Files:
	test_directives.py 
Log Message:


Added tests for subscriber directive.


=== Zope3/src/zope/app/component/tests/test_directives.py 1.30 => 1.31 ===
--- Zope3/src/zope/app/component/tests/test_directives.py:1.30	Sat Mar 20 12:10:57 2004
+++ Zope3/src/zope/app/component/tests/test_directives.py	Mon Mar 22 12:44:50 2004
@@ -24,6 +24,7 @@
 from zope.testing.doctestunit import DocTestSuite
 from zope.app.component.metaconfigure import interface
 from zope.app.content.interfaces import IContentType
+from zope.app.event.interfaces import ISubscriber
 
 from zope.configuration.xmlconfig import xmlconfig, XMLConfig
 from zope.configuration.exceptions import ConfigurationError
@@ -99,7 +100,59 @@
         super(Test, self).setUp()
         XMLConfig('meta.zcml', zope.app.component)()
         XMLConfig('meta.zcml', zope.app.security)()
-        
+
+    def testSubscriber(self):
+        from zope.app.component.tests.adapter import A1, A2, A3, I3
+        from zope.component.tests.components import Content
+
+        xmlconfig(StringIO(template % (
+            """
+            <subscriber
+              factory="zope.app.component.tests.adapter.A3"
+              for="zope.component.tests.components.IContent
+                   zope.app.component.tests.adapter.I1"
+              />
+            """
+            )))
+
+        content = Content()
+        a1 = A1()
+        subscribers = zapi.subscribers((content, a1), ISubscriber)
+
+        a3 = subscribers[0]
+
+        self.assertEqual(a3.__class__, A3)
+        self.assertEqual(a3.context, (content, a1))
+
+    def testMultiSubscriber(self):
+        from zope.app.component.tests.adapter import A1, A2, A3, I3
+        from zope.component.tests.components import Content
+
+        xmlconfig(StringIO(template % (
+            """
+            <subscriber
+              factory="zope.app.component.tests.adapter.A3"
+              for="zope.component.tests.components.IContent
+                   zope.app.component.tests.adapter.I1"
+              />
+            <subscriber
+              factory="zope.app.component.tests.adapter.A2"
+              for="zope.component.tests.components.IContent
+                   zope.app.component.tests.adapter.I1"
+              />
+            """
+            )))
+
+        content = Content()
+        a1 = A1()
+        subscribers = zapi.subscribers((content, a1), ISubscriber)
+
+        expectedLength = 2
+        self.assertEqual(len(subscribers), expectedLength)
+        classesNotFound = [A2, A3]
+        for a in subscribers:
+            classesNotFound.remove(a.__class__)
+        self.failIf(classesNotFound)
 
     def testAdapter(self):
         # Full import is critical!
@@ -186,7 +239,7 @@
         a2 = A2()
         a3 = zapi.queryMultiAdapter((content, a1, a2), I3)
         self.assertEqual(a3.__class__, A3)
-        self.assertEqual(a3.context, (content, a1, a2))        
+        self.assertEqual(a3.context, (content, a1, a2))
 
     def testNullAdapter(self):
         from zope.app.component.tests.adapter import A3, I3




More information about the Zope3-Checkins mailing list