4916fe06203d6a901e0d7cc43a4b7f7b69da4b5c
[odoo/odoo.git] / bin / addons / base / test / test_osv_expression.yml
1 -
2     Testing that some domain expressions work
3 -
4     !python {model: res.partner.address }: |
5         ids = self.search(cr, uid, [('partner_id','=','Agrolait')])
6         assert len(ids) >= 1, ids
7 -
8     Trying the "in" operator, for scalar value
9 -
10     !python {model: res.partner.address }: |
11         ids = self.search(cr, uid, [('partner_id','in','Agrolait')])
12         assert len(ids) >= 1, ids
13 -
14     Trying the "in" operator for list value
15 -
16     !python {model: res.partner.address }: |
17         ids = self.search(cr, uid, [('partner_id','in',['Agrolait','ASUStek'])])
18         assert len(ids) >= 1, ids
19 -
20     Check we can use "in" operator for plain fields.
21 -
22     !python {model: ir.ui.menu }: |
23         ids = self.search(cr, uid, [('sequence','in',[1, 2, 10, 20])])
24         assert len(ids) >= 1, ids
25 -
26     Test one2many operator with empty search list
27 -
28     !assert {model: res.partner, search: "[('address', 'in', [])]", count: 0, string: "Ids should be empty"}
29 -
30     Test one2many operator with False
31 -
32     !assert {model: res.partner, search: "[('address', '=', False)]"}:
33         - address in (False, None, [])
34 -
35     Test many2many operator with empty search list
36 -
37     !assert {model: res.partner, search: "[('category_id', 'in', [])]", count: 0, string: "Ids should be empty"}
38 -
39     Test many2many operator with False
40 -
41     !assert {model: res.partner, search: "[('category_id', '=', False)]"}:
42         - category_id in (False, None, [])
43
44     Filtering on invalid value across x2many relationship should return an empty set
45 -
46     !assert {model: res.partner, search: "[('address.city','=','foo')]", count: 0, string: "Searching for address.city = foo should give empty results"}
47 -
48     Check if many2one works with empty search list
49 -
50     !assert {model: res.partner, search: "[('company_id','in', [])]", count: 0, string: "Searching for company_id in [] should be empty!" }
51 -
52     For the sake of the following tests, I will create a second company
53 -
54     !record {model: res.company, id: ymltest_company2}:
55         name: Acme 2
56 -
57     And create a few partners with that company or no company
58 -
59     !python {model: res.partner }: |
60         for r in range(4):
61             self.create(cr, uid, { 'name': 'P of Acme %d' % r,
62                     'company_id': ref('ymltest_company2') })
63         for r in range(4):
64             self.create(cr, uid, { 'name': 'P of All %d' % r,
65                     'company_id': False })
66 -
67     Check if many2one works with negative empty list
68 -
69     !python {model: res.partner }: |
70         all_ids = self.search(cr, uid, [])
71         all_ids.sort()
72         res_ids = self.search(cr, uid,['|',('company_id','not in', []), ('company_id','=',False)])
73         res_ids.sort()
74         assert all_ids == res_ids, "not in [] fails"
75 -
76     Check that many2one will pick the correct records with a list
77 -
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)
82 -
83     Check that many2one will exclude the correct records with a list
84 -
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)
90 -
91     Check that we exclude the correct records, + False
92 -
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)
98 -
99     Check that multi-level expressions also work
100 -
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
104 -
105     Check that multi-level expressions with negative op work
106 -
107     !python {model: res.partner }: |
108         all_ids = self.search(cr, uid, [('company_id', '!=', False)])
109         all_ids.sort()
110         res_ids = self.search(cr, uid, [('company_id.partner_id', 'not in', [])])
111         res_ids.sort()
112         assert res_ids == all_ids, "Searching against empty set failed, returns %r" % res_ids
113