[Zope-Checkins] SVN: Zope/trunk/lib/python/Products/PageTemplates/ merged Zope/branches/slinkp-collector_596 25096:28418

Paul Winkler pw_lists at slinkp.com
Wed Nov 10 15:42:52 EST 2004


Log message for revision 28421:
  merged Zope/branches/slinkp-collector_596 25096:28418 
  
  I thought I had merged this before but clearly not :-(
  Also fixed a deprecation warning in testZopePageTemplate.py.
  
  

Changed:
  U   Zope/trunk/lib/python/Products/PageTemplates/CHANGES.txt
  U   Zope/trunk/lib/python/Products/PageTemplates/ZopePageTemplate.py
  A   Zope/trunk/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py

-=-
Modified: Zope/trunk/lib/python/Products/PageTemplates/CHANGES.txt
===================================================================
--- Zope/trunk/lib/python/Products/PageTemplates/CHANGES.txt	2004-11-10 20:19:35 UTC (rev 28420)
+++ Zope/trunk/lib/python/Products/PageTemplates/CHANGES.txt	2004-11-10 20:42:52 UTC (rev 28421)
@@ -21,3 +21,7 @@
 
         - The starting properties could be deleted.  This is only
         fixed for new templates.
+
+        - Collector 596 fixed; manage_addPageTemplate can now be
+          called with a text argument but no REQUEST.form['file'].
+          E.g. when called via ZPublisher.Client.

Modified: Zope/trunk/lib/python/Products/PageTemplates/ZopePageTemplate.py
===================================================================
--- Zope/trunk/lib/python/Products/PageTemplates/ZopePageTemplate.py	2004-11-10 20:19:35 UTC (rev 28420)
+++ Zope/trunk/lib/python/Products/PageTemplates/ZopePageTemplate.py	2004-11-10 20:42:52 UTC (rev 28421)
@@ -352,12 +352,17 @@
         file = REQUEST.form.get('file')
         headers = getattr(file, 'headers', None)
         if headers is None or not file.filename:
-            zpt = ZopePageTemplate(id)
+            zpt = ZopePageTemplate(id, text) # collector 596
         else:
             zpt = ZopePageTemplate(id, file, headers.get('content_type'))
 
         self._setObject(id, zpt)
 
+        # collector 596
+        if title:
+            ob = getattr(self, id)
+            ob.pt_setTitle(title)
+
         try:
             u = self.DestinationURL()
         except AttributeError:

Copied: Zope/trunk/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py (from rev 28418, Zope/branches/slinkp-collector_596/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py)
===================================================================
--- Zope/branches/slinkp-collector_596/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py	2004-11-10 17:19:29 UTC (rev 28418)
+++ Zope/trunk/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py	2004-11-10 20:42:52 UTC (rev 28421)
@@ -0,0 +1,77 @@
+"""ZopePageTemplate regression tests.
+
+Ensures that adding a page template works correctly.
+
+Note: Tests require Zope >= 2.7
+
+"""
+
+
+import unittest
+import Zope
+import transaction
+
+from Testing.makerequest import makerequest
+
+class ZPTRegressions(unittest.TestCase):
+
+    def setUp(self):
+        transaction.begin()
+        self.app = makerequest(Zope.app())
+        f = self.app.manage_addProduct['PageTemplates'].manage_addPageTemplate
+        self._addPT = f
+        self.title = 'title of page template'
+        self.text = 'text of page template'
+
+    def tearDown(self):
+        get_transaction().abort()
+        self.app._p_jar.close()
+
+    def testAddWithParams(self):
+        pt = self._addPT('pt1', title=self.title, text=self.text)
+        self.assertEqual(pt.title, self.title)
+        self.assertEqual(pt.document_src(), self.text)
+
+    def testAddWithoutParams(self):
+        pt = self._addPT('pt1')
+        default_text = open(pt._default_content_fn).read()
+        self.assertEqual(pt.title, '')
+        self.assertEqual(pt.document_src(), default_text)
+
+    def testAddWithRequest(self):
+        """Test manage_add with file"""
+        request = self.app.REQUEST
+        request.form['file'] = DummyFileUpload(filename='some file',
+                                               data=self.text,
+                                               content_type='text/html')
+        self._addPT('pt1', REQUEST=request)
+        # no object is returned when REQUEST is passed.
+        pt = self.app.pt1
+        self.assertEqual(pt.document_src(), self.text)
+
+    def testAddWithRequestButNoFile(self):
+        """Collector #596: manage_add with text but no file"""
+        request = self.app.REQUEST
+        self._addPT('pt1', text=self.text, REQUEST=request)
+        # no object is returned when REQUEST is passed.
+        pt = self.app.pt1
+        self.assertEqual(pt.document_src(), self.text)
+
+        
+class DummyFileUpload:
+
+    def __init__(self, data='', filename='', content_type=''):
+        self.data = data
+        self.filename = filename
+        self.headers = {'content_type': content_type}
+
+    def read(self):
+        return self.data
+
+       
+def test_suite():
+    return unittest.makeSuite(ZPTRegressions)
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')
+



More information about the Zope-Checkins mailing list