[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Publisher/Browser/tests - templateclass.py:1.1 test2.pt:1.1 test3.pt:1.1 testDirectives.py:1.5

Jim Fulton jim@zope.com
Tue, 18 Jun 2002 10:16:50 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/Publisher/Browser/tests
In directory cvs.zope.org:/tmp/cvs-serv30310/lib/python/Zope/App/Publisher/Browser/tests

Modified Files:
	testDirectives.py 
Added Files:
	templateclass.py test2.pt test3.pt 
Log Message:
Added the ability to specify templates in view pages rather than in
Python view classes.

Added the ability to supply a class when defiening views from
templates. In this case, the class becomes a base class of the
generated view class.

Added the ability to supply base classes to simple view classes.

Changed the zope page-template engine to use
Zope.App.Traversers.Traverser.Traverser directly, wo looking it up as
an adapter. I suspect that we'll stop making this pluggable, as it's
too much bother, given that adapters are used for each step anyway.



=== Added File Zope3/lib/python/Zope/App/Publisher/Browser/tests/templateclass.py ===
class templateclass:
    def data(self): return 42


=== Added File Zope3/lib/python/Zope/App/Publisher/Browser/tests/test2.pt ===
<html><body><p tal:content="view/data">test</p></body></html>


=== Added File Zope3/lib/python/Zope/App/Publisher/Browser/tests/test3.pt ===
<html><body><p tal:content="view/action">test</p></body></html>


=== Zope3/lib/python/Zope/App/Publisher/Browser/tests/testDirectives.py 1.4 => 1.5 ===
         xmlconfig(open(defs_path))
 
+        from Zope.ComponentArchitecture.GlobalAdapterService \
+             import provideAdapter
+        from Zope.App.Traversing.DefaultTraversable import DefaultTraversable
+        from Zope.App.Traversing.ITraversable import ITraversable
+
+        provideAdapter(None, ITraversable, DefaultTraversable)
+
     def testView(self):
         self.assertEqual(queryView(ob, 'test', request),
                          None)
@@ -242,6 +249,7 @@
     def testPageViews(self):
         self.assertEqual(queryView(ob, 'test', request),
                          None)
+        test3 = os.path.join(os.path.split(defs_path)[0], 'tests', 'test3.pt')
 
         xmlconfig(StringIO(template %
             """
@@ -251,14 +259,17 @@
 
                 <browser:page name="index.html" attribute="index" /> 
                 <browser:page name="action.html" attribute="action" /> 
+                <browser:page name="test.html" template="%s" /> 
             </browser:view>
-            """
+            """ % test3
             ))
 
         v = getView(ob, 'index.html', request)
         self.assertEqual(v(), 'V1 here')
         v = getView(ob, 'action.html', request)
         self.assertEqual(v(), 'done')
+        v = getView(ob, 'test.html', request)
+        self.assertEqual(str(v()), '<html><body><p>done</p></body></html>\n')
 
     def testPageViewsWithName(self):
         self.assertEqual(queryView(ob, 'test', request),
@@ -384,7 +395,7 @@
     def testtemplate(self):
         path = os.path.join(os.path.split(defs_path)[0], 'tests', 'test.pt')
         
-        self.assertEqual(queryView(ob, 'test', request),
+        self.assertEqual(queryView(ob, 'index.html', request),
                          None)
 
         xmlconfig(StringIO(template %
@@ -399,6 +410,25 @@
         v = getView(ob, 'index.html', request)
         self.assertEqual(v().strip(), '<html><body><p>test</p></body></html>')
 
+    def testtemplateWClass(self):
+        path = os.path.join(os.path.split(defs_path)[0], 'tests', 'test2.pt')
+        
+        self.assertEqual(queryView(ob, 'index.html', request),
+                         None)
+
+        xmlconfig(StringIO(template %
+            """
+            <browser:view
+                  name="index.html"
+                  template="%s"
+                  class="Zope.App.Publisher.Browser.tests.templateclass."
+                  for="Zope.ComponentArchitecture.tests.TestViews.IC" />
+            """ % path
+            ))
+
+        v = getView(ob, 'index.html', request)
+        self.assertEqual(v().strip(), '<html><body><p>42</p></body></html>')
+
     def testProtectedtemplate(self):
         path = os.path.join(os.path.split(defs_path)[0], 'tests', 'test.pt')
         
@@ -456,22 +486,6 @@
             <browser:view
                   template="%s"
                   for="Zope.ComponentArchitecture.tests.TestViews.IC" 
-                  /> 
-            """ % path
-            ))
-
-    def testtemplateAndFactory(self):
-        path = os.path.join(os.path.split(defs_path)[0], 'tests', 'test.pt')
-        self.assertRaises(
-            ConfigurationError,
-            xmlconfig,
-            StringIO(template %
-            """
-            <browser:view
-                  name="index.html"
-                  template="%s"
-                  for="Zope.ComponentArchitecture.tests.TestViews.IC" 
-                  factory="Zope.ComponentArchitecture.tests.TestViews.V1">
                   /> 
             """ % path
             ))