[Zope3-checkins] CVS: Zope3/src/zope/app/dtmlpage/tests - __init__.py:1.2 test_dtmlpage.py:1.2 test_dtmlpageeval.py:1.2

Philipp von Weitershausen philikon at philikon.de
Tue Feb 24 11:49:39 EST 2004


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

Added Files:
	__init__.py test_dtmlpage.py test_dtmlpageeval.py 
Log Message:


Moved the DTML Page content type to its own package below zope.app,
including its interfaces and browser views.




=== Zope3/src/zope/app/dtmlpage/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null	Tue Feb 24 11:49:39 2004
+++ Zope3/src/zope/app/dtmlpage/tests/__init__.py	Tue Feb 24 11:49:38 2004
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.


=== Zope3/src/zope/app/dtmlpage/tests/test_dtmlpage.py 1.1 => 1.2 ===
--- /dev/null	Tue Feb 24 11:49:39 2004
+++ Zope3/src/zope/app/dtmlpage/tests/test_dtmlpage.py	Tue Feb 24 11:49:38 2004
@@ -0,0 +1,79 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""
+Basic tests for Page Templates used in content-space.
+
+$Id$
+"""
+
+import unittest
+
+from zope.security.checker import NamesChecker, defineChecker
+
+from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.app.traversing.adapters import Traverser, DefaultTraversable
+from zope.app.interfaces.traversing import ITraverser, ITraversable
+from zope.app.tests import ztapi
+from zope.app.container.contained import contained
+from zope.app.dtmlpage.dtmlpage import DTMLPage
+
+
+class Data(object):
+
+    def __init__(self, **kw):
+        self.__dict__.update(kw)
+
+    def __getitem__(self, name):
+        return getattr(self, name)
+
+
+class DTMLPageTests(PlacelessSetup, unittest.TestCase):
+
+    def setUp(self):
+        super(DTMLPageTests, self).setUp()
+        ztapi.provideAdapter(None, ITraverser, Traverser)
+        ztapi.provideAdapter(None, ITraversable, DefaultTraversable)
+        defineChecker(Data, NamesChecker(['URL', 'name', '__getitem__']))
+
+    def test(self):
+        page = DTMLPage()
+        page.setSource(
+            '<html>'
+            '<head><title><dtml-var title></title></head>'
+            '<body>'
+            '<a href="<dtml-var "REQUEST.URL[\'1\']">">'
+            '<dtml-var name>'
+            '</a></body></html>'
+            )
+
+        page = contained(page, Data(name='zope'))
+
+        out = page.render(Data(URL={'1': 'http://foo.com/'}),
+                          title="Zope rules")
+        out = ' '.join(out.split())
+
+
+        self.assertEqual(
+            out,
+            '<html><head><title>Zope rules</title></head><body>'
+            '<a href="http://foo.com/">'
+            'zope'
+            '</a></body></html>'
+            )
+
+def test_suite():
+    return unittest.makeSuite(DTMLPageTests)
+
+if __name__=='__main__':
+    unittest.TextTestRunner().run(test_suite())


=== Zope3/src/zope/app/dtmlpage/tests/test_dtmlpageeval.py 1.1 => 1.2 ===
--- /dev/null	Tue Feb 24 11:49:39 2004
+++ Zope3/src/zope/app/dtmlpage/tests/test_dtmlpageeval.py	Tue Feb 24 11:49:38 2004
@@ -0,0 +1,64 @@
+##############################################################################
+#
+# 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
+#
+##############################################################################
+"""DTML Page Evaluation Tests
+
+$Id$
+"""
+from unittest import TestCase, main, makeSuite
+from zope.app.container.contained import contained
+from zope.app.dtmlpage.browser import DTMLPageEval
+
+class Test(TestCase):
+
+    def test(self):
+
+        class Template:
+            def render(self, request, **kw):
+                self.called = request, kw
+                request.response.setHeader('content-type', self.content_type)
+                return 42
+
+            content_type = 'text/x-test'
+
+        class Folder:
+            name='zope'
+
+        folder = Folder()
+
+        class Request(object):
+
+            def _getResponse(self):
+                return self
+
+            response = property(_getResponse)
+
+            def setHeader(self, name, value):
+                setattr(self, name, value)
+
+        request = Request()
+        template = contained(Template(), folder, 'foo')
+
+        view = DTMLPageEval()
+        # Do manually, since directive adds BrowserView as base class
+        view.context = template
+        view.request = request
+        self.assertEqual(view.index(request), 42)
+        self.assertEqual(template.called, (request, {}))
+        self.assertEqual(getattr(request, 'content-type'), 'text/x-test')
+
+def test_suite():
+    return makeSuite(Test)
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')




More information about the Zope3-Checkins mailing list