[FIX] tests: db name moved from constant to function
Avoids initializing the DB constant too early when subcommand modules are loaded, making them unable to run db-backed tests later. Closes #6984
This commit is contained in:
parent
de20e18faa
commit
2df9060d97
|
@ -6,11 +6,10 @@ import openerp
|
||||||
from openerp.tools.misc import mute_logger
|
from openerp.tools.misc import mute_logger
|
||||||
from openerp.tests import common
|
from openerp.tests import common
|
||||||
|
|
||||||
DB = common.DB
|
|
||||||
ADMIN_USER_ID = common.ADMIN_USER_ID
|
ADMIN_USER_ID = common.ADMIN_USER_ID
|
||||||
|
|
||||||
def registry():
|
def registry():
|
||||||
return openerp.modules.registry.RegistryManager.get(DB)
|
return openerp.modules.registry.RegistryManager.get(common.get_db_name())
|
||||||
|
|
||||||
|
|
||||||
class test_cr_execute(unittest2.TestCase):
|
class test_cr_execute(unittest2.TestCase):
|
||||||
|
|
|
@ -14,14 +14,13 @@ import unittest2
|
||||||
import openerp
|
import openerp
|
||||||
from openerp.tests import common
|
from openerp.tests import common
|
||||||
|
|
||||||
DB = common.DB
|
|
||||||
ADMIN_USER_ID = common.ADMIN_USER_ID
|
ADMIN_USER_ID = common.ADMIN_USER_ID
|
||||||
|
|
||||||
def registry(model):
|
def registry(model):
|
||||||
return openerp.modules.registry.RegistryManager.get(DB)[model]
|
return openerp.modules.registry.RegistryManager.get(common.get_db_name())[model]
|
||||||
|
|
||||||
def cursor():
|
def cursor():
|
||||||
return openerp.modules.registry.RegistryManager.get(DB).cursor()
|
return openerp.modules.registry.RegistryManager.get(common.get_db_name()).cursor()
|
||||||
|
|
||||||
|
|
||||||
def drop_sequence(code):
|
def drop_sequence(code):
|
||||||
|
|
|
@ -3,7 +3,6 @@ from openerp.tools import mute_logger
|
||||||
from openerp.tests import common
|
from openerp.tests import common
|
||||||
|
|
||||||
UID = common.ADMIN_USER_ID
|
UID = common.ADMIN_USER_ID
|
||||||
DB = common.DB
|
|
||||||
|
|
||||||
|
|
||||||
class TestORM(common.TransactionCase):
|
class TestORM(common.TransactionCase):
|
||||||
|
|
|
@ -6,22 +6,21 @@ import openerp
|
||||||
from openerp import SUPERUSER_ID
|
from openerp import SUPERUSER_ID
|
||||||
import common
|
import common
|
||||||
|
|
||||||
DB = common.DB
|
|
||||||
ADMIN_USER_ID = common.ADMIN_USER_ID
|
ADMIN_USER_ID = common.ADMIN_USER_ID
|
||||||
|
|
||||||
def registry(model):
|
def registry(model):
|
||||||
return openerp.modules.registry.RegistryManager.get(DB)[model]
|
return openerp.modules.registry.RegistryManager.get(common.get_db_name())[model]
|
||||||
|
|
||||||
def cursor():
|
def cursor():
|
||||||
return openerp.modules.registry.RegistryManager.get(DB).cursor()
|
return openerp.modules.registry.RegistryManager.get(common.get_db_name()).cursor()
|
||||||
|
|
||||||
def get_module(module_name):
|
def get_module(module_name):
|
||||||
registry = openerp.modules.registry.RegistryManager.get(DB)
|
registry = openerp.modules.registry.RegistryManager.get(common.get_db_name())
|
||||||
return registry.get(module_name)
|
return registry.get(module_name)
|
||||||
|
|
||||||
def reload_registry():
|
def reload_registry():
|
||||||
openerp.modules.registry.RegistryManager.new(
|
openerp.modules.registry.RegistryManager.new(
|
||||||
DB, update_module=True)
|
common.get_db_name(), update_module=True)
|
||||||
|
|
||||||
def search_registry(model_name, domain):
|
def search_registry(model_name, domain):
|
||||||
cr = cursor()
|
cr = cursor()
|
||||||
|
|
|
@ -452,7 +452,7 @@ class TestTemplating(ViewCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
import openerp.modules
|
import openerp.modules
|
||||||
super(TestTemplating, self).setUp()
|
super(TestTemplating, self).setUp()
|
||||||
self._pool = openerp.modules.registry.RegistryManager.get(common.DB)
|
self._pool = openerp.modules.registry.RegistryManager.get(common.get_db_name())
|
||||||
self._init = self._pool._init
|
self._init = self._pool._init
|
||||||
# fuck off
|
# fuck off
|
||||||
self._pool._init = False
|
self._pool._init = False
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import openerp.tests.common
|
import openerp.tests.common
|
||||||
|
|
||||||
DB = openerp.tests.common.DB
|
|
||||||
|
|
||||||
class test_xmlrpc(openerp.tests.common.HttpCase):
|
class test_xmlrpc(openerp.tests.common.HttpCase):
|
||||||
at_install = False
|
at_install = False
|
||||||
|
@ -9,15 +8,17 @@ class test_xmlrpc(openerp.tests.common.HttpCase):
|
||||||
|
|
||||||
def test_01_xmlrpc_login(self):
|
def test_01_xmlrpc_login(self):
|
||||||
""" Try to login on the common service. """
|
""" Try to login on the common service. """
|
||||||
uid = self.xmlrpc_common.login(DB, 'admin', 'admin')
|
db_name = openerp.tests.common.get_db_name()
|
||||||
|
uid = self.xmlrpc_common.login(db_name, 'admin', 'admin')
|
||||||
self.assertEqual(uid, 1)
|
self.assertEqual(uid, 1)
|
||||||
|
|
||||||
def test_xmlrpc_ir_model_search(self):
|
def test_xmlrpc_ir_model_search(self):
|
||||||
""" Try a search on the object service. """
|
""" Try a search on the object service. """
|
||||||
o = self.xmlrpc_object
|
o = self.xmlrpc_object
|
||||||
ids = o.execute(DB, 1, 'admin', 'ir.model', 'search', [])
|
db_name = openerp.tests.common.get_db_name()
|
||||||
|
ids = o.execute(db_name, 1, 'admin', 'ir.model', 'search', [])
|
||||||
self.assertIsInstance(ids, list)
|
self.assertIsInstance(ids, list)
|
||||||
ids = o.execute(DB, 1, 'admin', 'ir.model', 'search', [], {})
|
ids = o.execute(db_name, 1, 'admin', 'ir.model', 'search', [], {})
|
||||||
self.assertIsInstance(ids, list)
|
self.assertIsInstance(ids, list)
|
||||||
|
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|
|
@ -31,16 +31,21 @@ _logger = logging.getLogger(__name__)
|
||||||
ADDONS_PATH = openerp.tools.config['addons_path']
|
ADDONS_PATH = openerp.tools.config['addons_path']
|
||||||
HOST = '127.0.0.1'
|
HOST = '127.0.0.1'
|
||||||
PORT = openerp.tools.config['xmlrpc_port']
|
PORT = openerp.tools.config['xmlrpc_port']
|
||||||
DB = openerp.tools.config['db_name']
|
|
||||||
# If the database name is not provided on the command-line,
|
|
||||||
# use the one on the thread (which means if it is provided on
|
|
||||||
# the command-line, this will break when installing another
|
|
||||||
# database from XML-RPC).
|
|
||||||
if not DB and hasattr(threading.current_thread(), 'dbname'):
|
|
||||||
DB = threading.current_thread().dbname
|
|
||||||
# Useless constant, tests are aware of the content of demo data
|
# Useless constant, tests are aware of the content of demo data
|
||||||
ADMIN_USER_ID = openerp.SUPERUSER_ID
|
ADMIN_USER_ID = openerp.SUPERUSER_ID
|
||||||
|
|
||||||
|
|
||||||
|
def get_db_name():
|
||||||
|
db = openerp.tools.config['db_name']
|
||||||
|
# If the database name is not provided on the command-line,
|
||||||
|
# use the one on the thread (which means if it is provided on
|
||||||
|
# the command-line, this will break when installing another
|
||||||
|
# database from XML-RPC).
|
||||||
|
if not db and hasattr(threading.current_thread(), 'dbname'):
|
||||||
|
return threading.current_thread().dbname
|
||||||
|
return db
|
||||||
|
|
||||||
|
|
||||||
def at_install(flag):
|
def at_install(flag):
|
||||||
""" Sets the at-install state of a test, the flag is a boolean specifying
|
""" Sets the at-install state of a test, the flag is a boolean specifying
|
||||||
whether the test should (``True``) or should not (``False``) run during
|
whether the test should (``True``) or should not (``False``) run during
|
||||||
|
@ -127,7 +132,7 @@ class TransactionCase(BaseCase):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.registry = RegistryManager.get(DB)
|
self.registry = RegistryManager.get(get_db_name())
|
||||||
#: current transaction's cursor
|
#: current transaction's cursor
|
||||||
self.cr = self.cursor()
|
self.cr = self.cursor()
|
||||||
self.uid = openerp.SUPERUSER_ID
|
self.uid = openerp.SUPERUSER_ID
|
||||||
|
@ -149,7 +154,7 @@ class SingleTransactionCase(BaseCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
cls.registry = RegistryManager.get(DB)
|
cls.registry = RegistryManager.get(get_db_name())
|
||||||
cls.cr = cls.registry.cursor()
|
cls.cr = cls.registry.cursor()
|
||||||
cls.uid = openerp.SUPERUSER_ID
|
cls.uid = openerp.SUPERUSER_ID
|
||||||
cls.env = api.Environment(cls.cr, cls.uid, {})
|
cls.env = api.Environment(cls.cr, cls.uid, {})
|
||||||
|
@ -200,7 +205,7 @@ class HttpCase(TransactionCase):
|
||||||
# setup a magic session_id that will be rollbacked
|
# setup a magic session_id that will be rollbacked
|
||||||
self.session = openerp.http.root.session_store.new()
|
self.session = openerp.http.root.session_store.new()
|
||||||
self.session_id = self.session.sid
|
self.session_id = self.session.sid
|
||||||
self.session.db = DB
|
self.session.db = get_db_name()
|
||||||
openerp.http.root.session_store.save(self.session)
|
openerp.http.root.session_store.save(self.session)
|
||||||
# setup an url opener helper
|
# setup an url opener helper
|
||||||
self.opener = urllib2.OpenerDirector()
|
self.opener = urllib2.OpenerDirector()
|
||||||
|
@ -222,7 +227,7 @@ class HttpCase(TransactionCase):
|
||||||
|
|
||||||
def authenticate(self, user, password):
|
def authenticate(self, user, password):
|
||||||
if user is not None:
|
if user is not None:
|
||||||
url = '/login?%s' % werkzeug.urls.url_encode({'db': DB,'login': user, 'key': password})
|
url = '/login?%s' % werkzeug.urls.url_encode({'db': get_db_name(),'login': user, 'key': password})
|
||||||
auth = self.url_open(url)
|
auth = self.url_open(url)
|
||||||
assert auth.getcode() < 400, "Auth failure %d" % auth.getcode()
|
assert auth.getcode() < 400, "Auth failure %d" % auth.getcode()
|
||||||
|
|
||||||
|
@ -322,7 +327,7 @@ class HttpCase(TransactionCase):
|
||||||
options = {
|
options = {
|
||||||
'timeout' : timeout,
|
'timeout' : timeout,
|
||||||
'port': PORT,
|
'port': PORT,
|
||||||
'db': DB,
|
'db': get_db_name(),
|
||||||
'session_id': self.session_id,
|
'session_id': self.session_id,
|
||||||
}
|
}
|
||||||
options.update(kw)
|
options.update(kw)
|
||||||
|
@ -352,7 +357,7 @@ class HttpCase(TransactionCase):
|
||||||
"""
|
"""
|
||||||
options = {
|
options = {
|
||||||
'port': PORT,
|
'port': PORT,
|
||||||
'db': DB,
|
'db': get_db_name(),
|
||||||
'url_path': url_path,
|
'url_path': url_path,
|
||||||
'code': code,
|
'code': code,
|
||||||
'ready': ready,
|
'ready': ready,
|
||||||
|
|
Loading…
Reference in New Issue