Back to index

plone3  3.1.7
test_skinScripts.py
Go to the documentation of this file.
00001 #  ATContentTypes http://plone.org/products/atcontenttypes/
00002 #  Archetypes reimplementation of the CMF core types
00003 #  Copyright (c) 2003-2006 AT Content Types development team
00004 #
00005 #  This program is free software; you can redistribute it and/or modify
00006 #  it under the terms of the GNU General Public License as published by
00007 #  the Free Software Foundation; either version 2 of the License, or
00008 #  (at your option) any later version.
00009 #
00010 #  This program is distributed in the hope that it will be useful,
00011 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 #  GNU General Public License for more details.
00014 #
00015 #  You should have received a copy of the GNU General Public License
00016 #  along with this program; if not, write to the Free Software
00017 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 #
00019 """Test module for bug reports
00020 """
00021 
00022 __author__ = 'Alec Mitchell <apm13@columbia.edu>'
00023 __docformat__ = 'restructuredtext'
00024 
00025 from Testing import ZopeTestCase # side effect import. leave it here.
00026 from Products.ATContentTypes.tests import atcttestcase
00027 from DateTime import DateTime
00028 import Missing
00029 
00030 
00031 tests = []
00032 
00033 class TestFormatCatalogMetadata(atcttestcase.ATCTSiteTestCase):
00034 
00035     def afterSetUp(self):
00036         atcttestcase.ATCTSiteTestCase.afterSetUp(self)
00037         self.script = self.portal.formatCatalogMetadata
00038 
00039     def testFormatDate(self):
00040         date = '2005-11-02 13:52:25'
00041         format = '%m-%d-%Y %I:%M %p'
00042         self.portal.portal_properties.site_properties.manage_changeProperties(
00043                             localLongTimeFormat='%m-%d-%Y %I:%M %p')
00044         self.assertEqual(self.script(date),
00045                          DateTime(date).strftime(format))
00046         self.assertEqual(self.script(DateTime(date)),
00047                          DateTime(date).strftime(format))
00048 
00049     def testFormatDict(self):
00050         self.assertEqual(self.script({'a':1,'b':2}), 'a: 1, b: 2')
00051 
00052     def testFormatList(self):
00053         self.assertEqual(self.script(('a','b',1,2,3,4)), 'a, b, 1, 2, 3, 4')
00054         self.assertEqual(self.script(['a','b',1,2,3,4]), 'a, b, 1, 2, 3, 4')
00055         # this also needs to be able to handle unicode that won't encode to ascii
00056         ustr = 'i\xc3\xadacute'.decode('utf8')
00057         self.assertEqual(self.script(['a','b',ustr]), 'a, b, i\xc3\xadacute'.decode('utf8'))
00058 
00059     def testFormatString(self):
00060         self.assertEqual(self.script('fkj dsh ekjhsdf kjer'), 'fkj dsh ekjhsdf kjer')
00061 
00062     def testFormatTruncates(self):
00063         self.portal.portal_properties.site_properties.manage_changeProperties(
00064                             search_results_description_length=12, ellipsis='???')
00065         self.assertEqual(self.script('fkj dsh ekjhsdf kjer'), 'fkj dsh ekjh???')
00066 
00067     def testFormatStrange(self):
00068         self.assertEqual(self.script(None), '')
00069         self.assertEqual(self.script(Missing.Value()), '')
00070 
00071     def testUnicodeValue(self):
00072         """ Make sure non-ascii encodable unicode is acceptable """
00073         
00074         ustr = 'i\xc3\xadacute'.decode('utf8')
00075         self.assertEqual(self.script(ustr), ustr)
00076 
00077 tests.append(TestFormatCatalogMetadata)
00078 
00079 import unittest
00080 def test_suite():
00081     suite = unittest.TestSuite()
00082     for test in tests:
00083         suite.addTest(unittest.makeSuite(test))
00084     return suite