[Zope3-checkins] CVS: Zope3/src/zope/app/component/tests -
factory.py:1.1 test_contentdirective.py:1.16
test_directives.py:1.28 test_factory.py:1.11
Stephan Richter
srichter at cosmos.phy.tufts.edu
Tue Mar 9 07:39:26 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/component/tests
In directory cvs.zope.org:/tmp/cvs-serv10344/src/zope/app/component/tests
Modified Files:
test_contentdirective.py test_directives.py test_factory.py
Added Files:
factory.py
Log Message:
Removed the permission attribute from the two factoy directives. All factories
are public now. This was discussed recently on the mailing list and Jim okayed
it.
=== Added File Zope3/src/zope/app/component/tests/factory.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: factory.py,v 1.1 2004/03/09 12:39:25 srichter Exp $
"""
from zope.component.interfaces import IFactory
from zope.interface import Interface, implements, implementedBy
class IX(Interface):
"""the dummy interface which class X supposedly implements,
according to the factory"""
class IFoo(Interface):
"""an even more dummy interface just for testing """
class X:
implements(IX)
def __init__(self, *args, **kwargs):
self.args=args
self.kwargs=kwargs
class ClassFactoryWrapper:
implements(IFactory)
def __init__(self, klass):
self.__klass=klass
def __call__(self, *args, **kwargs):
return self.__klass(*args, **kwargs)
def getInterfaces(self):
return implementedBy(self.__klass)
f=ClassFactoryWrapper(X)
=== Zope3/src/zope/app/component/tests/test_contentdirective.py 1.15 => 1.16 ===
--- Zope3/src/zope/app/component/tests/test_contentdirective.py:1.15 Mon Mar 8 07:05:55 2004
+++ Zope3/src/zope/app/component/tests/test_contentdirective.py Tue Mar 9 07:39:25 2004
@@ -22,11 +22,11 @@
import zope.app.component
from zope.app import zapi
+from zope.component.interfaces import IFactory
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.services.servicenames import Factories
from zope.app.component.interface import queryInterface
# explicitly import ExampleClass and IExample using full paths
@@ -144,14 +144,13 @@
<content class="zope.app.component.tests.exampleclass.ExampleClass">
<factory
id="Example"
- permission="zope.Foo"
title="Example content"
description="Example description"
/>
</content>
""")
xmlconfig(f)
- factory = zapi.getService(None, Factories).getFactory('Example')
+ factory = zapi.getUtility(None, IFactory, 'Example')
self.assertEquals(factory.title, "Example content")
self.assertEquals(factory.description, "Example description")
@@ -161,52 +160,34 @@
<content class="zope.app.component.tests.exampleclass.ExampleClass">
<factory
- permission="zope.Foo"
title="Example content"
description="Example description"
/>
</content>
""")
xmlconfig(f)
- fservice = zapi.getService(None, Factories)
- self.assertRaises(ComponentLookupError, fservice.getFactory, 'Example')
- factory = fservice.getFactory('zope.app.component.tests.exampleclass.ExampleClass')
+ self.assertRaises(ComponentLookupError, zapi.getUtility,
+ None, IFactory, 'Example')
+ factory = zapi.getUtility(
+ None, IFactory,
+ 'zope.app.component.tests.exampleclass.ExampleClass')
self.assertEquals(factory.title, "Example content")
self.assertEquals(factory.description, "Example description")
- def testFactoryUndefinedPermission(self):
-
- f = configfile("""
-<permission id="zope.Foo" title="Zope Foo Permission" />
-
-<content class="zope.app.component.tests.exampleclass.ExampleClass">
- <factory
- id="Example"
- permission="zope.UndefinedPermission"
- title="Example content"
- description="Example description"
- />
-</content>
- """)
- self.assertRaises(ValueError, xmlconfig, f, testing=1)
-
def testFactoryPublicPermission(self):
f = configfile("""
-<permission id="zope.Foo" title="Zope Foo Permission" />
-
<content class="zope.app.component.tests.exampleclass.ExampleClass">
<factory
id="Example"
- permission="zope.Public"
title="Example content"
description="Example description"
/>
</content>
""")
xmlconfig(f)
- factory = zapi.getService(None, Factories).getFactory('Example')
+ factory = zapi.getUtility(None, IFactory, 'Example')
self.assert_(hasattr(factory, '__Security_checker__'))
=== Zope3/src/zope/app/component/tests/test_directives.py 1.27 => 1.28 ===
--- Zope3/src/zope/app/component/tests/test_directives.py:1.27 Mon Mar 8 07:05:55 2004
+++ Zope3/src/zope/app/component/tests/test_directives.py Tue Mar 9 07:39:25 2004
@@ -546,27 +546,27 @@
zapi.queryResource(ob, 'test', Request(IV), None), None)
xmlconfig(StringIO(template %
- """
+ '''
<resource
name="test"
factory="zope.app.component.tests.views.R1"
type="zope.app.component.tests.views.IR"
/>
- """
+ '''
))
v = zapi.queryResource(ob, 'test', Request(IR), None, providing=IV)
self.assertEqual(v, None)
xmlconfig(StringIO(template %
- """
+ '''
<resource
name="test"
factory="zope.app.component.tests.views.R1"
type="zope.app.component.tests.views.IR"
provides="zope.app.component.tests.views.IV"
/>
- """
+ '''
))
v = zapi.queryResource(ob, 'test', Request(IR), None, providing=IV)
@@ -579,25 +579,25 @@
self.assertEqual(zapi.queryResource(ob, '', Request(IV), None), None)
xmlconfig(StringIO(template %
- """
+ '''
<resource
factory="zope.app.component.tests.views.R1"
type="zope.app.component.tests.views.IR"
/>
- """
+ '''
))
v = zapi.queryResource(ob, '', Request(IR), None, providing=IV)
self.assertEqual(v, None)
xmlconfig(StringIO(template %
- """
+ '''
<resource
factory="zope.app.component.tests.views.R1"
type="zope.app.component.tests.views.IR"
provides="zope.app.component.tests.views.IV"
/>
- """
+ '''
))
v = zapi.queryResource(ob, '', Request(IR), None, providing=IV)
@@ -607,12 +607,12 @@
def testResourceUndefinedPermission(self):
config = StringIO(template % (
- """
+ '''
<resource name="test"
factory="zope.app.component.tests.views.R1"
type="zope.app.component.tests.views.IV"
permission="zope.UndefinedPermission"/>
- """
+ '''
))
self.assertRaises(ValueError, xmlconfig, config, testing=1)
@@ -624,7 +624,7 @@
zapi.queryResource(ob, 'test', Request(IV), None), None)
xmlconfig(StringIO(template % (
- """
+ '''
<layer name="zmi" />
<skin name="zmi" layers="zmi default" />
<resource name="test"
@@ -634,7 +634,7 @@
<resource name="test"
factory="zope.app.component.tests.views.R1"
type="zope.app.component.tests.views.IV"/>
- """
+ '''
)))
self.assertEqual(
@@ -649,15 +649,15 @@
self.assertRaises(ComponentLookupError, zapi.createObject, None, 'foo')
xmlconfig(StringIO(template % (
- """
+ '''
<factory
id="foo"
- component="zope.component.tests.factory.f"
+ component="zope.app.component.tests.factory.f"
/>
- """
+ '''
)))
- from zope.component.tests.factory import X
+ from factory import X
self.assertEqual(zapi.createObject(None, 'foo').__class__, X)
def test_suite():
=== Zope3/src/zope/app/component/tests/test_factory.py 1.10 => 1.11 ===
--- Zope3/src/zope/app/component/tests/test_factory.py:1.10 Mon Mar 8 07:05:55 2004
+++ Zope3/src/zope/app/component/tests/test_factory.py Tue Mar 9 07:39:25 2004
@@ -11,15 +11,17 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-""" Test handler for 'factory' subdirective of 'content' directive """
+""" Test handler for 'factory' subdirective of 'content' directive
+$Id$
+"""
import unittest
from cStringIO import StringIO
from zope.configuration.xmlconfig import xmlconfig
from zope.configuration.xmlconfig import XMLConfig
+from zope.component import createObject
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
@@ -50,13 +52,12 @@
<content class="zope.app.component.tests.exampleclass.ExampleClass">
<factory
id="Example"
- permission="zope.Foo"
title="Example content"
description="Example description"
/>
</content>''')
xmlconfig(f)
- obj = zapi.getService(None, Factories).createObject('Example')
+ obj = createObject(None, 'Example')
obj = removeAllProxies(obj)
self.failUnless(isinstance(obj, ExampleClass))
More information about the Zope3-Checkins
mailing list