Add test ordering of selection field

issue7934
review66491002
This commit is contained in:
Cédric Krier committed 2018-12-30 00:14:59 +01:00
1 parent 93e3c0f9df
commit 5cab9c3995
2 files changed
+65

No files matched your search

+11
View File
@@ -39,8 +39,19 @@ class SelectionRequired(ModelSQL):
'Selection', required=True)
class SelectionLabel(ModelSQL):
"Selection with different label"
__name__ = 'test.selection_label'
select = fields.Selection([
('a', "Z"),
('b', "Y"),
('c', "X"),
], "Selection")
def register(module):
Pool.register(
Selection,
SelectionRequired,
SelectionLabel,
module=module, type_='model')
+54
View File
@@ -118,6 +118,60 @@ class FieldSelectionTestCase(unittest.TestCase):
'select': None,
}])
@with_transaction()
def test_search_order_label(self):
"Test search order by label"
pool = Pool()
Selection = pool.get('test.selection_label')
Selection.create([{'select': v} for v in ['a', 'b', 'c']])
records = Selection.search([], order=[('select', 'ASC')])
values = [r.select for r in records]
self.assertListEqual(values, ['c', 'b', 'a'])
@with_transaction()
def test_search_order_fixed_selection(self):
"Test search order by fixed selection"
pool = Pool()
Selection = pool.get('test.selection')
Selection.create([{'select': v} for v in ['', 'arabic', 'hexa']])
records = Selection.search([], order=[('select', 'DESC')])
values = [r.select for r in records]
self.assertListEqual(values, ['hexa', 'arabic', ''])
@with_transaction()
def test_search_order_static_selection(self):
"Test search order by static selection"
pool = Pool()
Selection = pool.get('test.selection')
Selection.create([
{'dyn_select_static': str(i)} for i in range(1, 4)])
records = Selection.search([], order=[('dyn_select_static', 'DESC')])
values = [r.dyn_select_static for r in records]
self.assertListEqual(values, ['3', '2', '1'])
@with_transaction()
def test_search_order_dynamic_selection(self):
"Test search order by dynamic selection"
pool = Pool()
Selection = pool.get('test.selection')
Selection.create([
{'select': 'arabic', 'dyn_select': str(i)}
for i in range(1, 4)])
Selection.create([
{'select': 'hexa', 'dyn_select': hex(i)}
for i in range(1, 4)])
records = Selection.search([], order=[('dyn_select', 'DESC')])
values = [r.dyn_select for r in records]
self.assertListEqual(values, ['3', '2', '1', '0x3', '0x2', '0x1'])
@with_transaction()
def test_string(self):
"Test string selection"