changeset 618cc2469404 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=618cc2469404
description:
Add test ordering of selection field
issue7934
review66491002
diffstat:
trytond/tests/field_selection.py | 11 +++++++
trytond/tests/test_field_selection.py | 54 +++++++++++++++++++++++++++++++++++
2 files changed, 65 insertions(+), 0 deletions(-)
diffs (87 lines):
diff -r 8f0c905a2974 -r 618cc2469404 trytond/tests/field_selection.py
--- a/trytond/tests/field_selection.py Sun Dec 30 00:14:27 2018 +0100
+++ b/trytond/tests/field_selection.py Sun Dec 30 00:14:59 2018 +0100
@@ -39,8 +39,19 @@
'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')
diff -r 8f0c905a2974 -r 618cc2469404 trytond/tests/test_field_selection.py
--- a/trytond/tests/test_field_selection.py Sun Dec 30 00:14:27 2018 +0100
+++ b/trytond/tests/test_field_selection.py Sun Dec 30 00:14:59 2018 +0100
@@ -119,6 +119,60 @@
}])
@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"
Selection = Pool().get('test.selection')