From 5cab9c3995fd4cea0578b8e5fe740eb570b4ff4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 30 Dec 2018 00:14:59 +0100 Subject: [PATCH] Add test ordering of selection field issue7934 review66491002 --- trytond/tests/field_selection.py | 11 ++++++ trytond/tests/test_field_selection.py | 54 +++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/trytond/tests/field_selection.py b/trytond/tests/field_selection.py index ca41f63f9d..598b39bdbe 100644 --- a/trytond/tests/field_selection.py +++ b/trytond/tests/field_selection.py @@ -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') diff --git a/trytond/tests/test_field_selection.py b/trytond/tests/test_field_selection.py index e276083eee..ee8591fde2 100644 --- a/trytond/tests/test_field_selection.py +++ b/trytond/tests/test_field_selection.py @@ -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"