[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/Browser/tests - TestViews.py:1.1.2.1 testDirectives.py:1.1.2.1
Jim Fulton
jim@zope.com
Mon, 14 Jan 2002 08:42:52 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/Browser/tests
In directory cvs.zope.org:/tmp/cvs-serv29617/Publisher/Browser/tests
Added Files:
Tag: Zope-3x-branch
TestViews.py testDirectives.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/Publisher/Browser/tests/TestViews.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
#
##############################################################################
"""
Revision information: $Id: TestViews.py,v 1.1.2.1 2002/01/14 13:42:51 jim Exp $
"""
from Interface import Interface
from Zope.Publisher.Browser.IBrowserPublisher import IBrowserPublisher
class IC(Interface): pass
class V1:
__implements__ = IBrowserPublisher
def __init__(self,context):
self._context = context
class VZMI(V1):
pass
class R1:
__implements__ = IBrowserPublisher
r1 = R1()
class RZMI(R1):
pass
rZMI = RZMI()
=== Added File Zope3/lib/python/Zope/Publisher/Browser/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.Publisher.Browser.IBrowserPublisher import IBrowserPublisher
from Zope.Publisher.Browser.tests.TestViews import IC, V1, VZMI, R1, RZMI
from Zope.ComponentArchitecture import getView, getResource, _clear
from cStringIO import StringIO
template = """<zopeConfigure
xmlns='http://namespaces.zope.org/zope'
xmlns:browser='http://namespaces.zope.org/browser'>
%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', IBrowserPublisher, None), None)
xmlconfig(StringIO(template % (
"""
<directive name="view"
attributes="component, name, for, layer"
handler="Zope.Publisher.Browser.metaConfigure.view"
namespace="http://namespaces.zope.org/browser" />
<browser:view name="test"
factory="Zope.Publisher.Browser.tests.TestViews.V1"
for="Zope.Publisher.Browser.tests.TestViews.IC" />
"""
)))
self.assertEqual(getView(ob, 'test', IBrowserPublisher, None
).__class__, V1)
def testSKinView(self):
ob = Ob()
self.assertEqual(getView(ob, 'test', IBrowserPublisher, None), None)
xmlconfig(StringIO(template % (
"""
<directive name="view"
attributes="component, name, for, layer"
handler="Zope.Publisher.Browser.metaConfigure.view"
namespace="http://namespaces.zope.org/browser" />
<directive name="skin" attributes="name, layers"
handler="Zope.Publisher.Browser.metaConfigure.skin"
namespace="http://namespaces.zope.org/browser" />
<browser:skin name="zmi" layers="zmi," />
<browser:view name="test"
factory="Zope.Publisher.Browser.tests.TestViews.VZMI"
layer="zmi"
for="Zope.Publisher.Browser.tests.TestViews.IC" />
<browser:view name="test"
factory="Zope.Publisher.Browser.tests.TestViews.V1"
for="Zope.Publisher.Browser.tests.TestViews.IC" />
"""
)))
self.assertEqual(getView(ob, 'test', IBrowserPublisher, None
).__class__, V1)
self.assertEqual(getView(ob, 'test', IBrowserPublisher, None,
skin='zmi').__class__,
VZMI)
def testResource(self):
ob = Ob()
self.assertEqual(getResource(ob, 'test', IBrowserPublisher, None),
None)
xmlconfig(StringIO(template % (
"""
<directive name="resource"
attributes="component, name, layer"
handler="Zope.Publisher.Browser.metaConfigure.resource"
namespace="http://namespaces.zope.org/browser" />
<browser:resource name="test"
component="Zope.Publisher.Browser.tests.TestViews.r1" />
"""
)))
self.assertEqual(
getResource(ob, 'test', IBrowserPublisher, None).__class__,
R1)
def testSKinResource(self):
ob = Ob()
self.assertEqual(
getResource(ob, 'test', IBrowserPublisher, None),
None)
xmlconfig(StringIO(template % (
"""
<directive name="resource" attributes="component, name, layer"
handler="Zope.Publisher.Browser.metaConfigure.resource"
namespace="http://namespaces.zope.org/browser" />
<directive name="skin" attributes="name, layers"
handler="Zope.Publisher.Browser.metaConfigure.skin"
namespace="http://namespaces.zope.org/browser" />
<browser:skin name="zmi" layers="zmi," />
<browser:resource name="test"
component="Zope.Publisher.Browser.tests.TestViews.rZMI"
layer="zmi" />
<browser:resource name="test"
component="Zope.Publisher.Browser.tests.TestViews.r1" />
"""
)))
self.assertEqual(
getResource(ob, 'test', IBrowserPublisher, None).__class__,
R1)
self.assertEqual(
getResource(ob, 'test', IBrowserPublisher, None,
skin='zmi').__class__,
RZMI)
def test_suite():
loader=unittest.TestLoader()
return loader.loadTestsFromTestCase(Test)
if __name__=='__main__':
unittest.TextTestRunner().run(test_suite())