[Zope3-checkins] CVS: Zope3/src/zope/app/component/tests - test_contentdirective.py:1.15 test_directives.py:1.27 test_factory.py:1.10 test_servicedirective.py:1.12

Stephan Richter srichter at cosmos.phy.tufts.edu
Mon Mar 8 07:07:06 EST 2004


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

Modified Files:
	test_contentdirective.py test_directives.py test_factory.py 
	test_servicedirective.py 
Log Message:


Adjusted code to use the new APIs for permissions and principals. Also, use
the utility service instead of the permission registry to look up permissions.




=== Zope3/src/zope/app/component/tests/test_contentdirective.py 1.14 => 1.15 ===
--- Zope3/src/zope/app/component/tests/test_contentdirective.py:1.14	Fri Mar  5 17:08:59 2004
+++ Zope3/src/zope/app/component/tests/test_contentdirective.py	Mon Mar  8 07:05:55 2004
@@ -15,19 +15,17 @@
 
 $Id$
 """
-
 import unittest
 from StringIO import StringIO
 
 import zope.app.security
 import zope.app.component
 
+from zope.app import zapi
 from zope.component.exceptions import ComponentLookupError
 from zope.configuration.xmlconfig import xmlconfig, XMLConfig
 from zope.app.tests.placelesssetup import PlacelessSetup
 from zope.security.management import newSecurityManager, system_user
-from zope.app.security.exceptions import UndefinedPermissionError
-from zope.component import getService
 from zope.app.services.servicenames import Factories
 from zope.app.component.interface import queryInterface
 
@@ -153,7 +151,7 @@
 </content>
                        """)
         xmlconfig(f)
-        factory = getService(None, Factories).getFactory('Example')
+        factory = zapi.getService(None, Factories).getFactory('Example')
         self.assertEquals(factory.title, "Example content")
         self.assertEquals(factory.description, "Example description")
 
@@ -170,7 +168,7 @@
 </content>
                        """)
         xmlconfig(f)
-        fservice = getService(None, Factories)
+        fservice = zapi.getService(None, Factories)
         self.assertRaises(ComponentLookupError, fservice.getFactory, 'Example')
         factory = fservice.getFactory('zope.app.component.tests.exampleclass.ExampleClass')
         self.assertEquals(factory.title, "Example content")
@@ -190,8 +188,7 @@
     />
 </content>
             """)
-        self.assertRaises(UndefinedPermissionError, xmlconfig, f,
-                          testing=1)
+        self.assertRaises(ValueError, xmlconfig, f, testing=1)
 
 
     def testFactoryPublicPermission(self):
@@ -209,7 +206,7 @@
 </content>
             """)
         xmlconfig(f)
-        factory = getService(None, Factories).getFactory('Example')
+        factory = zapi.getService(None, Factories).getFactory('Example')
         self.assert_(hasattr(factory, '__Security_checker__'))
 
 


=== Zope3/src/zope/app/component/tests/test_directives.py 1.26 => 1.27 ===
--- Zope3/src/zope/app/component/tests/test_directives.py:1.26	Sat Mar  6 12:48:47 2004
+++ Zope3/src/zope/app/component/tests/test_directives.py	Mon Mar  8 07:05:55 2004
@@ -11,40 +11,36 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
+"""Component Directives Tests
 
