[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/PageTemplate/tests - SimpleTestView.py:1.2 __init__.py:1.2 sample.py:1.2 test.pt:1.2 testBoundPageTemplate.py:1.2 testSimpleViewClass.pt:1.2 testSimpleViewClass.py:1.2 testViewZPT.py:1.2 testZopePythonExpr.py:1.2 test_binding.py:1.2

Jim Fulton jim@zope.com
Mon, 10 Jun 2002 19:28:48 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/PageTemplate/tests
In directory cvs.zope.org:/tmp/cvs-serv17445/lib/python/Zope/App/PageTemplate/tests

Added Files:
	SimpleTestView.py __init__.py sample.py test.pt 
	testBoundPageTemplate.py testSimpleViewClass.pt 
	testSimpleViewClass.py testViewZPT.py testZopePythonExpr.py 
	test_binding.py 
Log Message:
Merged Zope-3x-branch into newly forked Zope3 CVS Tree.


=== Zope3/lib/python/Zope/App/PageTemplate/tests/SimpleTestView.py 1.1 => 1.2 ===
+#
+# 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')


=== Zope3/lib/python/Zope/App/PageTemplate/tests/__init__.py 1.1 => 1.2 ===
+#
+# Copyright (c) 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$
+"""
+


=== Zope3/lib/python/Zope/App/PageTemplate/tests/sample.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+import os
+from Zope.App.PageTemplate import ViewPageTemplateFile
+
+class C:
+    
+    index = ViewPageTemplateFile('test.pt')


=== Zope3/lib/python/Zope/App/PageTemplate/tests/test.pt 1.1 => 1.2 ===


=== Zope3/lib/python/Zope/App/PageTemplate/tests/testBoundPageTemplate.py 1.1 => 1.2 ===
+#
+# 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 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())


=== Zope3/lib/python/Zope/App/PageTemplate/tests/testSimpleViewClass.pt 1.1 => 1.2 ===
+  <body>
+    <p metal:define-macro="test">hello world</p>
+  </body>
+</html>


=== Zope3/lib/python/Zope/App/PageTemplate/tests/testSimpleViewClass.py 1.1 => 1.2 ===
+#
+# 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 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 test_suite():
+    loader=unittest.TestLoader()
+    return loader.loadTestsFromTestCase(Test)
+
+if __name__=='__main__':
+    unittest.TextTestRunner().run(test_suite())
+    


=== Zope3/lib/python/Zope/App/PageTemplate/tests/testViewZPT.py 1.1 => 1.2 ===
+#
+# 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.ComponentArchitecture import getService
+from Interface import Interface
+from Zope.App.OFS.Services.ServiceManager.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"
+        the_view_type = "some view type"
+        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.ComponentArchitecture.IPresentationRequest \
+             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())


=== Zope3/lib/python/Zope/App/PageTemplate/tests/testZopePythonExpr.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+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 TestSuite((
+        makeSuite(Test),
+        ))
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')


=== Zope3/lib/python/Zope/App/PageTemplate/tests/test_binding.py 1.1 => 1.2 ===
+#
+# 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.ComponentArchitecture.tests.PlacelessSetup import PlacelessSetup
+from Zope.App.Traversing.Traverser import Traverser
+from Zope.App.Traversing.ITraverser import ITraverser
+from Zope.App.Traversing.DefaultTraversable import DefaultTraversable
+from Zope.App.Traversing.ITraversable import ITraversable
+from Zope.ComponentArchitecture.GlobalAdapterService 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()