Back to index

plone3  3.1.7
testTranslationServiceTool.py
Go to the documentation of this file.
00001 #
00002 # Test toLocalizedTime script and TranslationServiceTool.
00003 #
00004 
00005 from Products.CMFPlone.tests import PloneTestCase
00006 from Products.CMFCore.utils import getToolByName
00007 
00008 
00009 class TestUTranslate(PloneTestCase.PloneTestCase):
00010 
00011     def afterSetUp(self):
00012         self.tool = getToolByName(self.portal, 'translation_service')
00013 
00014     def testUTranslate(self):
00015         # Test Unicode value
00016         value = self.tool.utranslate('domain', u'foo')
00017         self.assertEquals(value, u'foo')
00018 
00019         # Test ascii value
00020         value = self.tool.utranslate('domain', 'foo')
00021         self.assertEquals(value, u'foo')
00022 
00023         # Test utf-8 value
00024         value = self.tool.utranslate('domain', u'\xc3'.encode('utf-8'))
00025         self.assertEquals(value, u'\xc3')
00026 
00027         # Test empty string
00028         value = self.tool.utranslate('domain', '')
00029         self.assertEquals(value, u'')
00030 
00031         # Test empty domain
00032         value = self.tool.utranslate('', 'foo')
00033         self.assertEquals(value, u'foo')
00034 
00035         # Test default is None
00036         value = self.tool.utranslate('domain', 'foo', default=None)
00037         self.assertEquals(value, u'foo')
00038 
00039 class TestTranslationServiceTool(PloneTestCase.PloneTestCase):
00040 
00041     def afterSetUp(self):
00042         self.tool = getToolByName(self.portal, 'translation_service')
00043 
00044     def testLocalized_time(self):
00045         value = self.tool.ulocalized_time('Mar 9, 1997 1:45pm',
00046                                          long_format=True,
00047                                          context=self.portal)
00048         # TranslationServiceTool falls back to time formats in site properties
00049         # because PTS isn't installed
00050         self.assertEquals(value, 'Mar 09, 1997 01:45 PM')
00051 
00052     def test_ulocalized_time_fetch_error(self):
00053         # http://dev.plone.org/plone/ticket/4251
00054         error = "(Missing.Value,), {}"
00055         value = self.tool.ulocalized_time(error)
00056         self.failUnlessEqual(value, None)
00057 
00058 
00059 def test_suite():
00060     from unittest import TestSuite, makeSuite
00061     suite = TestSuite()
00062     suite.addTest(makeSuite(TestUTranslate))
00063     suite.addTest(makeSuite(TestTranslationServiceTool))
00064     return suite