Commit 508354e6 authored by Andreas Jung's avatar Andreas Jung

added tests for edgecase where the resolver has no REQUEST object

parent a717c7be
......@@ -339,6 +339,23 @@ class ZopePageTemplateFileTests(ZopeTestCase):
result = zpt.pt_render()
self.assertEqual('ATTR' in result, False)
class PreferredEncodingUnicodeResolverTests(unittest.TestCase):
def testPreferredCharsetResolverWithoutRequestAndWithoutEncoding(self):
# This test checks the edgecase where the unicode conflict resolver
# is called with a context object having no REQUEST
context = object()
result = PreferredCharsetResolver.resolve(context, '', None)
self.assertEqual(result, '')
def testPreferredCharsetResolverWithoutRequestAndWithEncoding(self):
# This test checks the edgecase where the unicode conflict resolver
# is called with a context object having no REQUEST
class ContextMock:
management_page_charset = 'iso-8859-15'
result = PreferredCharsetResolver.resolve(ContextMock(), '', None)
self.assertEqual(result, u'')
class ZPTRegressions(unittest.TestCase):
......@@ -463,6 +480,7 @@ def test_suite():
suite.addTests(unittest.makeSuite(ZPTMacros))
suite.addTests(unittest.makeSuite(ZopePageTemplateFileTests))
suite.addTests(unittest.makeSuite(ZPTUnicodeEncodingConflictResolution))
suite.addTests(unittest.makeSuite(PreferredEncodingUnicodeResolverTests))
return suite
if __name__ == '__main__':
......
......@@ -67,6 +67,7 @@ class PreferredCharsetResolver:
# Deal with the fact that a REQUEST is not always available.
# In this case fall back to the encoding of the ZMI and the
# Python default encoding.
if request is None:
charsets = [default_encoding]
management_charset = getattr(context, 'management_page_charset', None)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment