[FIX] ir.ui.view missing time libraries in qweb rendering context
[odoo/odoo.git] / openerp / tests / test_osv.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2010 OpenERP S.A. http://www.openerp.com
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 import unittest
23 from openerp.osv.query import Query
24
25
26 class QueryTestCase(unittest.TestCase):
27
28     def test_basic_query(self):
29         query = Query()
30         query.tables.extend(['"product_product"', '"product_template"'])
31         query.where_clause.append("product_product.template_id = product_template.id")
32         query.add_join(("product_template", "product_category", "categ_id", "id", "categ_id"), implicit=False, outer=False)  # add normal join
33         query.add_join(("product_product", "res_user", "user_id", "id", "user_id"), implicit=False, outer=True)  # outer join
34         self.assertEquals(query.get_sql()[0].strip(),
35             """"product_product" LEFT JOIN "res_user" as "product_product__user_id" ON ("product_product"."user_id" = "product_product__user_id"."id"),"product_template" JOIN "product_category" as "product_template__categ_id" ON ("product_template"."categ_id" = "product_template__categ_id"."id") """.strip())
36         self.assertEquals(query.get_sql()[1].strip(), """product_product.template_id = product_template.id""".strip())
37
38     def test_query_chained_explicit_joins(self):
39         query = Query()
40         query.tables.extend(['"product_product"', '"product_template"'])
41         query.where_clause.append("product_product.template_id = product_template.id")
42         query.add_join(("product_template", "product_category", "categ_id", "id", "categ_id"), implicit=False, outer=False)  # add normal join
43         query.add_join(("product_template__categ_id", "res_user", "user_id", "id", "user_id"), implicit=False, outer=True)  # CHAINED outer join
44         self.assertEquals(query.get_sql()[0].strip(),
45             """"product_product","product_template" JOIN "product_category" as "product_template__categ_id" ON ("product_template"."categ_id" = "product_template__categ_id"."id") LEFT JOIN "res_user" as "product_template__categ_id__user_id" ON ("product_template__categ_id"."user_id" = "product_template__categ_id__user_id"."id")""".strip())
46         self.assertEquals(query.get_sql()[1].strip(), """product_product.template_id = product_template.id""".strip())
47
48     def test_mixed_query_chained_explicit_implicit_joins(self):
49         query = Query()
50         query.tables.extend(['"product_product"', '"product_template"'])
51         query.where_clause.append("product_product.template_id = product_template.id")
52         query.add_join(("product_template", "product_category", "categ_id", "id", "categ_id"), implicit=False, outer=False)  # add normal join
53         query.add_join(("product_template__categ_id", "res_user", "user_id", "id", "user_id"), implicit=False, outer=True)  # CHAINED outer join
54         query.tables.append('"account.account"')
55         query.where_clause.append("product_category.expense_account_id = account_account.id")  # additional implicit join
56         self.assertEquals(query.get_sql()[0].strip(),
57             """"product_product","product_template" JOIN "product_category" as "product_template__categ_id" ON ("product_template"."categ_id" = "product_template__categ_id"."id") LEFT JOIN "res_user" as "product_template__categ_id__user_id" ON ("product_template__categ_id"."user_id" = "product_template__categ_id__user_id"."id"),"account.account" """.strip())
58         self.assertEquals(query.get_sql()[1].strip(), """product_product.template_id = product_template.id AND product_category.expense_account_id = account_account.id""".strip())
59
60     def test_raise_missing_lhs(self):
61         query = Query()
62         query.tables.append('"product_product"')
63         self.assertRaises(AssertionError, query.add_join, ("product_template", "product_category", "categ_id", "id", "categ_id"), implicit=False, outer=False)
64
65
66 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: