[Zope-Checkins] CVS: Zope3/lib/python/Zope/ComponentArchitecture/tests - testResources.py:1.1.2.1 TestViews.py:1.1.2.2 testDirectives.py:1.1.2.2 testSkins.py:1.1.2.7
Jim Fulton
jim@zope.com
Mon, 14 Jan 2002 08:43:22 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/ComponentArchitecture/tests
In directory cvs.zope.org:/tmp/cvs-serv29617/ComponentArchitecture/tests
Modified Files:
Tag: Zope-3x-branch
TestViews.py testDirectives.py testSkins.py
Added Files:
Tag: Zope-3x-branch
testResources.py
Log Message:
Factored skin service from view service.
Made skins type-dependent. IOW, skins for Browsers are different from
skins for FTP.
Added resource components, which are to views as utilities are to
adapters. They provide interface-specific components that do not
extend or depend on some specific other component. Like views, they
are named and are specific to a particulat presentation type.
We nee resources to deal with things like images and style sheets.
Added tests for browser directives.
=== Added File Zope3/lib/python/Zope/ComponentArchitecture/tests/testResources.py ===
##############################################################################
#
# Copyright (c) 2001 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
#
##############################################################################
import unittest, sys
from Zope.ComponentArchitecture import defineSkin, provideResource, getResource, _clear
from Zope.ComponentArchitecture import getRequestResource
from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
from Interface import Interface
from Request import Request
class Test(unittest.TestCase):
def tearDown(self):
_clear()
def testSkin(self):
class I2(Interface): pass
class C1: __implements__ = I2
class C2(C1): pass
provideResource('test', I2, C1())
self.assertEqual(getResource(None, 'test', I2).__class__, C1)
defineSkin('foo', I2, ('foo', ''))
self.assertEqual(getResource(None, 'test', I2, skin='foo').__class__,
C1)
provideResource('test', I2, C2(), layer='foo')
self.assertEqual(getResource(None, 'test', I2, skin='foo').__class__,
C2)
def testGetRequestResourceMethod(self):
class I2(Interface): pass
class C1: __implements__ = I2
class C2(C1): pass
provideResource('test', I2, C1())
self.assertEqual(
getRequestResource(None, 'test', Request(I2, '') ).__class__,
C1)
defineSkin('foo', I2, ('foo', ''))
self.assertEqual(
getRequestResource(None, 'test', Request(I2, 'foo')).__class__,
C1)
provideResource('test', I2, C2(), layer='foo')
self.assertEqual(
getRequestResource(None, 'test', Request(I2, 'foo')).__class__,
C2)
self.assertRaises(
ComponentLookupError,
getRequestResource, None, 'test2', Request(I2, 'foo'))
self.assertEqual(
getRequestResource(None, 'test2', Request(I2, 'foo'), None),
None)
def test_suite():
loader=unittest.TestLoader()
return loader.loadTestsFromTestCase(Test)
if __name__=='__main__':
unittest.TextTestRunner().run(test_suite())
=== Zope3/lib/python/Zope/ComponentArchitecture/tests/TestViews.py 1.1.2.1 => 1.1.2.2 ===
class VZMI(V1):
pass
+
+class R1:
+ __implements__ = IV
+
+r1 = R1()
+
+class RZMI(R1):
+ pass
+
+rZMI = RZMI()
=== Zope3/lib/python/Zope/ComponentArchitecture/tests/testDirectives.py 1.1.2.1 => 1.1.2.2 ===
import unittest, sys
from Zope.Configuration.xmlconfig import xmlconfig
-from Zope.ComponentArchitecture.tests.TestViews import IV, IC, V1, VZMI
-from Zope.ComponentArchitecture import getView, _clear
+from Zope.ComponentArchitecture.tests.TestViews import \
+ IV, IC, V1, VZMI, R1, RZMI
+from Zope.ComponentArchitecture import getView, getResource, _clear
from cStringIO import StringIO
template = """<zopeConfigure
@@ -27,8 +28,6 @@
class Ob:
__implements__ = IC
-
-
class Test(unittest.TestCase):
# XXX: tests for other directives needed
@@ -42,12 +41,16 @@
self.assertEqual(getView(ob, 'test', IV, None), None)
xmlconfig(StringIO(template % (
- '<directive name="view" attributes="component, type, name, for, layer"'
- ' handler="Zope.ComponentArchitecture.metaConfigure.view"'
- ' namespace="http://namespaces.zope.org/zope" />'
- '<view name="test" factory="Zope.ComponentArchitecture.tests.TestViews.V1"'
- ' for="Zope.ComponentArchitecture.tests.TestViews.IC" '
- ' type="Zope.ComponentArchitecture.tests.TestViews.IV"/>'
+ """
+ <directive name="view"
+ attributes="component, type, name, for, layer"
+ handler="Zope.ComponentArchitecture.metaConfigure.view"
+ namespace="http://namespaces.zope.org/zope" />
+ <view name="test"
+ factory="Zope.ComponentArchitecture.tests.TestViews.V1"
+ for="Zope.ComponentArchitecture.tests.TestViews.IC"
+ type="Zope.ComponentArchitecture.tests.TestViews.IV"/>
+ """
)))
self.assertEqual(getView(ob, 'test', IV, None).__class__, V1)
@@ -58,25 +61,81 @@
self.assertEqual(getView(ob, 'test', IV, None), None)
xmlconfig(StringIO(template % (
- '<directive name="view" attributes="component, type, name, for, layer"'
- ' handler="Zope.ComponentArchitecture.metaConfigure.view"'
- ' namespace="http://namespaces.zope.org/zope" />'
- '<directive name="skin" attributes="name, layers"'
- ' handler="Zope.ComponentArchitecture.metaConfigure.skin"'
- ' namespace="http://namespaces.zope.org/zope" />'
- '<skin name="zmi" layers="zmi," />'
- '<view name="test" factory="Zope.ComponentArchitecture.tests.TestViews.VZMI"'
- ' layer="zmi" '
- ' for="Zope.ComponentArchitecture.tests.TestViews.IC" '
- ' type="Zope.ComponentArchitecture.tests.TestViews.IV"/>'
- '<view name="test" factory="Zope.ComponentArchitecture.tests.TestViews.V1"'
- ' for="Zope.ComponentArchitecture.tests.TestViews.IC" '
- ' type="Zope.ComponentArchitecture.tests.TestViews.IV"/>'
+ """
+ <directive name="view"
+ attributes="component, type, name, for, layer"
+ handler="Zope.ComponentArchitecture.metaConfigure.view"
+ namespace="http://namespaces.zope.org/zope" />
+ <directive name="skin" attributes="name, type, layers"
+ handler="Zope.ComponentArchitecture.metaConfigure.skin"
+ namespace="http://namespaces.zope.org/zope" />
+ <skin name="zmi" layers="zmi,"
+ type="Zope.ComponentArchitecture.tests.TestViews.IV" />
+ <view name="test"
+ factory="Zope.ComponentArchitecture.tests.TestViews.VZMI"
+ layer="zmi"
+ for="Zope.ComponentArchitecture.tests.TestViews.IC"
+ type="Zope.ComponentArchitecture.tests.TestViews.IV"/>
+ <view name="test"
+ factory="Zope.ComponentArchitecture.tests.TestViews.V1"
+ for="Zope.ComponentArchitecture.tests.TestViews.IC"
+ type="Zope.ComponentArchitecture.tests.TestViews.IV"/>
+ """
)))
self.assertEqual(getView(ob, 'test', IV, None).__class__, V1)
- self.assertEqual(getView(ob, 'test', IV, None, skin='zmi').__class__, VZMI)
+ self.assertEqual(getView(ob, 'test', IV, None, skin='zmi').__class__,
+ VZMI)
+
+ def testResource(self):
+
+ ob = Ob()
+ self.assertEqual(getResource(ob, 'test', IV, None), None)
+
+ xmlconfig(StringIO(template % (
+ """
+ <directive name="resource"
+ attributes="component, type, name, layer"
+ handler="Zope.ComponentArchitecture.metaConfigure.resource"
+ namespace="http://namespaces.zope.org/zope" />
+ <resource name="test"
+ component="Zope.ComponentArchitecture.tests.TestViews.r1"
+ type="Zope.ComponentArchitecture.tests.TestViews.IV"/>
+ """
+ )))
+
+ self.assertEqual(getResource(ob, 'test', IV, None).__class__, R1)
+
+ def testSKinResource(self):
+
+ ob = Ob()
+ self.assertEqual(getResource(ob, 'test', IV, None), None)
+
+ xmlconfig(StringIO(template % (
+ """
+ <directive name="resource"
+ attributes="component, type, name, layer"
+ handler="Zope.ComponentArchitecture.metaConfigure.resource"
+ namespace="http://namespaces.zope.org/zope" />
+ <directive name="skin" attributes="name, type, layers"
+ handler="Zope.ComponentArchitecture.metaConfigure.skin"
+ namespace="http://namespaces.zope.org/zope" />
+ <skin name="zmi" layers="zmi,"
+ type="Zope.ComponentArchitecture.tests.TestViews.IV" />
+ <resource name="test"
+ component="Zope.ComponentArchitecture.tests.TestViews.rZMI"
+ layer="zmi"
+ type="Zope.ComponentArchitecture.tests.TestViews.IV"/>
+ <resource name="test"
+ component="Zope.ComponentArchitecture.tests.TestViews.r1"
+ type="Zope.ComponentArchitecture.tests.TestViews.IV"/>
+ """
+ )))
+ self.assertEqual(getResource(ob, 'test', IV, None).__class__, R1)
+ self.assertEqual(
+ getResource(ob, 'test', IV, None, skin='zmi').__class__,
+ RZMI)
def test_suite():
loader=unittest.TestLoader()
=== Zope3/lib/python/Zope/ComponentArchitecture/tests/testSkins.py 1.1.2.6 => 1.1.2.7 ===
provideView(I1, 'test', I2, C1)
self.assertEqual(getView(O(), 'test', I2).__class__, C1)
- defineSkin('foo', ('foo', ''))
+ defineSkin('foo', I2, ('foo', ''))
self.assertEqual(getView(O(), 'test', I2, skin='foo').__class__, C1)
provideView(None, 'test', I2, C2)
self.assertEqual(getView(O(), 'test', I2, skin='foo').__class__, C1)
@@ -68,7 +68,7 @@
provideView(I1, 'test', I2, C1)
self.assertEqual(getRequestView(O(), 'test',
Request(I2,'') ).__class__, C1)
- defineSkin('foo', ('foo', ''))
+ defineSkin('foo', I2, ('foo', ''))
self.assertEqual(getRequestView(O(), 'test',
Request(I2, 'foo')).__class__, C1)