From 72014c4109efe982e71d202d85eb814046ae9d46 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Wed, 21 Nov 2012 12:45:57 +0100 Subject: [PATCH 1/5] [ADD] base: added python test on the search() method bzr revid: qdp-launchpad@openerp.com-20121121114557-5swzfuisp2apttd5 --- openerp/addons/base/tests/test_search.py | 55 ++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 openerp/addons/base/tests/test_search.py diff --git a/openerp/addons/base/tests/test_search.py b/openerp/addons/base/tests/test_search.py new file mode 100644 index 00000000000..bc8a26b94fa --- /dev/null +++ b/openerp/addons/base/tests/test_search.py @@ -0,0 +1,55 @@ +import unittest2 + +import openerp.tests.common as common + +class test_expression(common.TransactionCase): + + def test_search_order(self): + + registry, cr, uid = self.registry, self.cr, self.uid + + # Create 6 partners with a given name, and a given creation order to ensure the order of their ID. Some are set as unactive to verify they are by default excluded from the searchs and to provide a second order argument + + partners = registry('res.partner') + c = partners.create(cr, uid, {'name': 'test_search_order_C'}) + d = partners.create(cr, uid, {'name': 'test_search_order_D', 'active': False}) + a = partners.create(cr, uid, {'name': 'test_search_order_A'}) + b = partners.create(cr, uid, {'name': 'test_search_order_B'}) + ab = partners.create(cr, uid, {'name': 'test_search_order_AB'}) + e = partners.create(cr, uid, {'name': 'test_search_order_E', 'active': False}) + + # The tests. + + # The basic searchs should exclude records that have active = False. The order of ids returned + # should be given by the `order´ parameter of search() + + name_asc = partners.search(cr, uid, [('name', 'like', 'test_search_order%')], order="name asc") + self.assertEqual([a, ab, b, c]), name_asc), "Search with 'NAME ASC' order failed.") + name_desc = partners.search(cr, uid, [('name', 'like', 'test_search_order%')], order="name desc") + self.assertEqual([c, b, ab, a]), name_desc), "Search with 'NAME DESC' order failed.") + id_asc = partners.search(cr, uid, [('name', 'like', 'test_search_order%')], order="id asc") + self.assertEqual([c, a, b, ab]), id_asc), "Search with 'ID ASC' order failed.") + id_desc = partners.search(cr, uid, [('name', 'like', 'test_search_order%')], order="id desc") + self.assertEqual([ab, b, a, c]), id_desc), "Search with 'ID DESC' order failed.") + + # The inactive records shouldn't be ecxluded as soon as a condition on this field is present in the domain + # criteria. The `order´ parameter of search() should support any valable coma-separated value + + active_asc_id_asc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="active asc, id asc") + self.assertEqual([d, e, c, a, b, ab]), active_asc_id_asc), "Search with 'ACTIVE ASC, ID ASC' order failed.") + active_desc_id_asc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="active desc, id asc") + self.assertEqual([c, a, b, ab, d, e]), active_desc_id_asc), "Search with 'ACTIVE DESC, ID ASC' order failed.") + active_asc_id_desc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="active asc, id desc") + self.assertEqual([e, d, ab, b, a, c]), active_asc_id_desc), "Search with 'ACTIVE ASC, ID DESC' order failed.") + active_desc_id_desc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="active desc, id desc") + self.assertEqual([ab, b, a, c, e, d]), active_desc_id_desc), "Search with 'ACTIVE DESC, ID DESC' order failed.") + id_asc_active_asc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="id asc, active asc") + self.assertEqual(id_asc, id_asc_active_asc), "Search with 'ID ASC, ACTIVE ASC' order failed.") + id_asc_active_desc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="id asc, active desc") + self.assertEqual(id_asc, id_asc_active_desc), "Search with 'ID ASC, ACTIVE DESC' order failed.") + id_desc_active_asc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="id desc, active asc") + self.assertEqual(id_desc, id_desc_active_asc), "Search with 'ID DESC, ACTIVE ASC' order failed.") + id_desc_active_desc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="id desc, active desc") + self.assertEqual(id_desc, id_desc_active_desc), "Search with 'ID DESC, ACTIVE DESC' order failed.") + + From d0b4d040e1874a2ba5230dbe5bc4c6c1911c3ba5 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Wed, 21 Nov 2012 13:21:06 +0100 Subject: [PATCH 2/5] [FIX] base: fixed syntax errors and test import of test_search python test bzr revid: qdp-launchpad@openerp.com-20121121122106-4mrnlw4z01np21dq --- openerp/addons/base/tests/__init__.py | 3 ++- openerp/addons/base/tests/test_search.py | 28 ++++++++++++------------ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/openerp/addons/base/tests/__init__.py b/openerp/addons/base/tests/__init__.py index 409f9928c6f..e8ad035131b 100644 --- a/openerp/addons/base/tests/__init__.py +++ b/openerp/addons/base/tests/__init__.py @@ -1,7 +1,8 @@ -import test_base, test_expression, test_ir_values +import test_base, test_expression, test_search, test_ir_values checks = [ test_base, test_expression, + test_search, test_ir_values, ] diff --git a/openerp/addons/base/tests/test_search.py b/openerp/addons/base/tests/test_search.py index bc8a26b94fa..9ee883dfca2 100644 --- a/openerp/addons/base/tests/test_search.py +++ b/openerp/addons/base/tests/test_search.py @@ -21,35 +21,35 @@ class test_expression(common.TransactionCase): # The tests. # The basic searchs should exclude records that have active = False. The order of ids returned - # should be given by the `order´ parameter of search() + # should be given by the 'order' parameter of search() name_asc = partners.search(cr, uid, [('name', 'like', 'test_search_order%')], order="name asc") - self.assertEqual([a, ab, b, c]), name_asc), "Search with 'NAME ASC' order failed.") + self.assertEqual([a, ab, b, c], name_asc, "Search with 'NAME ASC' order failed.") name_desc = partners.search(cr, uid, [('name', 'like', 'test_search_order%')], order="name desc") - self.assertEqual([c, b, ab, a]), name_desc), "Search with 'NAME DESC' order failed.") + self.assertEqual([c, b, ab, a], name_desc, "Search with 'NAME DESC' order failed.") id_asc = partners.search(cr, uid, [('name', 'like', 'test_search_order%')], order="id asc") - self.assertEqual([c, a, b, ab]), id_asc), "Search with 'ID ASC' order failed.") + self.assertEqual([c, a, b, ab], id_asc, "Search with 'ID ASC' order failed.") id_desc = partners.search(cr, uid, [('name', 'like', 'test_search_order%')], order="id desc") - self.assertEqual([ab, b, a, c]), id_desc), "Search with 'ID DESC' order failed.") + self.assertEqual([ab, b, a, c], id_desc, "Search with 'ID DESC' order failed.") # The inactive records shouldn't be ecxluded as soon as a condition on this field is present in the domain - # criteria. The `order´ parameter of search() should support any valable coma-separated value + # criteria. The 'order' parameter of search() should support any valable coma-separated value active_asc_id_asc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="active asc, id asc") - self.assertEqual([d, e, c, a, b, ab]), active_asc_id_asc), "Search with 'ACTIVE ASC, ID ASC' order failed.") + self.assertEqual([d, e, c, a, b, ab], active_asc_id_asc, "Search with 'ACTIVE ASC, ID ASC' order failed.") active_desc_id_asc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="active desc, id asc") - self.assertEqual([c, a, b, ab, d, e]), active_desc_id_asc), "Search with 'ACTIVE DESC, ID ASC' order failed.") + self.assertEqual([c, a, b, ab, d, e], active_desc_id_asc, "Search with 'ACTIVE DESC, ID ASC' order failed.") active_asc_id_desc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="active asc, id desc") - self.assertEqual([e, d, ab, b, a, c]), active_asc_id_desc), "Search with 'ACTIVE ASC, ID DESC' order failed.") + self.assertEqual([e, d, ab, b, a, c], active_asc_id_desc, "Search with 'ACTIVE ASC, ID DESC' order failed.") active_desc_id_desc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="active desc, id desc") - self.assertEqual([ab, b, a, c, e, d]), active_desc_id_desc), "Search with 'ACTIVE DESC, ID DESC' order failed.") + self.assertEqual([ab, b, a, c, e, d], active_desc_id_desc, "Search with 'ACTIVE DESC, ID DESC' order failed.") id_asc_active_asc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="id asc, active asc") - self.assertEqual(id_asc, id_asc_active_asc), "Search with 'ID ASC, ACTIVE ASC' order failed.") + self.assertEqual(id_asc, id_asc_active_asc, "Search with 'ID ASC, ACTIVE ASC' order failed.") id_asc_active_desc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="id asc, active desc") - self.assertEqual(id_asc, id_asc_active_desc), "Search with 'ID ASC, ACTIVE DESC' order failed.") + self.assertEqual(id_asc, id_asc_active_desc, "Search with 'ID ASC, ACTIVE DESC' order failed.") id_desc_active_asc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="id desc, active asc") - self.assertEqual(id_desc, id_desc_active_asc), "Search with 'ID DESC, ACTIVE ASC' order failed.") + self.assertEqual(id_desc, id_desc_active_asc, "Search with 'ID DESC, ACTIVE ASC' order failed.") id_desc_active_desc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="id desc, active desc") - self.assertEqual(id_desc, id_desc_active_desc), "Search with 'ID DESC, ACTIVE DESC' order failed.") + self.assertEqual(id_desc, id_desc_active_desc, "Search with 'ID DESC, ACTIVE DESC' order failed.") From b4742249b4355880b9189f57c0de3f157b629a35 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Wed, 21 Nov 2012 13:53:47 +0100 Subject: [PATCH 3/5] [FIX] base: test_search, invalid use of search criterion 'active in (True, False)' replaced by 'active is True OR active is False' bzr revid: qdp-launchpad@openerp.com-20121121125347-hsihsibwz0igp03r --- openerp/addons/base/tests/test_search.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/openerp/addons/base/tests/test_search.py b/openerp/addons/base/tests/test_search.py index 9ee883dfca2..04fd4afe63e 100644 --- a/openerp/addons/base/tests/test_search.py +++ b/openerp/addons/base/tests/test_search.py @@ -35,21 +35,21 @@ class test_expression(common.TransactionCase): # The inactive records shouldn't be ecxluded as soon as a condition on this field is present in the domain # criteria. The 'order' parameter of search() should support any valable coma-separated value - active_asc_id_asc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="active asc, id asc") + active_asc_id_asc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), '|', ('active', '=', True), ('active', '=', False)], order="active asc, id asc") self.assertEqual([d, e, c, a, b, ab], active_asc_id_asc, "Search with 'ACTIVE ASC, ID ASC' order failed.") - active_desc_id_asc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="active desc, id asc") + active_desc_id_asc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), '|', ('active', '=', True), ('active', '=', False)], order="active desc, id asc") self.assertEqual([c, a, b, ab, d, e], active_desc_id_asc, "Search with 'ACTIVE DESC, ID ASC' order failed.") - active_asc_id_desc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="active asc, id desc") + active_asc_id_desc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), '|', ('active', '=', True), ('active', '=', False)], order="active asc, id desc") self.assertEqual([e, d, ab, b, a, c], active_asc_id_desc, "Search with 'ACTIVE ASC, ID DESC' order failed.") - active_desc_id_desc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="active desc, id desc") + active_desc_id_desc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), '|', ('active', '=', True), ('active', '=', False)], order="active desc, id desc") self.assertEqual([ab, b, a, c, e, d], active_desc_id_desc, "Search with 'ACTIVE DESC, ID DESC' order failed.") - id_asc_active_asc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="id asc, active asc") - self.assertEqual(id_asc, id_asc_active_asc, "Search with 'ID ASC, ACTIVE ASC' order failed.") - id_asc_active_desc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="id asc, active desc") - self.assertEqual(id_asc, id_asc_active_desc, "Search with 'ID ASC, ACTIVE DESC' order failed.") - id_desc_active_asc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="id desc, active asc") - self.assertEqual(id_desc, id_desc_active_asc, "Search with 'ID DESC, ACTIVE ASC' order failed.") - id_desc_active_desc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), ('active', 'in', (True, False))], order="id desc, active desc") - self.assertEqual(id_desc, id_desc_active_desc, "Search with 'ID DESC, ACTIVE DESC' order failed.") + id_asc_active_asc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), '|', ('active', '=', True), ('active', '=', False)], order="id asc, active asc") + self.assertEqual([c, d, a, b, ab, e], id_asc_active_asc, "Search with 'ID ASC, ACTIVE ASC' order failed.") + id_asc_active_desc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), '|', ('active', '=', True), ('active', '=', False)], order="id asc, active desc") + self.assertEqual([c, d, a, b, ab, e], id_asc_active_desc, "Search with 'ID ASC, ACTIVE DESC' order failed.") + id_desc_active_asc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), '|', ('active', '=', True), ('active', '=', False)], order="id desc, active asc") + self.assertEqual([e, ab, b, a, d, c], id_desc_active_asc, "Search with 'ID DESC, ACTIVE ASC' order failed.") + id_desc_active_desc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), '|', ('active', '=', True), ('active', '=', False)], order="id desc, active desc") + self.assertEqual([e, ab, b, a, d, c], id_desc_active_desc, "Search with 'ID DESC, ACTIVE DESC' order failed.") From 18b7592b8d73d1b4d01d3affec824279c042da4e Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Wed, 21 Nov 2012 14:07:36 +0100 Subject: [PATCH 4/5] [FIX] osv/orm: fixed the use of 'order' argument given to a search function in order to allow to order by 'ID DESC' and by ' + ID ASC/DESC' bzr revid: qdp-launchpad@openerp.com-20121121130736-guj7np9nk65zx3o1 --- openerp/osv/orm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py index c1f04dbbfa8..6a1f917caa1 100644 --- a/openerp/osv/orm.py +++ b/openerp/osv/orm.py @@ -4722,7 +4722,7 @@ class BaseModel(object): order_direction = order_split[1].strip() if len(order_split) == 2 else '' inner_clause = None if order_field == 'id': - order_by_clause = '"%s"."%s"' % (self._table, order_field) + order_by_elements.append('"%s"."id" %s' % (self._table, order_direction)) elif order_field in self._columns: order_column = self._columns[order_field] if order_column._classic_read: From dc3d462b9f4d836deab6be00d432778cba25e91d Mon Sep 17 00:00:00 2001 From: Vo Minh Thu Date: Wed, 21 Nov 2012 15:31:59 +0100 Subject: [PATCH 5/5] [IMP] test_search: comment typos. bzr revid: vmt@openerp.com-20121121143159-mppc6s7rezpwc3hx --- openerp/addons/base/tests/test_search.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/openerp/addons/base/tests/test_search.py b/openerp/addons/base/tests/test_search.py index 04fd4afe63e..dc554408667 100644 --- a/openerp/addons/base/tests/test_search.py +++ b/openerp/addons/base/tests/test_search.py @@ -8,7 +8,10 @@ class test_expression(common.TransactionCase): registry, cr, uid = self.registry, self.cr, self.uid - # Create 6 partners with a given name, and a given creation order to ensure the order of their ID. Some are set as unactive to verify they are by default excluded from the searchs and to provide a second order argument + # Create 6 partners with a given name, and a given creation order to + # ensure the order of their ID. Some are set as unactive to verify they + # are by default excluded from the searches and to provide a second + # `order` argument. partners = registry('res.partner') c = partners.create(cr, uid, {'name': 'test_search_order_C'}) @@ -20,8 +23,9 @@ class test_expression(common.TransactionCase): # The tests. - # The basic searchs should exclude records that have active = False. The order of ids returned - # should be given by the 'order' parameter of search() + # The basic searches should exclude records that have active = False. + # The order of the returned ids should be given by the `order` + # parameter of search(). name_asc = partners.search(cr, uid, [('name', 'like', 'test_search_order%')], order="name asc") self.assertEqual([a, ab, b, c], name_asc, "Search with 'NAME ASC' order failed.") @@ -32,8 +36,9 @@ class test_expression(common.TransactionCase): id_desc = partners.search(cr, uid, [('name', 'like', 'test_search_order%')], order="id desc") self.assertEqual([ab, b, a, c], id_desc, "Search with 'ID DESC' order failed.") - # The inactive records shouldn't be ecxluded as soon as a condition on this field is present in the domain - # criteria. The 'order' parameter of search() should support any valable coma-separated value + # The inactive records shouldn't be excluded as soon as a condition on + # that field is present in the domain. The `order` parameter of + # search() should support any legal coma-separated values. active_asc_id_asc = partners.search(cr, uid, [('name', 'like', 'test_search_order%'), '|', ('active', '=', True), ('active', '=', False)], order="active asc, id asc") self.assertEqual([d, e, c, a, b, ab], active_asc_id_asc, "Search with 'ACTIVE ASC, ID ASC' order failed.")