+$Id$
+"""
+import re
 import unittest
+import pprint
 from cStringIO import StringIO
 
+from zope.interface import Interface, implements
+from zope.testing.doctestunit import DocTestSuite
+from zope.app.component.metaconfigure import interface
+from zope.app.content.interfaces import IContentType
+
 from zope.configuration.xmlconfig import xmlconfig, XMLConfig
 from zope.configuration.exceptions import ConfigurationError
-from zope.app.security.exceptions import UndefinedPermissionError
 
 from zope.proxy import getProxiedObject
 from zope.security.proxy import getTestProxyItems
 
 import zope.app.component
 from zope.component.exceptions import ComponentLookupError
-from zope.component import getView, queryView, queryResource
-from zope.component import createObject
-from zope.component import getDefaultViewName
-from zope.component import getNamedAdapter, queryNamedAdapter
-from zope.component import getUtility, queryUtility
 
+from zope.app import zapi
 from zope.app.tests.placelesssetup import PlacelessSetup
 from zope.app.component.tests.views import IV, IC, V1, VZMI, R1, RZMI, IR
 from zope.component.tests.request import Request
-from zope.interface import implements
 from zope.security.checker import ProxyFactory
 
 
-import re
-import pprint
-
-from zope.interface import Interface
-from zope.testing.doctestunit import DocTestSuite
-from zope.app.component.metaconfigure import interface
-from zope.app.content.interfaces import IContentType
-
 atre = re.compile(' at [0-9a-fA-Fx]+')
 
 class Context:
@@ -131,7 +127,7 @@
 
         self.testAdapter()
         self.assertEqual(IApp(Content()).__class__, Comp)
-        self.assertEqual(queryNamedAdapter(Content(), IV, 'test'),
+        self.assertEqual(zapi.queryNamedAdapter(Content(), IV, 'test'),
                          None)
 
         xmlconfig(StringIO(template % (
@@ -145,8 +141,9 @@
             """
             )))
 
-        self.assertEqual(getNamedAdapter(Content(), IApp, "test").__class__,
-                         Comp)
+        self.assertEqual(
+            zapi.getNamedAdapter(Content(), IApp, "test").__class__,
+            Comp)
 
     def testProtectedAdapter(self):
 
@@ -182,15 +179,14 @@
               />
             """
             ))
-        self.assertRaises(UndefinedPermissionError, xmlconfig, config,
-                          testing=1)
+        self.assertRaises(ValueError, xmlconfig, config, testing=1)
 
     def testUtility(self):
 
         # Full import is critical!
         from zope.component.tests.components import IApp, comp
 
-        self.assertEqual(queryUtility(None, IV, None), None)
+        self.assertEqual(zapi.queryUtility(None, IV, None), None)
 
         xmlconfig(StringIO(template % (
             """
@@ -201,7 +197,7 @@
             """
             )))
 
-        self.assertEqual(getUtility(None, IApp), comp)
+        self.assertEqual(zapi.getUtility(None, IApp), comp)
 
     def testNamedUtility(self):
 
@@ -210,7 +206,7 @@
 
         self.testUtility()
 
-        self.assertEqual(queryUtility(None, IV, None, name='test'), None)
+        self.assertEqual(zapi.queryUtility(None, IV, None, name='test'), None)
 
         xmlconfig(StringIO(template % (
             """
@@ -222,14 +218,14 @@
             """
             )))
 
-        self.assertEqual(getUtility(None, IApp, "test"), comp)
+        self.assertEqual(zapi.getUtility(None, IApp, "test"), comp)
 
     def testUtilityFactory(self):
 
         # Full import is critical!
         from zope.component.tests.components import IApp, Comp
 
-        self.assertEqual(queryUtility(None, IV, None), None)
+        self.assertEqual(zapi.queryUtility(None, IV, None), None)
 
         xmlconfig(StringIO(template % (
             """
@@ -240,14 +236,14 @@
             """
             )))
 
-        self.assertEqual(getUtility(None, IApp).__class__, Comp)
+        self.assertEqual(zapi.getUtility(None, IApp).__class__, Comp)
 
     def testProtectedUtility(self):
 
         # Full import is critical!
         from zope.component.tests.components import IApp, comp
 
-        self.assertEqual(queryUtility(None, IV, None), None)
+        self.assertEqual(zapi.queryUtility(None, IV, None), None)
 
         xmlconfig(StringIO(template % (
             """
@@ -259,7 +255,7 @@
             """
             )))
 
-        utility = ProxyFactory(getUtility(None, IApp))
+        utility = ProxyFactory(zapi.getUtility(None, IApp))
         items = [item[0] for item in getTestProxyItems(utility)]
         self.assertEqual(items, ['a', 'f'])
         self.assertEqual(getProxiedObject(utility), comp)
@@ -274,14 +270,14 @@
               />
             """
             ))
