[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Content/ZPTPage/Views/Browser/tests - testZPTPageEval.py:1.1.2.1

Jim Fulton jim@zope.com
Thu, 23 May 2002 14:01:14 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Content/ZPTPage/Views/Browser/tests
In directory cvs.zope.org:/tmp/cvs-serv26429/lib/python/Zope/App/OFS/Content/ZPTPage/Views/Browser/tests

Added Files:
      Tag: Zope-3x-branch
	testZPTPageEval.py 
Log Message:
This all started with wanting to be able to use url;view in a ZPT path. :)

That lead me to:

- Massive traversal refactoring.

  Namespace handling is now centralized in Zope.App.Traversing. 

- ZPT refactoring, including some renaming that touches pretty much everything. :)

  - The application specific ZPT support was moved into
    Zope.App.PageTemplate. 

  - To get page template files (for use in views):

    from Zope.App.PageTemplate import ViewPageTemplateFile

  - Fixed up security so that ZPT expressions only have access to 
    safe builtins and so that modules namespace does imports safely.

  - Got ZPTPage working!

- renaming url to absolute_url and got absolute_url to work in paths.

- Cleaned up the (as yet unused) RestrictedInterpreter module in
  Zope.Security. In particular, changed to use a separate
  RestrictedBuiltins module.



=== Added File Zope3/lib/python/Zope/App/OFS/Content/ZPTPage/Views/Browser/tests/testZPTPageEval.py ===
##############################################################################
#
# Copyright (c) 2001, 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
# 
##############################################################################
"""

Revision information:
$Id: testZPTPageEval.py,v 1.1.2.1 2002/05/23 18:01:13 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup

from Zope.App.OFS.Content.ZPTPage.Views.Browser.ZPTPageEval import ZPTPageEval
from Zope.Proxy.ContextWrapper import ContextWrapper


class Test(CleanUp, TestCase):

    def test(self):

        class Template:
            def render(self, request, **kw):
                self.called = request, kw
                return 42

            content_type = 'text/x-test'

        class Folder: name='zope'
        folder = Folder()
        
        class Request:
            def getResponse(self):
                return self
            def setHeader(self, name, value):
                setattr(self, name, value)
                           
        request = Request()

        template = ContextWrapper(Template(), folder)

        view = ZPTPageEval(template)
        self.assertEqual(view.index(request), 42)
        self.assertEqual(template.called, (request, {}))
        self.assertEqual(getattr(request, 'content-type'), 'text/x-test')

def test_suite():
    return TestSuite((
        makeSuite(Test),
        ))

if __name__=='__main__':
    main(defaultTest='test_suite')