[Zope-Checkins] CVS: Zope3/lib/python/Zope/ComponentArchitecture/tests - testDirectives.py:1.1.2.5

Jim Fulton jim@zope.com
Mon, 4 Mar 2002 13:53:57 -0500


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

Modified Files:
      Tag: Zope-3x-branch
	testDirectives.py 
Log Message:
Added factory directive.

Fixed bug in provideFactory that caused instances that implemented
IFactory independent of the class to be rejected.


=== Zope3/lib/python/Zope/ComponentArchitecture/tests/testDirectives.py 1.1.2.4 => 1.1.2.5 ===
 from Zope.ComponentArchitecture.tests.TestViews import \
      IV, IC, V1, VZMI, R1, RZMI
-from Zope.ComponentArchitecture import getView, getResource
+from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
+from Zope.ComponentArchitecture import getView, getResource, createObject
 from cStringIO import StringIO
 from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
 from Zope.ComponentArchitecture import getDefaultViewName
@@ -157,10 +158,36 @@
         self.assertEqual(
             getResource(ob, 'test', IV, None, skin='zmi').__class__,
             RZMI)
+
+    def testFactory(self):
+
+        self.assertRaises(ComponentLookupError, createObject, None, 'foo')
+
+        xmlconfig(StringIO(template % (
+            """
+            <directive name="facory"
+                       attributes="component, factory_id"
+               handler="Zope.ComponentArchitecture.metaConfigure.factory"
+               namespace="http://namespaces.zope.org/zope" />
+            <facory 
+               factory_id="foo"
+               component="Zope.ComponentArchitecture.tests.TestFactory.f"
+               />
+            <facory 
+               component="Zope.ComponentArchitecture.tests.TestFactory.f"
+               />
+            """
+            ))) 
+
+        from Zope.ComponentArchitecture.tests.TestFactory import X
+        self.assertEqual(createObject(None, 'foo').__class__, X)
+        self.assertEqual(createObject(
+            None,
+            'Zope.ComponentArchitecture.tests.TestFactory.f').__class__, X)
     
 def test_suite():
     loader=unittest.TestLoader()
     return loader.loadTestsFromTestCase(Test)
-
 if __name__=='__main__':
     unittest.TextTestRunner().run(test_suite())
+