2 Testing for hierarchical search in M2M
4 !python {model: res.partner }: |
5 ids = self.search(cr, uid, [('category_id', 'child_of','supplier')])
6 assert len(ids) >= 1, ids
9 Test hierarchical search in M2M with child ID1
11 !python {model: res.partner }: |
12 ids = self.search(cr, uid, [('category_id', 'child_of','Components Supplier')])
13 assert len(ids) >= 1, ids
15 Test hierarchical search in M2M with child ID2
17 !python {model: res.partner }: |
18 ids = self.search(cr, uid, [('category_id', 'child_of','Miscellaneous Suppliers')])
19 assert len(ids) >= 1, ids
22 "1.0 Setup test partner categories: parent root"
24 !record {model: res.partner.category, id: categ_root}:
27 "1.1 Setup test partner categories: parent category"
29 !record {model: res.partner.category, id: categ_0}:
33 "1.2 Setup test partner categories: child 1"
35 !record {model: res.partner.category, id: categ_1}:
39 Test hierarchical search in M2M with child ID (list of ids)
41 !python {model: res.partner.category }: |
42 ids = self.search(cr, uid, [('id', 'child_of',[ref('categ_root')])])
43 assert len(ids) == 3, ids
45 Test hierarchical search in M2M with child ID (single id)
47 !python {model: res.partner.category }: |
48 ids = self.search(cr, uid, [('id', 'child_of',ref('categ_root'))])
49 assert len(ids) == 3, ids
51 Test hierarchical search in M2M with child IDs
53 !python {model: res.partner.category }: |
54 ids = self.search(cr, uid, [('id', 'child_of',[ref('categ_1'), ref('categ_0')])])
55 assert len(ids) == 2, ids
57 Test hierarchical search in M2M with child IDs
59 !python {model: res.partner.category }: |
60 ids = self.search(cr, uid, [('id', 'child_of',[ref('categ_0')])])
61 assert len(ids) == 2, ids
63 Test hierarchical search in M2M with child IDs
65 !python {model: res.partner.category }: |
66 ids = self.search(cr, uid, [('id', 'child_of',[ref('categ_1')])])
67 assert len(ids) == 1, ids
69 Testing that some domain expressions work
71 !python {model: res.partner.address }: |
72 ids = self.search(cr, uid, [('partner_id','=','Agrolait')])
73 assert len(ids) >= 1, ids
75 Trying the "in" operator, for scalar value
77 !python {model: res.partner.address }: |
78 ids = self.search(cr, uid, [('partner_id','in','Agrolait')])
79 assert len(ids) >= 1, ids
81 Trying the "in" operator for list value
83 !python {model: res.partner.address }: |
84 ids = self.search(cr, uid, [('partner_id','in',['Agrolait','ASUStek'])])
85 assert len(ids) >= 1, ids
87 Check we can use "in" operator for plain fields.
89 !python {model: ir.ui.menu }: |
90 ids = self.search(cr, uid, [('sequence','in',[1, 2, 10, 20])])
91 assert len(ids) >= 1, ids
93 Test one2many operator with empty search list
95 !assert {model: res.partner, search: "[('address', 'in', [])]", count: 0, string: "Ids should be empty"}
97 Test one2many operator with False
99 !assert {model: res.partner, search: "[('address', '=', False)]"}:
100 - address in (False, None, [])
102 Test many2many operator with empty search list
104 !assert {model: res.partner, search: "[('category_id', 'in', [])]", count: 0, string: "Ids should be empty"}
106 Test many2many operator with False
108 !assert {model: res.partner, search: "[('category_id', '=', False)]"}:
109 - category_id in (False, None, [])
111 Filtering on invalid value across x2many relationship should return an empty set
113 !assert {model: res.partner, search: "[('address.city','=','foo')]", count: 0, string: "Searching for address.city = foo should give empty results"}
115 Check if many2one works with empty search list
117 !assert {model: res.partner, search: "[('company_id','in', [])]", count: 0, string: "Searching for company_id in [] should be empty!" }
119 For the sake of the following tests, I will create a second company
121 !record {model: res.company, id: ymltest_company2}:
124 And create a few partners with that company or no company
126 !python {model: res.partner }: |
128 self.create(cr, uid, { 'name': 'P of Acme %d' % r,
129 'company_id': ref('ymltest_company2') })
131 self.create(cr, uid, { 'name': 'P of All %d' % r,
132 'company_id': False })
134 Check if many2one works with negative empty list
136 !python {model: res.partner }: |
137 all_ids = self.search(cr, uid, [])
139 res_ids = self.search(cr, uid,['|',('company_id','not in', []), ('company_id','=',False)])
141 assert all_ids == res_ids, "not in [] fails"
143 Check that many2one will pick the correct records with a list
145 !python {model: res.partner }: |
146 res_ids = self.search(cr, uid, [('company_id', 'in', [False,])])
147 assert len(res_ids) >= 4, "We created 4 partners w/company, why find %d? %r" % \
148 (len(res_ids), res_ids)
150 Check that many2one will exclude the correct records with a list
152 !python {model: res.partner }: |
153 # assuming that the default company is #1
154 res_ids = self.search(cr, uid, [('company_id', 'not in', [1])])
155 assert len(res_ids) >= 4, "We should have found 4 records at least, only have %d! %r" % \
156 (len(res_ids), res_ids)
158 Check that we exclude the correct records, + False
160 !python {model: res.partner }: |
161 # assuming that the default company is #1
162 res_ids = self.search(cr, uid, ['|', ('company_id', 'not in', [1]), ('company_id', '=', False)])
163 assert len(res_ids) >= 8, "We should have found 8 records at least, only have %d! %r" % \
164 (len(res_ids), res_ids)
166 Check that multi-level expressions also work
168 !python {model: res.partner }: |
169 res_ids = self.search(cr, uid, [('company_id.partner_id', 'in', [])])
170 assert res_ids == [], "Searching an empty set should return empty result, not %r" % res_ids
172 Check that multi-level expressions with negative op work
174 !python {model: res.partner }: |
175 all_ids = self.search(cr, uid, [('company_id', '!=', False)])
177 res_ids = self.search(cr, uid, [('company_id.partner_id', 'not in', [])])
179 assert res_ids == all_ids, "Searching against empty set failed, returns %r" % res_ids
181 Verify that normalize_domain() works.
183 !python {model: res.partner}: |
184 from osv import expression
185 norm_domain = domain = ['&',(1,'=',1),('a','=','b')]
186 assert norm_domain == expression.normalize(domain), "Normalized domains should be left untouched"
187 domain = [('x','in',['y','z']),('a.v','=','e'),'|','|',('a','=','b'),'!',('c','>','d'),('e','!=','f'),('g','=','h')]
188 norm_domain = ['&','&','&'] + domain
189 assert norm_domain == expression.normalize(domain), "Non-normalized domains should be properly normalized"