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

Jim Fulton jim@zope.com
Wed, 25 Dec 2002 09:14:08 -0500


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

Added Files:
	__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:
Grand renaming:

- Renamed most files (especially python modules) to lower case.

- Moved views and interfaces into separate hierarchies within each
  project, where each top-level directory under the zope package
  is a separate project.

- Moved everything to src from lib/python.

  lib/python will eventually go away. I need access to the cvs
  repository to make this happen, however.

There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.



=== Zope3/src/zope/app/pagetemplate/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:08 2002
+++ Zope3/src/zope/app/pagetemplate/tests/__init__.py	Wed Dec 25 09:13:06 2002
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.


=== Zope3/src/zope/app/pagetemplate/tests/sample.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:08 2002
+++ Zope3/src/zope/app/pagetemplate/tests/sample.py	Wed Dec 25 09:13:06 2002
@@ -0,0 +1,22 @@
+##############################################################################
+#
+# 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 zope.app.pagetemplate import ViewPageTemplateFile
+
+class C:
+    index = ViewPageTemplateFile('test.pt')


=== Zope3/src/zope/app/pagetemplate/tests/simpletestview.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:08 2002
+++ Zope3/src/zope/app/pagetemplate/tests/simpletestview.py	Wed Dec 25 09:13:06 2002
@@ -0,0 +1,17 @@
+##############################################################################
+#
+# 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/src/zope/app/pagetemplate/tests/test.pt 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:08 2002
+++ Zope3/src/zope/app/pagetemplate/tests/test.pt	Wed Dec 25 09:13:06 2002
@@ -0,0 +1 @@
+<html><body></body></html>


=== Zope3/src/zope/app/pagetemplate/tests/test_binding.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:08 2002
+++ Zope3/src/zope/app/pagetemplate/tests/test_binding.py	Wed Dec 25 09:13:06 2002
@@ -0,0 +1,45 @@
+##############################################################################
+#
+# 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()


=== Zope3/src/zope/app/pagetemplate/tests/test_boundpagetemplate.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:08 2002
+++ Zope3/src/zope/app/pagetemplate/tests/test_boundpagetemplate.py	Wed Dec 25 09:13:06 2002
@@ -0,0 +1,36 @@
+##############################################################################
+#
+# 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())


=== Zope3/src/zope/app/pagetemplate/tests/test_simpleviewclass.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:08 2002
+++ Zope3/src/zope/app/pagetemplate/tests/test_simpleviewclass.py	Wed Dec 25 09:13:06 2002
@@ -0,0 +1,57 @@
+##############################################################################
+#
+# 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
+
+
+class data: pass
+
+class SimpleViewTestCase(unittest.TestCase):
+
+    def test_simple(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 test_WBases(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():
+    return unittest.makeSuite(SimpleViewTestCase)
+
+if __name__=='__main__':
+    unittest.TextTestRunner().run(test_suite())


=== Zope3/src/zope/app/pagetemplate/tests/test_viewzpt.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:08 2002
+++ Zope3/src/zope/app/pagetemplate/tests/test_viewzpt.py	Wed Dec 25 09:13:06 2002
@@ -0,0 +1,96 @@
+##############################################################################
+#
+# 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
+import sys
+import unittest
+
+from zope.testing.cleanup import CleanUp
+from zope.component import getService
+from zope.interface import Interface
+
+from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
+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())


=== Zope3/src/zope/app/pagetemplate/tests/test_zopepythonexpr.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:08 2002
+++ Zope3/src/zope/app/pagetemplate/tests/test_zopepythonexpr.py	Wed Dec 25 09:13:06 2002
@@ -0,0 +1,56 @@
+##############################################################################
+#
+# 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 makeSuite(Test)
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')


=== Zope3/src/zope/app/pagetemplate/tests/testsimpleviewclass.pt 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:08 2002
+++ Zope3/src/zope/app/pagetemplate/tests/testsimpleviewclass.pt	Wed Dec 25 09:13:06 2002
@@ -0,0 +1,5 @@
+<html>
+  <body>
+    <p metal:define-macro="test">hello world</p>
+  </body>
+</html>