[Zope-Checkins] CVS: Zope3/lib/python/Zope/PageTemplate/tests - testViewZPT.py:1.1.2.1
Steve Alexander
steve@cat-box.net
Sun, 24 Mar 2002 14:19:50 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/PageTemplate/tests
In directory cvs.zope.org:/tmp/cvs-serv27024/lib/python/Zope/PageTemplate/tests
Added Files:
Tag: Zope-3x-branch
testViewZPT.py
Log Message:
Test written for ViewZPT.py.
After consulting with Jim, removed the change that allowed the instance
passed in not to have a getContext method.
It turned out to be really crufty to get rid of namespace['here'], as it
is set to instance in ZPT.pt_getContext, where ZPT is the base class of
ViewZPT.
=== Added File Zope3/lib/python/Zope/PageTemplate/tests/testViewZPT.py ===
# This software is subject to the provisions of the Zope Public License,
# Version 1.1 (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.
# The tests in this module are translations of some of the DTML tests;
# the original DTML sources are shown in the docstrings for each
# test. The names of the test methods have been changed to be more
# meaningful.
import os, sys, unittest
from Zope.PageTemplate.ViewZPT import ViewZPT
from Zope.Testing.CleanUp import CleanUp
from Zope.ComponentArchitecture import provideView
from Interface import Interface
class I1(Interface):
pass
class C1:
__implements__ = I1
class InstanceWithContext:
def __init__(self, context):
self.context = context
def getContext(self):
return self.context
class InstanceWithoutContext:
pass
class TestViewZPT(unittest.TestCase, CleanUp):
def setUp(self):
CleanUp.setUp(self)
self.t = ViewZPT()
self.context = C1()
def checkNamespaceHereAvailable(self):
context = self.context
request = None
namespace = self.t.pt_getContext(InstanceWithContext(context), request)
self.failUnless(namespace['here'] is context)
self.failUnless(namespace.has_key('views'))
def checkNamespaceHereNotAvailable(self):
request = None
self.assertRaises(AttributeError, self.t.pt_getContext,
InstanceWithoutContext(), request)
def checkViewMapper(self):
the_view = "This is the view"
the_view_type = "some view type"
the_view_name = "some view name"
def ViewMaker(*args, **kw):
return the_view
provideView(I1,
name=the_view_name,
type=the_view_type,
maker=ViewMaker)
from Zope.ComponentArchitecture.IViewService import IViewRequest
class MyRequest:
__implements__ = IViewRequest
def getViewType(self):
return the_view_type
def getViewSkin(self):
return "some skin"
request = MyRequest()
namespace = self.t.pt_getContext(InstanceWithContext(self.context),
request)
views = namespace['views']
self.failUnless(the_view is views[the_view_name])
def test_suite():
return unittest.makeSuite(TestViewZPT, 'check')
if __name__ == '__main__':
unittest.TextTestRunner().run(test_suite())