2 Testing that some domain expressions work
4 !python {model: res.partner.address }: |
5 ids = self.search(cr, uid, [('partner_id','=','Agrolait')])
6 assert len(ids) >= 1, ids
8 Trying the "in" operator, for scalar value
10 !python {model: res.partner.address }: |
11 ids = self.search(cr, uid, [('partner_id','in','Agrolait')])
12 assert len(ids) >= 1, ids
14 Trying the "in" operator for list value
16 !python {model: res.partner.address }: |
17 ids = self.search(cr, uid, [('partner_id','in',['Agrolait','ASUStek'])])
18 assert len(ids) >= 1, ids
20 Check we can use "in" operator for plain fields.
22 !python {model: ir.ui.menu }: |
23 ids = self.search(cr, uid, [('sequence','in',[1, 2, 10, 20])])
24 assert len(ids) >= 1, ids
26 Test one2many operator with empty search list
28 !assert {model: res.partner, search: "[('address', 'in', [])]", count: 0, string: "Ids should be empty"}
30 Test one2many operator with False
32 !assert {model: res.partner, search: "[('address', '=', False)]"}:
33 - address in (False, None, [])
35 Test many2many operator with empty search list
37 !assert {model: res.partner, search: "[('category_id', 'in', [])]", count: 0, string: "Ids should be empty"}
39 Test many2many operator with False
41 !assert {model: res.partner, search: "[('category_id', '=', False)]"}:
42 - category_id in (False, None, [])
44 Filtering on invalid value across x2many relationship should return an empty set
46 !assert {model: res.partner, search: "[('address.city','=','foo')]", count: 0, string: "Searching for address.city = foo should give empty results"}
48 Check if many2one works with empty search list
50 !assert {model: res.partner, search: "[('company_id','in', [])]", count: 0, string: "Searching for company_id in [] should be empty!" }
52 For the sake of the following tests, I will create a second company
54 !record {model: res.company, id: ymltest_company2}:
57 And create a few partners with that company or no company
59 !python {model: res.partner }: |
61 self.create(cr, uid, { 'name': 'P of Acme %d' % r,
62 'company_id': ref('ymltest_company2') })
64 self.create(cr, uid, { 'name': 'P of All %d' % r,
65 'company_id': False })
67 Check if many2one works with negative empty list
69 !python {model: res.partner }: |
70 all_ids = self.search(cr, uid, [])
72 res_ids = self.search(cr, uid,['|',('company_id','not in', []), ('company_id','=',False)])
74 assert all_ids == res_ids, "not in [] fails"
76 Check that many2one will pick the correct records with a list
78 !python {model: res.partner }: |
79 res_ids = self.search(cr, uid, [('company_id', 'in', [False,])])
80 assert len(res_ids) >= 4, "We created 4 partners w/company, why find %d? %r" % \
81 (len(res_ids), res_ids)
83 Check that many2one will exclude the correct records with a list
85 !python {model: res.partner }: |
86 # assuming that the default company is #1
87 res_ids = self.search(cr, uid, [('company_id', 'not in', [1])])
88 assert len(res_ids) >= 4, "We should have found 4 records at least, only have %d! %r" % \
89 (len(res_ids), res_ids)
91 Check that we exclude the correct records, + False
93 !python {model: res.partner }: |
94 # assuming that the default company is #1
95 res_ids = self.search(cr, uid, ['|', ('company_id', 'not in', [1]), ('company_id', '=', False)])
96 assert len(res_ids) >= 8, "We should have found 8 records at least, only have %d! %r" % \
97 (len(res_ids), res_ids)
99 Check that multi-level expressions also work
101 !python {model: res.partner }: |
102 res_ids = self.search(cr, uid, [('company_id.partner_id', 'in', [])])
103 assert res_ids == [], "Searching an empty set should return empty result, not %r" % res_ids
105 Check that multi-level expressions with negative op work
107 !python {model: res.partner }: |
108 all_ids = self.search(cr, uid, [('company_id', '!=', False)])
110 res_ids = self.search(cr, uid, [('company_id.partner_id', 'not in', [])])
112 assert res_ids == all_ids, "Searching against empty set failed, returns %r" % res_ids
114 Check that we can exclude translated fields (bug lp:1071710)
116 !python {model: res.country}: |
117 # first install french language
118 BLI = self.pool.get('base.language.install')
119 BLI.lang_install(cr, uid, [BLI.create(cr, uid, {'lang': 'fr_FR'})])
121 be_id = self.search(cr, uid, [('name', '=', 'Belgium')])[0]
123 ctx = {'lang': 'fr_FR'}
124 not_be = self.search(cr, uid, [('name', '!=', 'Belgique')], context=ctx)
126 assert be_id not in not_be, "Search match failed"