[Zope-Checkins]
SVN: Zope/trunk/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py
more tests
Andreas Jung
andreas at andreas-jung.com
Mon Jan 8 15:38:26 EST 2007
Log message for revision 71830:
more tests
Changed:
U Zope/trunk/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py
-=-
Modified: Zope/trunk/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py
===================================================================
--- Zope/trunk/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py 2007-01-08 19:38:24 UTC (rev 71829)
+++ Zope/trunk/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py 2007-01-08 20:38:26 UTC (rev 71830)
@@ -11,12 +11,18 @@
import unittest
import Zope2
import transaction
+
import zope.component.testing
-from zope.traversing.adapters import DefaultTraversable
+from zope.traversing.adapters import DefaultTraversable, Traverser
+from zope.publisher.http import HTTPCharsets
+
from Testing.makerequest import makerequest
from Testing.ZopeTestCase import ZopeTestCase, installProduct
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate, manage_addPageTemplate
from Products.PageTemplates.utils import encodingFromXMLPreamble, charsetFromMetaEquiv
+from zope.component import provideUtility
+from Products.PageTemplates.interfaces import IUnicodeEncodingConflictResolver
+from Products.PageTemplates.unicodeconflictresolver import PreferredCharsetResolver
ascii_str = '<html><body>hello world</body></html>'
@@ -76,8 +82,37 @@
self.assertEqual(extract('<html><META http-equiv="content-type" content="text/html; charset=iso-8859-15"></html>'), 'iso-8859-15')
self.assertEqual(extract('<html><META http-equiv="content-type" content="text/html"></html>'), None)
self.assertEqual(extract('<html>...<html>'), None)
-
+
+class ZPTUnicodeEncodingConflictResolution(ZopeTestCase):
+
+ def setUp(self):
+ super(ZPTUnicodeEncodingConflictResolution, self).setUp()
+ zope.component.provideAdapter(DefaultTraversable, (None,))
+ zope.component.provideAdapter(HTTPCharsets, (None,))
+ provideUtility(PreferredCharsetResolver, IUnicodeEncodingConflictResolver)
+
+ def testISO_8859_15(self):
+ manage_addPageTemplate(self.app, 'test',
+ text='<div tal:content="python: request.get(\'data\')" />',
+ encoding='ascii')
+ zpt = self.app['test']
+ self.app.REQUEST.set('HTTP_ACCEPT_CHARSET', 'ISO-8859-15,utf-8')
+ self.app.REQUEST.set('data', 'üöä')
+ result = zpt.pt_render()
+ self.assertEqual(result.startswith(unicode('<div>üöä</div>', 'iso-8859-15')), True)
+
+ def testUTF8(self):
+ manage_addPageTemplate(self.app, 'test',
+ text='<div tal:content="python: request.get(\'data\')" />',
+ encoding='ascii')
+ zpt = self.app['test']
+ self.app.REQUEST.set('HTTP_ACCEPT_CHARSET', 'ISO-8859-15,utf-8')
+ self.app.REQUEST.set('data', unicode('üöä', 'iso-8859-15').encode('utf-8'))
+ result = zpt.pt_render()
+ self.assertEqual(result.startswith(unicode('<div>üöä</div>', 'iso-8859-15')), True)
+
+
class ZopePageTemplateFileTests(ZopeTestCase):
def testPT_RenderWithAscii(self):
@@ -274,6 +309,7 @@
suite.addTests(unittest.makeSuite(ZPTUtilsTests))
suite.addTests(unittest.makeSuite(ZPTMacros))
suite.addTests(unittest.makeSuite(ZopePageTemplateFileTests))
+ suite.addTests(unittest.makeSuite(ZPTUnicodeEncodingConflictResolution))
return suite
if __name__ == '__main__':
More information about the Zope-Checkins
mailing list