-        self.assertRaises(UndefinedPermissionError, xmlconfig, config,
+        self.assertRaises(ValueError, xmlconfig, config,
                           testing=1)
 
 
     def testView(self):
 
         ob = Ob()
-        self.assertEqual(queryView(ob, 'test', Request(IV), None), None)
+        self.assertEqual(zapi.queryView(ob, 'test', Request(IV), None), None)
 
         xmlconfig(StringIO(template %
             """
@@ -292,13 +288,14 @@
             """
             ))
 
-        self.assertEqual(queryView(ob, 'test', Request(IV), None).__class__,
-                         V1)
+        self.assertEqual(
+            zapi.queryView(ob, 'test', Request(IV), None).__class__,
+            V1)
 
     def testViewThatProvidesAnInterface(self):
 
         ob = Ob()
-        self.assertEqual(queryView(ob, 'test', Request(IV), None), None)
+        self.assertEqual(zapi.queryView(ob, 'test', Request(IV), None), None)
 
         xmlconfig(StringIO(template %
             """
@@ -310,7 +307,7 @@
             """
             ))
 
-        v = queryView(ob, 'test', Request(IR), None, providing=IV)
+        v = zapi.queryView(ob, 'test', Request(IR), None, providing=IV)
         self.assertEqual(v, None)
 
         xmlconfig(StringIO(template %
@@ -324,7 +321,7 @@
             """
             ))
 
-        v = queryView(ob, 'test', Request(IR), None, providing=IV)
+        v = zapi.queryView(ob, 'test', Request(IR), None, providing=IV)
 
         self.assertEqual(v.__class__,
                          V1)
@@ -332,7 +329,7 @@
     def testUnnamedViewThatProvidesAnInterface(self):
 
         ob = Ob()
-        self.assertEqual(queryView(ob, '', Request(IV), None), None)
+        self.assertEqual(zapi.queryView(ob, '', Request(IV), None), None)
 
         xmlconfig(StringIO(template %
             """
@@ -343,7 +340,7 @@
             """
             ))
 
-        v = queryView(ob, '', Request(IR), None, providing=IV)
+        v = zapi.queryView(ob, '', Request(IR), None, providing=IV)
         self.assertEqual(v, None)
 
         xmlconfig(StringIO(template %
@@ -356,7 +353,7 @@
             """
             ))
 
-        v = queryView(ob, '', Request(IR), None, providing=IV)
+        v = zapi.queryView(ob, '', Request(IR), None, providing=IV)
 
         self.assertEqual(v.__class__, V1)
 
@@ -373,7 +370,7 @@
             """
             ))
 
-        v = ProxyFactory(getView(Ob(), 'test', Request(IV)))
+        v = ProxyFactory(zapi.getView(Ob(), 'test', Request(IV)))
         self.assertEqual(v.index(), 'V1 here')
         self.assertRaises(Exception, getattr, v, 'action')
 
@@ -390,7 +387,7 @@
             """
             ))
 
-        v = ProxyFactory(getView(Ob(), 'test', Request(IV)))
+        v = ProxyFactory(zapi.getView(Ob(), 'test', Request(IV)))
         self.assertEqual(v.action(), 'done')
         self.assertRaises(Exception, getattr, v, 'index')
 
@@ -408,7 +405,7 @@
             """
             ))
 
-        v = getView(Ob(), 'test', Request(IV))
+        v = zapi.getView(Ob(), 'test', Request(IV))
         self.assertEqual(v.index(), 'V1 here')
         self.assertEqual(v.action(), 'done')
 
@@ -426,7 +423,7 @@
             """
             ))
 
-        v = getView(Ob(), 'test', Request(IV))
+        v = zapi.getView(Ob(), 'test', Request(IV))
         self.assertEqual(v.index(), 'V1 here')
         self.assertEqual(v.action(), 'done')
 
@@ -458,15 +455,14 @@
                   />
             """
             ))
-        self.assertRaises(UndefinedPermissionError, xmlconfig, config,
-                          testing=1)
+        self.assertRaises(ValueError, xmlconfig, config, testing=1)
 
 
 
     def testDefaultView(self):
 
         ob = Ob()
-        self.assertEqual(queryView(ob, 'test', Request(IV), None), None)
+        self.assertEqual(zapi.queryView(ob, 'test', Request(IV), None), None)
 
         xmlconfig(StringIO(template % (
             """
