Back to index

plone3  3.1.7
testSortObjects.py
Go to the documentation of this file.
00001 #
00002 # Tests the sortObjects script
00003 #
00004 
00005 from Products.CMFPlone.tests import PloneTestCase
00006 from Products.CMFPlone.tests import dummy
00007 
00008 
00009 class TestSortObjects(PloneTestCase.PloneTestCase):
00010 
00011     def afterSetUp(self):
00012         self.items = [
00013             dummy.Item('d', 'fred'),
00014             dummy.Item('c', 'wilma'),
00015             dummy.Item('b', 'barney'),
00016             dummy.Item('a', 'betty'),
00017         ]
00018         self.items2 = [
00019             dummy.Item('D', 'Fred'),
00020             dummy.Item('c', 'Wilma'),
00021             dummy.Item('B', 'barney'),
00022             dummy.Item('a', 'betty'),
00023         ]
00024 
00025     def testSortObjectsDefault(self):
00026         # Sorts by title_or_id by default
00027         sorted = self.portal.sortObjects(self.items)
00028         self.assertEqual([x.getId() for x in sorted], ['b', 'a', 'd', 'c'])
00029 
00030     def testSortObjectById(self):
00031         # Sorts by passed in method
00032         sorted = self.portal.sortObjects(self.items, 'getId')
00033         self.assertEqual([x.getId() for x in sorted], ['a', 'b', 'c', 'd'])
00034 
00035     def testSortObjectsIsCaseInsensitive(self):
00036         # Sorts by passed in method
00037         sorted = self.portal.sortObjects(self.items2, 'getId')
00038         self.assertEqual([x.getId() for x in sorted], ['a', 'B', 'c', 'D'])
00039 
00040 
00041 def test_suite():
00042     from unittest import TestSuite, makeSuite
00043     suite = TestSuite()
00044     suite.addTest(makeSuite(TestSortObjects))
00045     return suite