[Checkins] SVN: five.pt/trunk/src/five/pt/tests/test_persistenttemplate.py new five.pt tests showing failures in persistent ZPTs

Leonardo Rochael Almeida leorochael at gmail.com
Thu Aug 4 09:44:21 EDT 2011


Log message for revision 122461:
  new five.pt tests showing failures in persistent ZPTs

Changed:
  U   five.pt/trunk/src/five/pt/tests/test_persistenttemplate.py

-=-
Modified: five.pt/trunk/src/five/pt/tests/test_persistenttemplate.py
===================================================================
--- five.pt/trunk/src/five/pt/tests/test_persistenttemplate.py	2011-08-04 09:03:53 UTC (rev 122460)
+++ five.pt/trunk/src/five/pt/tests/test_persistenttemplate.py	2011-08-04 13:44:20 UTC (rev 122461)
@@ -1,3 +1,6 @@
+import re
+import cgi
+
 from Testing.ZopeTestCase import ZopeTestCase
 from Products.PageTemplates.ZopePageTemplate import manage_addPageTemplate
 
@@ -59,6 +62,18 @@
                        for name in names)
     return options_capture_update_base % (params,)
 
+textarea_content_search = re.compile(
+    r'<textarea[^>]*>([^<]+)</textarea>',
+    re.IGNORECASE | re.MULTILINE
+).search
+
+def get_editable_content(template):
+    # Note that pt_editForm is also a patched PageTemplateFile class,
+    # so this is actually a test of five.pt as well.
+    edit_form = template.pt_editForm()
+    editable_text = textarea_content_search(edit_form).group(1)
+    return editable_text
+
 _marker = object()
 
 class TestPersistent(ZopeTestCase):
@@ -79,9 +94,17 @@
         template = self._makeOne('foo', simple_i18n)
         result = template().strip()
         self.assertEqual(result, u'Hello, World')
-        # check that it's editable
-        template.pt_editForm()
+        editable_text = get_editable_content(template)
+        self.assertEqual(editable_text, cgi.escape(simple_i18n))
 
+    def test_escape_on_edit(self):
+        # check that escapable chars can round-trip intact.
+        source = u"&gt; &amp; &lt;"
+        template = self._makeOne('foo', source)
+        self.assertEqual(template(), source) # nothing to render
+        editable_text = get_editable_content(template)
+        self.assertEqual(editable_text, cgi.escape(source))
+
     def test_macro_with_i18n(self):
         self._makeOne('macro_outer', macro_outer)
         self._makeOne('macro_middle', macro_middle)
@@ -139,3 +162,12 @@
         self.folder.method = 'post'
         template = self._makeOne('foo', python_path_source)
         self.assertEquals(template(), u'<form method="post" />')
+
+    def test_filename_attribute(self):
+        # check that a persistent page template that happens to have
+        # a filename attribute doesn't break
+        template = self._makeOne('foo', repeat_object)
+        template.filename = 'some/random/path'
+        # this should still work, without trying to open some random
+        # file on the filesystem
+        self.assertEqual(template().strip().split(), u'0 1 2'.split())



More information about the checkins mailing list