[IMP] cron: added yaml test.
[odoo/odoo.git] / openerp / addons / base / test / test_osv_expression.yml
1 -
2     Testing for hierarchical search in M2M
3 -
4     !python {model: res.partner }: |
5         ids = self.search(cr, uid, [('category_id', 'child_of','supplier')])
6         assert len(ids) >= 1, ids
7
8 -
9     Test hierarchical search in M2M with child ID1
10 -
11     !python {model: res.partner }: |
12         ids = self.search(cr, uid, [('category_id', 'child_of','Components Supplier')])
13         assert len(ids) >= 1, ids
14 -
15     Test hierarchical search in M2M with child ID2
16 -
17     !python {model: res.partner }: |
18         ids = self.search(cr, uid, [('category_id', 'child_of','Miscellaneous Suppliers')])
19         assert len(ids) >= 1, ids
20
21 -
22     "1.0 Setup test partner categories: parent root"
23 -
24     !record {model: res.partner.category, id: categ_root}:
25         name: Root category
26 -
27     "1.1 Setup test partner categories: parent category"
28 -
29     !record {model: res.partner.category, id: categ_0}:
30         name: Parent category
31         parent_id: categ_root
32 -
33     "1.2 Setup test partner categories: child 1"
34 -
35     !record {model: res.partner.category, id: categ_1}:
36         name: Child 1
37         parent_id: categ_0
38 -
39     Test hierarchical search in M2M with child ID (list of ids)
40 -
41     !python {model: res.partner.category }: |
42         ids = self.search(cr, uid, [('id', 'child_of',[ref('categ_root')])])
43         assert len(ids) == 3, ids
44 -
45     Test hierarchical search in M2M with child ID (single id)
46 -
47     !python {model: res.partner.category }: |
48         ids = self.search(cr, uid, [('id', 'child_of',ref('categ_root'))])
49         assert len(ids) == 3, ids
50 -
51     Test hierarchical search in M2M with child IDs
52 -
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
56 -
57     Test hierarchical search in M2M with child IDs
58 -
59     !python {model: res.partner.category }: |
60         ids = self.search(cr, uid, [('id', 'child_of',[ref('categ_0')])])
61         assert len(ids) == 2, ids
62 -
63     Test hierarchical search in M2M with child IDs
64 -
65     !python {model: res.partner.category }: |
66         ids = self.search(cr, uid, [('id', 'child_of',[ref('categ_1')])])
67         assert len(ids) == 1, ids
68 -
69     Testing that some domain expressions work
70 -
71     !python {model: res.partner.address }: |
72         ids = self.search(cr, uid, [('partner_id','=','Agrolait')])
73         assert len(ids) >= 1, ids
74 -
75     Trying the "in" operator, for scalar value
76 -
77     !python {model: res.partner.address }: |
78         ids = self.search(cr, uid, [('partner_id','in','Agrolait')])
79         assert len(ids) >= 1, ids
80 -
81     Trying the "in" operator for list value
82 -
83     !python {model: res.partner.address }: |
84         ids = self.search(cr, uid, [('partner_id','in',['Agrolait','ASUStek'])])
85         assert len(ids) >= 1, ids
86 -
87     Check we can use "in" operator for plain fields.
88 -
89     !python {model: ir.ui.menu }: |
90         ids = self.search(cr, uid, [('sequence','in',[1, 2, 10, 20])])
91         assert len(ids) >= 1, ids
92 -
93     Test one2many operator with empty search list
94 -
95     !assert {model: res.partner, search: "[('address', 'in', [])]", count: 0, string: "Ids should be empty"}
96 -
97     Test one2many operator with False
98 -
99     !assert {model: res.partner, search: "[('address', '=', False)]"}:
100         - address in (False, None, [])
101 -
102     Test many2many operator with empty search list
103 -
104     !assert {model: res.partner, search: "[('category_id', 'in', [])]", count: 0, string: "Ids should be empty"}
105 -
106     Test many2many operator with False
107 -
108     !assert {model: res.partner, search: "[('category_id', '=', False)]"}:
109         - category_id in (False, None, [])
110 -
111     Filtering on invalid value across x2many relationship should return an empty set
112 -
113     !assert {model: res.partner, search: "[('address.city','=','foo')]", count: 0, string: "Searching for address.city = foo should give empty results"}
114 -
115     Check if many2one works with empty search list
116 -
117     !assert {model: res.partner, search: "[('company_id','in', [])]", count: 0, string: "Searching for company_id in [] should be empty!" }
118 -
119     For the sake of the following tests, I will create a second company
120 -
121     !record {model: res.company, id: ymltest_company2}:
122         name: Acme 2
123 -
124     And create a few partners with that company or no company
125 -
126     !python {model: res.partner }: |
127         for r in range(4):
128             self.create(cr, uid, { 'name': 'P of Acme %d' % r,
129                     'company_id': ref('ymltest_company2') })
130         for r in range(4):
131             self.create(cr, uid, { 'name': 'P of All %d' % r,
132                     'company_id': False })
133 -
134     Check if many2one works with negative empty list
135 -
136     !python {model: res.partner }: |
137         all_ids = self.search(cr, uid, [])
138         all_ids.sort()
139         res_ids = self.search(cr, uid,['|',('company_id','not in', []), ('company_id','=',False)])
140         res_ids.sort()
141         assert all_ids == res_ids, "not in [] fails"
142 -
143     Check that many2one will pick the correct records with a list
144 -
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)
149 -
150     Check that many2one will exclude the correct records with a list
151 -
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)
157 -
158     Check that we exclude the correct records, + False
159 -
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)
165 -
166     Check that multi-level expressions also work
167 -
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
171 -
172     Check that multi-level expressions with negative op work
173 -
174     !python {model: res.partner }: |
175         all_ids = self.search(cr, uid, [('company_id', '!=', False)])
176         all_ids.sort()
177         res_ids = self.search(cr, uid, [('company_id.partner_id', 'not in', [])])
178         res_ids.sort()
179         assert res_ids == all_ids, "Searching against empty set failed, returns %r" % res_ids
180 -
181     Verify that normalize_domain() works.
182 -
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"
190
191
192