[MERGE] Make sure we pass only lists, tuples or dicts to Cursor.execute().
[odoo/odoo.git] / openerp / tests / test_db_cursor.py
1 # -*- coding: utf-8 -*-
2
3 import unittest2
4
5 import openerp
6 from openerp.tools.misc import mute_logger
7 import common
8
9 DB = common.DB
10 ADMIN_USER_ID = common.ADMIN_USER_ID
11
12 def cursor():
13     return openerp.modules.registry.RegistryManager.get(DB).db.cursor()
14
15
16 class test_cr_execute(unittest2.TestCase):
17     """ Try cr.execute with wrong parameters """
18
19     @mute_logger('openerp.sql_db')
20     def test_execute_bad_params(self):
21         """
22         Try to use iterable but non-list or int params in query parameters.
23         """
24         cr = cursor()
25         with self.assertRaises(ValueError):
26             cr.execute("SELECT id FROM res_users WHERE login=%s", 'admin')
27         with self.assertRaises(ValueError):
28             cr.execute("SELECT id FROM res_users WHERE id=%s", 1)
29         with self.assertRaises(ValueError):
30             cr.execute("SELECT id FROM res_users WHERE id=%s", '1')
31
32 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: