File: testSortObjects.py

package info (click to toggle)
zope-cmfplone 2.5.1-4etch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 7,752 kB
  • ctags: 5,237
  • sloc: python: 28,264; xml: 3,723; php: 129; makefile: 99; sh: 2
file content (52 lines) | stat: -rw-r--r-- 1,519 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#
# Tests the sortObjects script
#

import os, sys
if __name__ == '__main__':
    execfile(os.path.join(sys.path[0], 'framework.py'))

from Products.CMFPlone.tests import PloneTestCase
from Products.CMFPlone.tests import dummy


class TestSortObjects(PloneTestCase.PloneTestCase):

    def afterSetUp(self):
        self.items = [
            dummy.Item('d', 'fred'),
            dummy.Item('c', 'wilma'),
            dummy.Item('b', 'barney'),
            dummy.Item('a', 'betty'),
        ]
        self.items2 = [
            dummy.Item('D', 'Fred'),
            dummy.Item('c', 'Wilma'),
            dummy.Item('B', 'barney'),
            dummy.Item('a', 'betty'),
        ]

    def testSortObjectsDefault(self):
        # Sorts by title_or_id by default
        sorted = self.portal.sortObjects(self.items)
        self.assertEqual([x.getId() for x in sorted], ['b', 'a', 'd', 'c'])

    def testSortObjectById(self):
        # Sorts by passed in method
        sorted = self.portal.sortObjects(self.items, 'getId')
        self.assertEqual([x.getId() for x in sorted], ['a', 'b', 'c', 'd'])

    def testSortObjectsIsCaseInsensitive(self):
        # Sorts by passed in method
        sorted = self.portal.sortObjects(self.items2, 'getId')
        self.assertEqual([x.getId() for x in sorted], ['a', 'B', 'c', 'D'])


def test_suite():
    from unittest import TestSuite, makeSuite
    suite = TestSuite()
    suite.addTest(makeSuite(TestSortObjects))
    return suite

if __name__ == '__main__':
    framework()