@@ -477,14 +473,15 @@
             """
             )))
 
-        self.assertEqual(queryView(ob, 'test', Request(IV), None).__class__,
-                         V1)
-        self.assertEqual(getDefaultViewName(ob, Request(IV)), 'test')
+        self.assertEqual(
+            zapi.queryView(ob, 'test', Request(IV), None).__class__,
+            V1)
+        self.assertEqual(zapi.getDefaultViewName(ob, Request(IV)), 'test')
 
     def testDefaultViewOnly(self):
 
         ob = Ob()
-        self.assertEqual(queryView(ob, 'test', Request(IV), None), None)
+        self.assertEqual(zapi.queryView(ob, 'test', Request(IV), None), None)
 
         xmlconfig(StringIO(template % (
             """
@@ -494,13 +491,13 @@
             """
             )))
 
-        self.assertEqual(queryView(ob, 'test', Request(IV), None), None)
-        self.assertEqual(getDefaultViewName(ob, Request(IV)), 'test')
+        self.assertEqual(zapi.queryView(ob, 'test', Request(IV), None), None)
+        self.assertEqual(zapi.getDefaultViewName(ob, Request(IV)), 'test')
 
     def testSkinView(self):
 
         ob = Ob()
-        self.assertEqual(queryView(ob, 'test', Request(IV), None), None)
+        self.assertEqual(zapi.queryView(ob, 'test', Request(IV), None), None)
 
         xmlconfig(StringIO(template % (
             """
@@ -518,16 +515,18 @@
             """
             )))
 
-        self.assertEqual(queryView(ob, 'test', Request(IV), None).__class__,
-                         V1)
         self.assertEqual(
-            queryView(ob, 'test', Request(IV, 'zmi'), None).__class__,
+            zapi.queryView(ob, 'test', Request(IV), None).__class__,
+            V1)
+        self.assertEqual(
+            zapi.queryView(ob, 'test', Request(IV, 'zmi'), None).__class__,
             VZMI)
 
     def testResource(self):
 
         ob = Ob()
-        self.assertEqual(queryResource(ob, 'test', Request(IV), None), None)
+        self.assertEqual(
+            zapi.queryResource(ob, 'test', Request(IV), None), None)
         xmlconfig(StringIO(template % (
             """
             <resource name="test"
@@ -536,14 +535,15 @@
             """
             )))
 
-        self.assertEqual(queryResource(ob, 'test', Request(IV), None
-                                       ).__class__,
+        self.assertEqual(zapi.queryResource(ob, 'test', Request(IV), None
+                                            ).__class__,
                          R1)
 
     def testResourceThatProvidesAnInterface(self):
 
         ob = Ob()
-        self.assertEqual(queryResource(ob, 'test', Request(IV), None), None)
+        self.assertEqual(
+            zapi.queryResource(ob, 'test', Request(IV), None), None)
 
         xmlconfig(StringIO(template %
             """
@@ -555,7 +555,7 @@
             """
             ))
 
-        v = queryResource(ob, 'test', Request(IR), None, providing=IV)
+        v = zapi.queryResource(ob, 'test', Request(IR), None, providing=IV)
         self.assertEqual(v, None)
 
         xmlconfig(StringIO(template %
@@ -569,14 +569,14 @@
             """
             ))
 
-        v = queryResource(ob, 'test', Request(IR), None, providing=IV)
+        v = zapi.queryResource(ob, 'test', Request(IR), None, providing=IV)
 
         self.assertEqual(v.__class__, R1)
 
     def testUnnamedResourceThatProvidesAnInterface(self):
 
         ob = Ob()
-        self.assertEqual(queryResource(ob, '', Request(IV), None), None)
+        self.assertEqual(zapi.queryResource(ob, '', Request(IV), None), None)
 
         xmlconfig(StringIO(template %
             """
@@ -587,7 +587,7 @@
             """
             ))
 
-        v = queryResource(ob, '', Request(IR), None, providing=IV)
+        v = zapi.queryResource(ob, '', Request(IR), None, providing=IV)
         self.assertEqual(v, None)
 
         xmlconfig(StringIO(template %
@@ -600,7 +600,7 @@
             """
             ))
 
-        v = queryResource(ob, '', Request(IR), None, providing=IV)
+        v = zapi.queryResource(ob, '', Request(IR), None, providing=IV)
 
         self.assertEqual(v.__class__, R1)
 
@@ -614,14 +614,14 @@
                   permission="zope.UndefinedPermission"/>
             """
             ))
