From 147fae832aeb481d00dbb2ae62553bcaecc6e706 Mon Sep 17 00:00:00 2001 From: Vo Minh Thu Date: Thu, 15 Nov 2012 13:39:37 +0100 Subject: [PATCH] [FIX] test_db_cursor: explicitely close the cursor (without relying on __del__). bzr revid: vmt@openerp.com-20121115123937-keq4eb2a3n85x0rv --- openerp/tests/test_db_cursor.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/openerp/tests/test_db_cursor.py b/openerp/tests/test_db_cursor.py index e9737547619..dba1cf47b64 100644 --- a/openerp/tests/test_db_cursor.py +++ b/openerp/tests/test_db_cursor.py @@ -9,8 +9,8 @@ import common DB = common.DB ADMIN_USER_ID = common.ADMIN_USER_ID -def cursor(): - return openerp.modules.registry.RegistryManager.get(DB).db.cursor() +def registry(): + return openerp.modules.registry.RegistryManager.get(DB) class test_cr_execute(unittest2.TestCase): @@ -21,12 +21,12 @@ class test_cr_execute(unittest2.TestCase): """ Try to use iterable but non-list or int params in query parameters. """ - cr = cursor() - with self.assertRaises(ValueError): - cr.execute("SELECT id FROM res_users WHERE login=%s", 'admin') - with self.assertRaises(ValueError): - cr.execute("SELECT id FROM res_users WHERE id=%s", 1) - with self.assertRaises(ValueError): - cr.execute("SELECT id FROM res_users WHERE id=%s", '1') + with registry().cursor(auto_commit=False) as cr: + with self.assertRaises(ValueError): + cr.execute("SELECT id FROM res_users WHERE login=%s", 'admin') + with self.assertRaises(ValueError): + cr.execute("SELECT id FROM res_users WHERE id=%s", 1) + with self.assertRaises(ValueError): + cr.execute("SELECT id FROM res_users WHERE id=%s", '1') # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: