[Zope-Checkins] CVS: Zope3/lib/python/Zope/ComponentArchitecture/tests - testDirectives.py:1.1.2.1
Andreas Jung
andreas@digicool.com
Thu, 10 Jan 2002 16:54:18 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/ComponentArchitecture/tests
In directory cvs.zope.org:/tmp/cvs-serv20090/lib/python/Zope/ComponentArchitecture/tests
Added Files:
Tag: Zope-3x-branch
testDirectives.py
Log Message:
initial test for directives (view directive)
=== Added File Zope3/lib/python/Zope/ComponentArchitecture/tests/testDirectives.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.Configuration.xmlconfig import xmlconfig
from Zope.ComponentArchitecture.tests.TestViews import IV, IC, V1, VZMI
from Zope.ComponentArchitecture import getView, _clear
from cStringIO import StringIO
template = """<zopeConfigure
xmlns='http://namespaces.zope.org/zope'
xmlns:test='http://www.zope.org/NS/Zope3/test'>
%s
</zopeConfigure>"""
class Ob:
__implements__ = IC
class Test(unittest.TestCase):
# XXX: tests for other directives needed
def tearDown(self):
_clear()
def testView(self):
ob = Ob()
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"/>'
)))
self.assertEqual(getView(ob, 'test', IV, None).__class__, V1)
def testSKinView(self):
ob = Ob()
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"/>'
)))
self.assertEqual(getView(ob, 'test', IV, None).__class__, V1)
self.assertEqual(getView(ob, 'test', IV, None, skin='zmi').__class__, VZMI)
def test_suite():
loader=unittest.TestLoader()
return loader.loadTestsFromTestCase(Test)
if __name__=='__main__':
unittest.TextTestRunner().run(test_suite())