[Zope3-checkins] CVS: Zope3/src/zope/app/schema/tests - test_vocabulary.py:1.1.2.4

Fred L. Drake, Jr. fred@zope.com
Thu, 15 May 2003 11:05:28 -0400


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

Modified Files:
      Tag: schema-vocabulary-branch
	test_vocabulary.py 
Log Message:
- add tests that don't pass additional keyword args
- refactor so not so much test harness gets duplicated


=== Zope3/src/zope/app/schema/tests/test_vocabulary.py 1.1.2.3 => 1.1.2.4 ===
--- Zope3/src/zope/app/schema/tests/test_vocabulary.py:1.1.2.3	Thu May 15 10:53:59 2003
+++ Zope3/src/zope/app/schema/tests/test_vocabulary.py	Thu May 15 11:05:27 2003
@@ -17,6 +17,7 @@
 import unittest
 
 from zope.app.schema import vocabulary
+from zope.app.tests.placelesssetup import PlacelessSetup
 from zope.configuration.tests.test_xml import TempFile
 from zope.configuration.xmlconfig import XMLConfig
 
@@ -31,27 +32,20 @@
         self.kw = kw
 
 
-class VocabularyServiceTests(unittest.TestCase):
-
-    def setUp(self):
-        vocabulary._clear()
-
-    def tearDown(self):
-        vocabulary._clear()
+class VocabularyServiceTests(PlacelessSetup, unittest.TestCase):
 
     def test_global_missing_vocabulary(self):
         self.assertRaises(LookupError,
                           vocabulary.vocabularyService.get,
                           None, "missing-vocabulary")
 
-    def check_vocabulary_get(self):
+    def check_vocabulary_get(self, **kw):
         context = object()
         vocab = vocabulary.vocabularyService.get(context, "my-vocab")
         self.assert_(vocab.ob is context)
-        self.assertEqual(vocab.kw, {"filter": "my-filter",
-                                    "another": "keyword"})
+        self.assertEqual(vocab.kw, kw)
 
-    def test_passing_keywords_from_zcml(self):
+    def load_zcml(self, fragment):
         text = """\
         <zopeConfigure xmlns='http://namespaces.zope.org/zope'>
           <include package='zope.configuration' file='metameta.zcml' />
@@ -61,14 +55,9 @@
 
           <include package='zope.app.schema' />
 
-          <vocabulary
-              name='my-vocab'
-              factory='zope.app.schema.tests.test_vocabulary.MyFactory'
-              filter='my-filter'
-              another='keyword'
-              />
+          %s
         </zopeConfigure>
-        """
+        """ % fragment
         f = TempFile()
         try:
             f.write(text)
@@ -77,6 +66,38 @@
             x()
         finally:
             f.close()
+
+    def test_simple_zcml(self):
+        self.load_zcml("""\
+          <vocabulary
+              name='my-vocab'
+              factory='zope.app.schema.tests.test_vocabulary.MyFactory'
+              />""")
+        self.check_vocabulary_get()
+
+    def test_passing_keywords_from_zcml(self):
+        self.load_zcml("""\
+          <vocabulary
+              name='my-vocab'
+              factory='zope.app.schema.tests.test_vocabulary.MyFactory'
+              filter='my-filter'
+              another='keyword'
+              />""")
+        self.check_vocabulary_get(filter="my-filter", another="keyword")
+
+    def test_action_without_keywords(self):
+        # make sure the action machinery works, aside from ZCML concerns
+        actions = vocabulary.register(MyContext(), "my-vocab", ".maker")
+        self.assertEqual(len(actions), 1)
+        descriminator, callable, args, kw = actions[0]
+        # check our expectations of the action:
+        self.assertEqual(len(args), 2)
+        self.assertEqual(args[0], "my-vocab")
+        self.assertEqual(kw, {})
+        self.failIf(isinstance(args[1], vocabulary.FactoryKeywordPasser))
+        # enact the registration:
+        callable(*args, **kw)
+        # make sure the factory behaves as expected:
         self.check_vocabulary_get()
 
     def test_action_with_keywords(self):
@@ -93,7 +114,7 @@
         # enact the registration:
         callable(*args, **kw)
         # make sure the factory behaves as expected:
-        self.check_vocabulary_get()
+        self.check_vocabulary_get(filter="my-filter", another="keyword")
 
 
 def test_suite():