odoo/openerp/addons/base/test/test_osv_expression.yml

126 lines
5.0 KiB
YAML

-
Testing that some domain expressions work
-
!python {model: res.partner.address }: |
ids = self.search(cr, uid, [('partner_id','=','Agrolait')])
assert len(ids) >= 1, ids
-
Trying the "in" operator, for scalar value
-
!python {model: res.partner.address }: |
ids = self.search(cr, uid, [('partner_id','in','Agrolait')])
assert len(ids) >= 1, ids
-
Trying the "in" operator for list value
-
!python {model: res.partner.address }: |
ids = self.search(cr, uid, [('partner_id','in',['Agrolait','ASUStek'])])
assert len(ids) >= 1, ids
-
Check we can use "in" operator for plain fields.
-
!python {model: ir.ui.menu }: |
ids = self.search(cr, uid, [('sequence','in',[1, 2, 10, 20])])
assert len(ids) >= 1, ids
-
Test one2many operator with empty search list
-
!assert {model: res.partner, search: "[('address', 'in', [])]", count: 0, string: "Ids should be empty"}
-
Test one2many operator with False
-
!assert {model: res.partner, search: "[('address', '=', False)]"}:
- address in (False, None, [])
-
Test many2many operator with empty search list
-
!assert {model: res.partner, search: "[('category_id', 'in', [])]", count: 0, string: "Ids should be empty"}
-
Test many2many operator with False
-
!assert {model: res.partner, search: "[('category_id', '=', False)]"}:
- category_id in (False, None, [])
-
Filtering on invalid value across x2many relationship should return an empty set
-
!assert {model: res.partner, search: "[('address.city','=','foo')]", count: 0, string: "Searching for address.city = foo should give empty results"}
-
Check if many2one works with empty search list
-
!assert {model: res.partner, search: "[('company_id','in', [])]", count: 0, string: "Searching for company_id in [] should be empty!" }
-
For the sake of the following tests, I will create a second company
-
!record {model: res.company, id: ymltest_company2}:
name: Acme 2
-
And create a few partners with that company or no company
-
!python {model: res.partner }: |
for r in range(4):
self.create(cr, uid, { 'name': 'P of Acme %d' % r,
'company_id': ref('ymltest_company2') })
for r in range(4):
self.create(cr, uid, { 'name': 'P of All %d' % r,
'company_id': False })
-
Check if many2one works with negative empty list
-
!python {model: res.partner }: |
all_ids = self.search(cr, uid, [])
all_ids.sort()
res_ids = self.search(cr, uid,['|',('company_id','not in', []), ('company_id','=',False)])
res_ids.sort()
assert all_ids == res_ids, "not in [] fails"
-
Check that many2one will pick the correct records with a list
-
!python {model: res.partner }: |
res_ids = self.search(cr, uid, [('company_id', 'in', [False,])])
assert len(res_ids) >= 4, "We created 4 partners w/company, why find %d? %r" % \
(len(res_ids), res_ids)
-
Check that many2one will exclude the correct records with a list
-
!python {model: res.partner }: |
# assuming that the default company is #1
res_ids = self.search(cr, uid, [('company_id', 'not in', [1])])
assert len(res_ids) >= 4, "We should have found 4 records at least, only have %d! %r" % \
(len(res_ids), res_ids)
-
Check that we exclude the correct records, + False
-
!python {model: res.partner }: |
# assuming that the default company is #1
res_ids = self.search(cr, uid, ['|', ('company_id', 'not in', [1]), ('company_id', '=', False)])
assert len(res_ids) >= 8, "We should have found 8 records at least, only have %d! %r" % \
(len(res_ids), res_ids)
-
Check that multi-level expressions also work
-
!python {model: res.partner }: |
res_ids = self.search(cr, uid, [('company_id.partner_id', 'in', [])])
assert res_ids == [], "Searching an empty set should return empty result, not %r" % res_ids
-
Check that multi-level expressions with negative op work
-
!python {model: res.partner }: |
all_ids = self.search(cr, uid, [('company_id', '!=', False)])
all_ids.sort()
res_ids = self.search(cr, uid, [('company_id.partner_id', 'not in', [])])
res_ids.sort()
assert res_ids == all_ids, "Searching against empty set failed, returns %r" % res_ids
-
Verify that normalize_domain() works.
-
!python {model: res.partner}: |
from osv.expression import expression
norm_domain = domain = ['&',(1,'=',1),('a','=','b')]
assert norm_domain == expression.normalize_domain(domain), "Normalized domains should be left untouched"
domain = [('x','in',['y','z']),('a.v','=','e'),'|','|',('a','=','b'),'!',('c','>','d'),('e','!=','f'),('g','=','h')]
norm_domain = ['&','&','&'] + domain
assert norm_domain == expression.normalize_domain(domain), "Non-normalized domains should be properly normalized"