-        self.assertRaises(UndefinedPermissionError, xmlconfig, config,
-                          testing=1)
+        self.assertRaises(ValueError, xmlconfig, config, testing=1)
 
 
     def testSkinResource(self):
 
         ob = Ob()
-        self.assertEqual(queryResource(ob, 'test', Request(IV), None), None)
+        self.assertEqual(
+            zapi.queryResource(ob, 'test', Request(IV), None), None)
 
         xmlconfig(StringIO(template % (
             """
@@ -638,15 +638,15 @@
             )))
 
         self.assertEqual(
-            queryResource(ob, 'test', Request(IV), None).__class__,
+            zapi.queryResource(ob, 'test', Request(IV), None).__class__,
             R1)
         self.assertEqual(
-            queryResource(ob, 'test', Request(IV, 'zmi'), None).__class__,
+            zapi.queryResource(ob, 'test', Request(IV, 'zmi'), None).__class__,
             RZMI)
 
     def testFactory(self):
 
-        self.assertRaises(ComponentLookupError, createObject, None, 'foo')
+        self.assertRaises(ComponentLookupError, zapi.createObject, None, 'foo')
 
         xmlconfig(StringIO(template % (
             """
@@ -658,7 +658,7 @@
             )))
 
         from zope.component.tests.factory import X
-        self.assertEqual(createObject(None, 'foo').__class__, X)
+        self.assertEqual(zapi.createObject(None, 'foo').__class__, X)
 
 def test_suite():
     return unittest.TestSuite((


=== Zope3/src/zope/app/component/tests/test_factory.py 1.9 => 1.10 ===
--- Zope3/src/zope/app/component/tests/test_factory.py:1.9	Wed Feb 25 18:02:23 2004
+++ Zope3/src/zope/app/component/tests/test_factory.py	Mon Mar  8 07:05:55 2004
@@ -18,10 +18,12 @@
 
 from zope.configuration.xmlconfig import xmlconfig
 from zope.configuration.xmlconfig import XMLConfig
+from zope.proxy import removeAllProxies
 from zope.app.services.servicenames import Factories
 from zope.app.tests.placelesssetup import PlacelessSetup
 from zope.security.management import newSecurityManager, system_user
 
+from zope.app import zapi
 import zope.app.security
 import zope.app.component
 
@@ -43,9 +45,7 @@
         XMLConfig('meta.zcml', zope.app.security)()
 
     def testFactory(self):
-        from zope.component import getService
-        from zope.proxy import removeAllProxies
-        f = configfile("""
+        f = configfile('''
 <permission id="zope.Foo" title="Zope Foo Permission" />
 <content class="zope.app.component.tests.exampleclass.ExampleClass">
     <factory
@@ -54,10 +54,9 @@
       title="Example content"
       description="Example description"
        />
-</content>
-                       """)
+</content>''')
         xmlconfig(f)
-        obj = getService(None, Factories).createObject('Example')
+        obj = zapi.getService(None, Factories).createObject('Example')
         obj = removeAllProxies(obj)
         self.failUnless(isinstance(obj, ExampleClass))
 


=== Zope3/src/zope/app/component/tests/test_servicedirective.py 1.11 => 1.12 ===
--- Zope3/src/zope/app/component/tests/test_servicedirective.py:1.11	Thu Nov 27 08:59:17 2003
+++ Zope3/src/zope/app/component/tests/test_servicedirective.py	Mon Mar  8 07:05:55 2004
@@ -11,7 +11,10 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
+"""Service Directive Tests
 
+$Id$
+"""
 import unittest
 from cStringIO import StringIO
 
@@ -157,7 +160,7 @@
               <directive name="permission"
                  attributes="id title description"
                  handler="
-              zope.app.security.registries.metaconfigure.definePermission" />
+              zope.app.security.metaconfigure.definePermission" />
             </directives>
 
             <permission id="zope.TestPermission" title="Test permission" />




More information about the Zope3-Checkins mailing list