author | Lennard de Rijk <ljvderijk@gmail.com> |
Fri, 03 Jul 2009 18:09:48 +0200 | |
changeset 2509 | 3788c916776f |
parent 1688 | f8457a410d1f |
permissions | -rw-r--r-- |
1614
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
2 |
# |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2009 the Melange authors. |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
4 |
# |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
8 |
# |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
10 |
# |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
16 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
17 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
18 |
__authors__ = [ |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
19 |
'"Sverre Rabbelier" <sverre@rabbelier.nl>', |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
20 |
] |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
21 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
22 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
23 |
import unittest |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
24 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
25 |
from google.appengine.api import users |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
26 |
|
1688
f8457a410d1f
Split out test_model model and logic into it's own module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1673
diff
changeset
|
27 |
from tests.app.soc.logic.models.test_model import TestModelLogic |
f8457a410d1f
Split out test_model model and logic into it's own module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1673
diff
changeset
|
28 |
from tests.app.soc.models.test_model import TestModel |
1614
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
29 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
30 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
31 |
class UserTest(unittest.TestCase): |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
32 |
"""Tests related to user logic. |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
33 |
""" |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
34 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
35 |
def setUp(self): |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
36 |
"""Set up required for the slot allocation tests. |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
37 |
""" |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
38 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
39 |
entities = [] |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
40 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
41 |
for i in range(5): |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
42 |
entity = TestModel(key_name='test_%d' % i, value=i) |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
43 |
entity.put() |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
44 |
entities.append(entity) |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
45 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
46 |
self.logic = TestModelLogic() |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
47 |
self.entities = entities |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
48 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
49 |
def testGetForFields(self): |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
50 |
"""Test that all entries were retrieved. |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
51 |
""" |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
52 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
53 |
expected = set(range(5)) |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
54 |
actual = set([i.value for i in self.logic.getForFields()]) |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
55 |
self.assertEqual(expected, actual) |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
56 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
57 |
def testGetForFieldsFiltered(self): |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
58 |
"""Test that only the entry that matches the filter is retrieved. |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
59 |
""" |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
60 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
61 |
fields = {'value': 1} |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
62 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
63 |
expected = [1] |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
64 |
actual = [i.value for i in self.logic.getForFields(fields)] |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
65 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
66 |
self.assertEqual(expected, actual) |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
67 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
68 |
def testGetForFieldsWithOperator(self): |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
69 |
"""Test that all entries matching the filter are retrieved. |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
70 |
""" |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
71 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
72 |
fields = {'value <': 3} |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
73 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
74 |
expected = set(range(3)) |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
75 |
actual = set([i.value for i in self.logic.getForFields(fields)]) |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
76 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
77 |
self.assertEqual(expected, actual) |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
78 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
79 |
def testGetForFieldsNonMatching(self): |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
80 |
"""Test that unique returns None instead of a list. |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
81 |
""" |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
82 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
83 |
fields = {'value': 1337} |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
84 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
85 |
expected = [] |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
86 |
actual = self.logic.getForFields(fields) |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
87 |
self.assertEqual(expected, actual) |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
88 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
89 |
def testGetForFieldsUnique(self): |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
90 |
"""Test that unique returns an entry instead of a list. |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
91 |
""" |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
92 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
93 |
fields = {'value': 1} |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
94 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
95 |
actual = self.logic.getForFields(fields, unique=True) |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
96 |
self.assertTrue(isinstance(actual, TestModel)) |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
97 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
98 |
def testGetForFieldsUniqueEmpty(self): |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
99 |
"""Test that unique returns None instead of a list. |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
100 |
""" |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
101 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
102 |
fields = {'value': 1337} |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
103 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
104 |
expected = None |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
105 |
actual = self.logic.getForFields(fields, unique=True) |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
106 |
self.assertEqual(expected, actual) |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
107 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
108 |
def testGetForFieldsMultiFilter(self): |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
109 |
"""Test that all entries matching an 'IN' filter are returned. |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
110 |
""" |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
111 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
112 |
fields = {'value': [1, 2]} |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
113 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
114 |
expected = 2 |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
115 |
actual = len(self.logic.getForFields(fields)) |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
116 |
self.assertEqual(expected, actual) |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
117 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
118 |
def testGetFieldsOrdened(self): |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
119 |
"""Test that fields can be ordened. |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
120 |
""" |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
121 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
122 |
order = ['value'] |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
123 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
124 |
expected = range(5) |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
125 |
actual = [i.value for i in self.logic.getForFields(order=order)] |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
126 |
self.assertEqual(expected, actual) |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
127 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
128 |
def testGetFieldsReverseOrdened(self): |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
129 |
"""Test that fields can be ordened in reverse. |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
130 |
""" |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
131 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
132 |
order = ['-value'] |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
133 |
|
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
134 |
expected = range(5) |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
135 |
expected.reverse() |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
136 |
actual = [i.value for i in self.logic.getForFields(order=order)] |
797f5ae462e7
Convert getForFields back to the Query API and add tests
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
137 |
self.assertEqual(expected, actual) |
1673
9f67ec81f1ef
Add a test to ensure that ordening and filtering works
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1614
diff
changeset
|
138 |
|
9f67ec81f1ef
Add a test to ensure that ordening and filtering works
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1614
diff
changeset
|
139 |
def testGetFieldsFilteredOrdened(self): |
9f67ec81f1ef
Add a test to ensure that ordening and filtering works
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1614
diff
changeset
|
140 |
"""Test that fields can be filtered and ordened. |
9f67ec81f1ef
Add a test to ensure that ordening and filtering works
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1614
diff
changeset
|
141 |
""" |
9f67ec81f1ef
Add a test to ensure that ordening and filtering works
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1614
diff
changeset
|
142 |
|
9f67ec81f1ef
Add a test to ensure that ordening and filtering works
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1614
diff
changeset
|
143 |
order = ['-value'] |
9f67ec81f1ef
Add a test to ensure that ordening and filtering works
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1614
diff
changeset
|
144 |
|
9f67ec81f1ef
Add a test to ensure that ordening and filtering works
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1614
diff
changeset
|
145 |
fields = {'value': [1,2, 3, 4]} |
9f67ec81f1ef
Add a test to ensure that ordening and filtering works
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1614
diff
changeset
|
146 |
|
9f67ec81f1ef
Add a test to ensure that ordening and filtering works
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1614
diff
changeset
|
147 |
expected = [4, 3, 2, 1] |
9f67ec81f1ef
Add a test to ensure that ordening and filtering works
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1614
diff
changeset
|
148 |
actual = [i.value for i in self.logic.getForFields(fields, order=order)] |
9f67ec81f1ef
Add a test to ensure that ordening and filtering works
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1614
diff
changeset
|
149 |
self.assertEqual(expected, actual) |