[IMP] base: test for expression distribute_not

Testing the use case of c28a28e, in which distribute_not was refactored
with iteration instead of recursion.
This commit is contained in:
Nicolas Lempereur 2015-11-05 15:08:17 +01:00
parent c28a28e69e
commit d24fcd1d2e
1 changed files with 20 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import unittest2
import openerp.osv.expression as expression
from openerp.osv.expression import get_unaccent_wrapper
from openerp.osv.orm import BaseModel
import openerp.tests.common as common
@ -459,6 +460,25 @@ class test_expression(common.TransactionCase):
partner_parent_id_col._auto_join = False
state_country_id_col._auto_join = False
def test_40_negating_long_expression(self):
source = ['!','&',('user_id','=',4),('partner_id','in',[1,2])]
expect = ['|',('user_id','!=',4),('partner_id','not in',[1,2])]
self.assertEqual(expression.distribute_not(source), expect,
"distribute_not on expression applied wrongly")
pos_leaves = [[('a', 'in', [])], [('d', '!=', 3)]]
neg_leaves = [[('a', 'not in', [])], [('d', '=', 3)]]
source = expression.OR([expression.AND(pos_leaves)] * 1000)
expect = source
self.assertEqual(expression.distribute_not(source), expect,
"distribute_not on long expression without negation operator should not alter it")
source = ['!'] + source
expect = expression.AND([expression.OR(neg_leaves)] * 1000)
self.assertEqual(expression.distribute_not(source), expect,
"distribute_not on long expression applied wrongly")
def test_translate_search(self):
Country = self.registry('res.country')
be = self.ref('base.be')