-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest_complex_sorting.py
More file actions
77 lines (62 loc) · 2.66 KB
/
Copy pathtest_complex_sorting.py
File metadata and controls
77 lines (62 loc) · 2.66 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from sqlobject import IntCol, SQLObject, StringCol, sqlmeta
from sqlobject.tests.dbtest import inserts, setupClass
# Test more complex orderBy clauses
class ComplexNames(SQLObject):
class sqlmeta(sqlmeta):
table = 'names_table'
defaultOrder = ['lastName', 'firstName', 'phone', 'age']
firstName = StringCol(length=30)
lastName = StringCol(length=30)
phone = StringCol(length=11)
age = IntCol()
def setupComplexNames():
setupClass(ComplexNames)
inserts(ComplexNames, [('aj', 'baker', '555-444-333', 34),
('joe', 'robbins', '444-555-333', 34),
('tim', 'jackson', '555-444-222', 32),
('joe', 'baker', '222-111-000', 24),
('zoe', 'robbins', '444-555-333', 46)],
schema='firstName lastName phone age')
def nameList(names):
result = []
for name in names:
result.append('%s %s' % (name.firstName, name.lastName))
return result
def firstList(names):
return [n.firstName for n in names]
def test_defaultComplexOrder():
setupComplexNames()
assert nameList(ComplexNames.select()) == \
['aj baker', 'joe baker',
'tim jackson', 'joe robbins',
'zoe robbins']
def test_complexOrders():
setupComplexNames()
assert nameList(ComplexNames.select().orderBy(['age', 'phone',
'firstName',
'lastName'])) == \
['joe baker', 'tim jackson',
'joe robbins', 'aj baker',
'zoe robbins']
assert nameList(ComplexNames.select().orderBy(['-age', 'phone',
'firstName',
'lastName'])) == \
['zoe robbins', 'joe robbins',
'aj baker', 'tim jackson',
'joe baker']
assert nameList(ComplexNames.select().orderBy(['age', '-phone',
'firstName',
'lastName'])) == \
['joe baker', 'tim jackson',
'aj baker', 'joe robbins',
'zoe robbins']
assert nameList(ComplexNames.select().orderBy(['-firstName', 'phone',
'lastName', 'age'])) == \
['zoe robbins', 'tim jackson',
'joe baker', 'joe robbins',
'aj baker']
assert nameList(ComplexNames.select().orderBy(['-firstName', '-phone',
'lastName', 'age'])) == \
['zoe robbins', 'tim jackson',
'joe robbins', 'joe baker',
'aj baker']