[Zope3-checkins] CVS: Zope3/src/zope/app/pagetemplate/tests - __init__.py:1.1.2.1 sample.py:1.1.2.1 simpletestview.py:1.1.2.1 test.pt:1.1.2.1 test_binding.py:1.1.2.1 test_boundpagetemplate.py:1.1.2.1 test_simpleviewclass.py:1.1.2.1 test_viewzpt.py:1.1.2.1 test_zopepythonexpr.py:1.1.2.1 testsimpleviewclass.pt:1.1.2.1

Jim Fulton jim@zope.com
Mon, 23 Dec 2002 14:31:58 -0500


Update of /cvs-repository/Zope3/src/zope/app/pagetemplate/tests
In directory cvs.zope.org:/tmp/cvs-serv19908/zope/app/pagetemplate/tests

Added Files:
      Tag: NameGeddon-branch
	__init__.py sample.py simpletestview.py test.pt 
	test_binding.py test_boundpagetemplate.py 
	test_simpleviewclass.py test_viewzpt.py test_zopepythonexpr.py 
	testsimpleviewclass.pt 
Log Message:
Initial renaming before debugging

=== Added File Zope3/src/zope/app/pagetemplate/tests/__init__.py ===
#
# This file is necessary to make this directory a package.


=== Added File Zope3/src/zope/app/pagetemplate/tests/sample.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: sample.py,v 1.1.2.1 2002/12/23 19:31:57 jim Exp $
"""

import os
from Zope.App.PageTemplate import ViewPageTemplateFile

class C:
    
    index = ViewPageTemplateFile('test.pt')


=== Added File Zope3/src/zope/app/pagetemplate/tests/simpletestview.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.
# 
##############################################################################

from zope.app.pagetemplate.simpleviewclass import SimpleViewClass

SimpleTestView = SimpleViewClass('testSimpleViewClass.pt')


=== Added File Zope3/src/zope/app/pagetemplate/tests/test.pt ===
<html><body></body></html>


=== Added File Zope3/src/zope/app/pagetemplate/tests/test_binding.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.
# 
##############################################################################

import unittest
from Zope.PageTemplate.tests import util
from zope.app.pagetemplate.tests.testpackage.content \
     import Content, PTComponent

# Wow, this is a lot of work. :(
from zope.app.tests.placelesssetup import PlacelessSetup
from zope.app.traversing.traverser import Traverser
from zope.app.interfaces.traversing.traverser import ITraverser
from zope.app.traversing.defaulttraversable import DefaultTraversable
from zope.app.interfaces.traversing.traversable import ITraversable
from zope.component.adapter import provideAdapter


class BindingTestCase(PlacelessSetup, unittest.TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)
        provideAdapter(None, ITraverser, Traverser)
        provideAdapter(None, ITraversable, DefaultTraversable)

    def test_binding(self):
        comp = PTComponent(Content())
        self.assertEqual(comp.index(), "42\n")

def test_suite():
    return unittest.makeSuite(BindingTestCase)

if __name__=='__main__':
    unittest.main()


=== Added File Zope3/src/zope/app/pagetemplate/tests/test_boundpagetemplate.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.
# 
##############################################################################
import unittest, sys, os
    

class Test(unittest.TestCase):

    def testAttributes(self):

        from zope.app.pagetemplate.tests.sample import C

        self.assertRaises(AttributeError, setattr, C.index, 'foo', 1)
        self.assertRaises(AttributeError, setattr, C().index, 'foo', 1)

        C.index.im_func.foo = 1
        self.assertEqual(C.index.foo, 1)



def test_suite():
    loader=unittest.TestLoader()
    return loader.loadTestsFromTestCase(Test)

if __name__=='__main__':
    unittest.TextTestRunner().run(test_suite())


=== Added File Zope3/src/zope/app/pagetemplate/tests/test_simpleviewclass.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.
# 
##############################################################################
import unittest, sys



class data: pass

class Test(unittest.TestCase):

    def test(self):
        from zope.app.pagetemplate.tests.simpletestview import SimpleTestView
        
        ob = data()
        view = SimpleTestView(ob, None)        
        macro = view['test']
        out = view()
        self.assertEqual(out,
                         '<html>\n'
                         '  <body>\n'
                         '    <p>hello world</p>\n'
                         '  </body>\n</html>\n')

    def testWBases(self):
        from zope.app.pagetemplate.simpleviewclass import SimpleViewClass

        class C: pass
        
        SimpleTestView = SimpleViewClass('testSimpleViewClass.pt', bases=(C, ))
        
        self.failUnless(issubclass(SimpleTestView, C))

        ob = data()
        view = SimpleTestView(ob, None)        
        macro = view['test']
        out = view()
        self.assertEqual(out,
                         '<html>\n'
                         '  <body>\n'
                         '    <p>hello world</p>\n'
                         '  </body>\n</html>\n')

def test_suite():
    loader=unittest.TestLoader()
    return loader.loadTestsFromTestCase(Test)

if __name__=='__main__':
    unittest.TextTestRunner().run(test_suite())
    


=== Added File Zope3/src/zope/app/pagetemplate/tests/test_viewzpt.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.
# 
##############################################################################
import os, sys, unittest

from Zope.App.PageTemplate import ViewPageTemplateFile
from zope.testing.cleanup import CleanUp
from zope.component import getService
from zope.interface import Interface
from zope.app.services.tests.placefulsetup\
           import PlacefulSetup

class I1(Interface):
    pass

class C1:
    __implements__ = I1

class InstanceWithContext:
    def __init__(self, context):
        self.context = context

class InstanceWithoutContext:
    pass

class TestViewZPT(PlacefulSetup, unittest.TestCase):

    def setUp(self):
       PlacefulSetup.setUp(self)
       self.t = ViewPageTemplateFile('test.pt')
       self.context = C1()
      

    def checkNamespaceContextAvailable(self):
        context = self.context
        request = None
              
        namespace = self.t.pt_getContext(InstanceWithContext(context), request)
        self.failUnless(namespace['context'] is context)
        self.failUnless('views' in namespace)
      
        
    def checkNamespaceHereNotAvailable(self):
        request = None              
        self.assertRaises(AttributeError, self.t.pt_getContext,
                          InstanceWithoutContext(), request)
   
    def checkViewMapper(self):
          
        the_view = "This is the view"
        class the_view_type(Interface): pass
        the_view_name = "some view name"
        def ViewMaker(*args, **kw):
            return the_view
          
        getService(None,"Views").provideView(I1,
                    name=the_view_name,
                    type=the_view_type,
                    maker=[ViewMaker])
        
        from zope.component.interfaces \
             import IPresentationRequest

        class MyRequest:
            __implements__ = IPresentationRequest
            def getPresentationType(self):
                return the_view_type
            def getPresentationSkin(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())


=== Added File Zope3/src/zope/app/pagetemplate/tests/test_zopepythonexpr.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: test_zopepythonexpr.py,v 1.1.2.1 2002/12/23 19:31:57 jim Exp $
"""

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

class Engine:

    def getTypes(self):
        return {}

class Context:

    _engine = Engine()

    def __init__(self, **kw):
        self.vars = kw

class Test(CleanUp, TestCase):

      def test(self):
          from zope.app.pagetemplate.engine import ZopePythonExpr
          from zope.exceptions import Forbidden

          expr = ZopePythonExpr('python', 'max(a,b)', Engine())
          self.assertEqual(expr(Context(a=1, b=2)), 2)
          expr = ZopePythonExpr(
              'python', '__import__("sys").__name__', Engine())
          self.assertEqual(expr(Context()), 'sys')
          expr = ZopePythonExpr('python', '__import__("sys").exit',
                                Engine())
          self.assertRaises(Forbidden, expr, Context())
          expr = ZopePythonExpr('python', 'open("x", "w")', Engine())
          self.assertRaises(NameError, expr, Context())

def test_suite():
    return makeSuite(Test)

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


=== Added File Zope3/src/zope/app/pagetemplate/tests/testsimpleviewclass.pt ===
<html>
  <body>
    <p metal:define-macro="test">hello world</p>
  </body>
</html>