[Zope-Checkins] CVS: Zope3/lib/python/Zope/ComponentArchitecture/tests - TestComponents.py:1.1.4.1 Request.py:1.1.2.4 TestViews.py:1.1.2.4 testAPI.py:1.1.2.16 testResources.py:1.1.2.6 testSkins.py:1.1.2.11 testViewDefinitions.py:1.1.2.5 testDirectives.py:NONE
Jim Fulton
jim@zope.com
Fri, 7 Jun 2002 10:41:53 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/ComponentArchitecture/tests
In directory cvs.zope.org:/tmp/cvs-serv12187/lib/python/Zope/ComponentArchitecture/tests
Modified Files:
Tag: Zope-3x-branch
Request.py TestViews.py testAPI.py testResources.py
testSkins.py testViewDefinitions.py
Added Files:
Tag: Zope-3x-branch
TestComponents.py
Removed Files:
Tag: Zope-3x-branch
testDirectives.py
Log Message:
Merging in Zope3InWonderland-branch, which implemented the following
proposals (see
http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/OldProposals):
- RenameAllowToRequire
- GroupClassRelatedDirectivesInClassDirective
- ViewInterfaceAndSimplification
- ConsistentUseOfSpacesAsDelimitersInZCMLAttributes
- TwoArgumentViewConstructors
- ImplementsInZCML
- SimpleViewCreationInZCML
- RemoveGetView
- ReplaceProtectWithAllow
- ViewMethodsAsViews
- MergeProtectionAndComponentDefinitions
There were also various security fixes resulting of better integration
of security with components.
=== Added File Zope3/lib/python/Zope/ComponentArchitecture/tests/TestComponents.py ===
##############################################################################
#
# Copyright (c) 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: TestComponents.py,v 1.1.4.1 2002/06/07 14:41:22 jim Exp $
"""
__metaclass__ = type # All classes are new style when run with Python 2.2+
from Interface import Interface
from Interface.Attribute import Attribute
class IApp(Interface):
a = Attribute('test attribute')
def f(): "test func"
class IContent(Interface): pass
class Content: __implements__ = IContent
class Comp:
__used_for__ = IContent
__implements__ = IApp
a=1
def f(): pass
comp = Comp()
=== Zope3/lib/python/Zope/ComponentArchitecture/tests/Request.py 1.1.2.3 => 1.1.2.4 ===
class Request:
- def __init__(self,iface, skin):
+ def __init__(self, iface, skin='default'):
self._iface = iface
self._skin = skin
# Implementation methods for interface
- # Zope.ComponentArchitecture.IViewService.IViewRequest
+ # Zope.ComponentArchitecture.IPresentationService.IPresentationRequest
- def getViewSkin(self):
- '''See interface IViewRequest'''
+ def getPresentationSkin(self):
+ '''See interface IPresentationRequest'''
return self._skin
- def getViewType(self):
- '''See interface IViewRequest'''
+ def getPresentationType(self):
+ '''See interface IPresentationRequest'''
return self._iface
=== Zope3/lib/python/Zope/ComponentArchitecture/tests/TestViews.py 1.1.2.3 => 1.1.2.4 ===
from Interface import Interface
-class IV(Interface): pass
+
+class IV(Interface):
+ def index(): pass
+
class IC(Interface): pass
class V1:
__implements__ = IV
- def __init__(self,context):
+ def __init__(self,context, request):
self._context = context
+ def index(self): return 'V1 here'
+
+ def action(self): return 'done'
+
class VZMI(V1):
- pass
+ def index(self): return 'ZMI here'
class R1:
- __implements__ = IV
-r1 = R1()
+ def index(self): return 'R1 here'
+
+ def action(self): return 'R done'
+
+ def __init__(self, request):
+ pass
+
+ __implements__ = IV
class RZMI(R1):
pass
-rZMI = RZMI()
=== Zope3/lib/python/Zope/ComponentArchitecture/tests/testAPI.py 1.1.2.15 => 1.1.2.16 ===
##############################################################################
import unittest, sys, Interface
+from Request import Request
class I1(Interface.Interface): pass
class I2(Interface.Interface): pass
class I3(Interface.Interface): pass
class Comp:
__implements__ = I2
- def __init__(self, context): self._context = context
- def getContext(self): return self._context
+ def __init__(self, context, request=None): self.context = context
class Comp2:
__implements__ = I3
- def __init__(self, context): self._context = context
- def getContext(self): return self._context
+ def __init__(self, context, request=None): self.context = context
comp = Comp(1)
@@ -31,13 +30,15 @@
__implements__ = I1
ob = Ob()
+
from PlacelessSetup import PlacelessSetup
class Test(PlacelessSetup, unittest.TestCase):
def testAdapter(self):
- from Zope.ComponentArchitecture import getAdapter, getService
+ from Zope.ComponentArchitecture \
+ import getAdapter, getService, queryAdapter
from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
# if an object implements the interface you want to adapt to,
@@ -49,12 +50,12 @@
self.assertRaises(ComponentLookupError, getAdapter, ob, I2)
# ...otherwise, you get the default
- self.assertEquals(getAdapter(ob, I2, Test), Test)
+ self.assertEquals(queryAdapter(ob, I2, Test), Test)
getService(None, 'Adapters').provideAdapter(I1, I2, Comp)
c = getAdapter(ob, I2)
self.assertEquals(c.__class__, Comp)
- self.assertEquals(c.getContext(), ob)
+ self.assertEquals(c.context, ob)
def testMultipleAdapterFactories(self):
from Zope.ComponentArchitecture import getAdapter, getService
@@ -64,7 +65,7 @@
getService(None, 'Adapters').provideAdapter(I1, I2, [Comp2, Comp])
c = getAdapter(ob, I2)
self.assertEquals(c.__class__, Comp)
- self.assertEquals(c.getContext().getContext(), ob)
+ self.assertEquals(c.context.context, ob)
def testAdapterForInterfaceNone(self):
from Zope.ComponentArchitecture import getAdapter, getService
@@ -74,39 +75,42 @@
getService(None, 'Adapters').provideAdapter(None, I2, Comp)
c = getAdapter(ob, I2)
self.assertEquals(c.__class__, Comp)
- self.assertEquals(c.getContext(), ob)
+ self.assertEquals(c.context, ob)
def testUtility(self):
- from Zope.ComponentArchitecture import getUtility, getService
+ from Zope.ComponentArchitecture import getUtility, queryUtility
+ from Zope.ComponentArchitecture import getService
from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
self.assertRaises(ComponentLookupError, getUtility, ob, I1)
self.assertRaises(ComponentLookupError, getUtility, ob, I2)
- self.assertEquals(getUtility(ob, I2, Test), Test)
+ self.assertEquals(queryUtility(ob, I2, Test), Test)
getService(None, 'Utilities').provideUtility(I2, comp)
self.assertEquals(id(getUtility(ob, I2)), id(comp))
def testView(self):
- from Zope.ComponentArchitecture import getView, getService
+ from Zope.ComponentArchitecture import getView, queryView, getService
from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
- self.assertRaises(ComponentLookupError, getView, ob, 'foo', I1)
- self.assertRaises(ComponentLookupError, getView, ob, 'foo', I2)
- self.assertEquals(getView(ob, 'foo', I2, Test), Test)
+ self.assertRaises(ComponentLookupError,
+ getView, ob, 'foo', Request(I1))
+ self.assertRaises(ComponentLookupError,
+ getView, ob, 'foo', Request(I2))
+ self.assertEquals(queryView(ob, 'foo', Request(I2), Test), Test)
- getService(None, 'Views').provideView(I1, 'foo', I2, Comp)
- c = getView(ob, 'foo', I2)
+ getService(None, 'Views').provideView(I1, 'foo', I2, [Comp])
+ c = getView(ob, 'foo', Request(I2))
self.assertEquals(c.__class__, Comp)
- self.assertEquals(c.getContext(), ob)
+ self.assertEquals(c.context, ob)
self.assertRaises(ComponentLookupError,
- getView, ob, 'foo2', I1)
+ getView, ob, 'foo2', Request(I1))
self.assertRaises(ComponentLookupError,
- getView, ob, 'foo2', I2)
- self.assertEquals(getView(ob, 'foo2', I2, Test), Test)
+ getView, ob, 'foo2', Request(I2))
+ self.assertEquals(queryView(ob, 'foo2', Request(I2), Test), Test)
- self.assertEquals(getView( ob, 'foo2', I1, None), None)
+ self.assertEquals(queryView( ob, 'foo2', Request(I1), None), None)
def testDefaultViewName(self):
from Zope.ComponentArchitecture import getService
@@ -114,13 +118,13 @@
viewService = getService(None, 'Views')
self.assertRaises(NotFoundError,
viewService.getDefaultViewName,
- ob, I1)
+ ob, Request(I1))
viewService.setDefaultViewName(I1, I2, 'sample_name')
- self.assertEquals(viewService.getDefaultViewName(ob, I2),
+ self.assertEquals(viewService.getDefaultViewName(ob, Request(I2)),
'sample_name')
self.assertRaises(NotFoundError,
viewService.getDefaultViewName,
- ob, I1)
+ ob, Request(I1))
def test_suite():
=== Zope3/lib/python/Zope/ComponentArchitecture/tests/testResources.py 1.1.2.5 => 1.1.2.6 ===
from Zope.ComponentArchitecture import getService
from PlacelessSetup import PlacelessSetup
-from Zope.ComponentArchitecture import getResource
-from Zope.ComponentArchitecture import getRequestResource
+from Zope.ComponentArchitecture import getResource, queryResource
from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
from Interface import Interface
from Request import Request
@@ -30,45 +29,52 @@
def testSkin(self):
class I2(Interface): pass
- class C1: __implements__ = I2
+ class C1:
+ def __init__(self, request): pass
+ __implements__ = I2
class C2(C1): pass
- getService(None,'Resources').provideResource('test', I2, C1())
- self.assertEqual(getResource(None, 'test', I2).__class__, C1)
- getService(None,'Skins').defineSkin('foo', I2, ('foo', ''))
- self.assertEqual(getResource(None, 'test', I2, skin='foo').__class__,
- C1)
- getService(None,'Resources').provideResource('test', I2, C2(),
- layer='foo')
- self.assertEqual(getResource(None, 'test', I2, skin='foo').__class__,
- C2)
+ getService(None,'Resources').provideResource('test', I2, C1)
+ self.assertEqual(getResource(None, 'test', Request(I2)).__class__, C1)
+ getService(None,'Skins').defineSkin('foo', I2, ('foo', 'default'))
+ self.assertEqual(
+ getResource(None, 'test', Request(I2, 'foo')).__class__,
+ C1)
+ getService(None,'Resources').provideResource('test', I2, C2,
+ layer='foo')
+ self.assertEqual(
+ getResource(None, 'test', Request(I2, 'foo')).__class__,
+ C2)
def testGetRequestResourceMethod(self):
class I2(Interface): pass
- class C1: __implements__ = I2
+ class C1:
+ def __init__(self, request): pass
+
+ __implements__ = I2
class C2(C1): pass
- getService(None,'Resources').provideResource('test', I2, C1())
+ getService(None,'Resources').provideResource('test', I2, C1)
self.assertEqual(
- getRequestResource(None, 'test', Request(I2, '') ).__class__,
+ getResource(None, 'test', Request(I2, 'default') ).__class__,
C1)
- getService(None,'Skins').defineSkin('foo', I2, ('foo', ''))
+ getService(None,'Skins').defineSkin('foo', I2, ('foo', 'default'))
self.assertEqual(
- getRequestResource(None, 'test', Request(I2, 'foo')).__class__,
+ getResource(None, 'test', Request(I2, 'foo')).__class__,
C1)
- getService(None,'Resources').provideResource('test', I2, C2(),
- layer='foo')
+ getService(None,'Resources').provideResource('test', I2, C2,
+ layer='foo')
self.assertEqual(
- getRequestResource(None, 'test', Request(I2, 'foo')).__class__,
+ getResource(None, 'test', Request(I2, 'foo')).__class__,
C2)
self.assertRaises(
ComponentLookupError,
- getRequestResource, None, 'test2', Request(I2, 'foo'))
+ getResource, None, 'test2', Request(I2, 'foo'))
self.assertEqual(
- getRequestResource(None, 'test2', Request(I2, 'foo'), None),
+ queryResource(None, 'test2', Request(I2, 'foo'), None),
None)
def test_suite():
=== Zope3/lib/python/Zope/ComponentArchitecture/tests/testSkins.py 1.1.2.10 => 1.1.2.11 ===
from PlacelessSetup import PlacelessSetup
-from Zope.ComponentArchitecture import getView, getService
-from Zope.ComponentArchitecture import getRequestView
+from Zope.ComponentArchitecture import getView, getService, queryView
from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
from Interface import Interface
from Request import Request
+
class Test(PlacelessSetup, unittest.TestCase):
def testSkin(self):
@@ -29,22 +29,28 @@
class C1:
__implements__ = I2
__used_for__ = I1
- def __init__(self, o): self._context=o
+ def __init__(self, o, request): self._context=o
class C2(C1): pass
class C3(C1): pass
class O: __implements__ = I1
- getService(None, 'Views').provideView(I1, 'test', I2, C1)
- self.assertEqual(getView(O(), 'test', I2).__class__, C1)
- getService(None, 'Skins').defineSkin('foo', I2, ('foo', ''))
- self.assertEqual(getView(O(), 'test', I2, skin='foo').__class__, C1)
- getService(None, 'Views').provideView(None, 'test', I2, C2)
- self.assertEqual(getView(O(), 'test', I2, skin='foo').__class__, C1)
- getService(None, 'Views').provideView(None, 'test', I2, C2, layer='foo')
- self.assertEqual(getView(O(), 'test', I2, skin='foo').__class__, C2)
- getService(None, 'Views').provideView(I1, 'test', I2, C3, layer='foo')
- self.assertEqual(getView(O(), 'test', I2, skin='foo').__class__, C3)
+ getService(None, 'Views').provideView(I1, 'test', I2, [C1])
+ self.assertEqual(getView(O(), 'test', Request(I2)).__class__, C1)
+ getService(None, 'Skins').defineSkin('foo', I2, ('foo', 'default'))
+ self.assertEqual(getView(O(), 'test', Request(I2, 'foo')).__class__,
+ C1)
+ getService(None, 'Views').provideView(None, 'test', I2, [C2])
+ self.assertEqual(getView(O(), 'test', Request(I2, 'foo')).__class__,
+ C1)
+ getService(None, 'Views').provideView(
+ None, 'test', I2, [C2], layer='foo')
+ self.assertEqual(getView(O(), 'test', Request(I2, 'foo')).__class__,
+ C2)
+ getService(None, 'Views').provideView(
+ I1, 'test', I2, [C3], layer='foo')
+ self.assertEqual(getView(O(), 'test', Request(I2, 'foo')).__class__,
+ C3)
@@ -56,38 +62,40 @@
class C1:
__implements__ = I2
__used_for__ = I1
- def __init__(self, o): self._context=o
+ def __init__(self, o, request): self._context=o
class C2(C1): pass
class C3(C1): pass
class O: __implements__ = I1
- getService(None, 'Views').provideView(I1, 'test', I2, C1)
- self.assertEqual(getRequestView(O(), 'test',
+ getService(None, 'Views').provideView(I1, 'test', I2, [C1])
+ self.assertEqual(getView(O(), 'test',
Request(I2,'') ).__class__, C1)
- getService(None, 'Skins').defineSkin('foo', I2, ('foo', ''))
+ getService(None, 'Skins').defineSkin('foo', I2, ('foo', 'default'))
- self.assertEqual(getRequestView(O(), 'test',
+ self.assertEqual(getView(O(), 'test',
Request(I2, 'foo')).__class__, C1)
- getService(None, 'Views').provideView(None, 'test', I2, C2)
+ getService(None, 'Views').provideView(None, 'test', I2, [C2])
- self.assertEqual(getRequestView(O(), 'test',
+ self.assertEqual(getView(O(), 'test',
Request(I2, 'foo')).__class__, C1)
- getService(None, 'Views').provideView(None, 'test', I2, C2, layer='foo')
+ getService(None, 'Views').provideView(
+ None, 'test', I2, [C2], layer='foo')
- self.assertEqual(getRequestView(O(), 'test',
+ self.assertEqual(getView(O(), 'test',
Request(I2, 'foo')).__class__, C2)
- getService(None, 'Views').provideView(I1, 'test', I2, C3, layer='foo')
+ getService(None, 'Views').provideView(
+ I1, 'test', I2, [C3], layer='foo')
- self.assertEqual(getRequestView(O(), 'test',
+ self.assertEqual(getView(O(), 'test',
Request(I2, 'foo')).__class__, C3)
self.assertRaises(ComponentLookupError,
- getRequestView, O(), 'test2', Request(I2, 'foo'))
+ getView, O(), 'test2', Request(I2, 'foo'))
- self.assertEqual(getRequestView(O(), 'test2',
- Request(I2, 'foo'), None), None)
+ self.assertEqual(queryView(O(), 'test2',
+ Request(I2, 'foo'), None), None)
=== Zope3/lib/python/Zope/ComponentArchitecture/tests/testViewDefinitions.py 1.1.2.4 => 1.1.2.5 ===
C.layer = layer
- viewService.provideView(forinterface, name, IV, C,
+ viewService.provideView(forinterface, name, IV, [C],
layer=layer)
for name in ('foo', 'bar', 'baz'):
@@ -53,7 +53,7 @@
C.__used_for__ = IC2
C.layer = layer
C.__implements__ = ViewType
- viewService.provideView(IC2, name, IV, C,
+ viewService.provideView(IC2, name, IV, [C],
layer=layer)
for name in ('foo', 'bar', 'baz'):
@@ -63,7 +63,7 @@
C.__used_for__ = IC
C.layer = layer
C.__implements__ = ViewType
- viewService.provideView(IC, name, IV, C,
+ viewService.provideView(IC, name, IV, [C],
layer=layer)
=== Removed File Zope3/lib/python/Zope/ComponentArchitecture/tests/testDirectives.py ===