[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.tests import common
|
||||
|
||||
DB = common.DB
|
||||
ADMIN_USER_ID = common.ADMIN_USER_ID
|
||||
|
||||
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):
|
||||
|
|
|
@ -14,14 +14,13 @@ import unittest2
|
|||
import openerp
|
||||
from openerp.tests import common
|
||||
|
||||
DB = common.DB
|
||||
ADMIN_USER_ID = common.ADMIN_USER_ID
|
||||
|
||||
def registry(model):
|
||||
return openerp.modules.registry.RegistryManager.get(DB)[model]
|
||||
return openerp.modules.registry.RegistryManager.get(common.get_db_name())[model]
|
||||
|
||||
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):
|
||||
|
|
|
@ -3,7 +3,6 @@ from openerp.tools import mute_logger
|
|||
from openerp.tests import common
|
||||
|
||||
UID = common.ADMIN_USER_ID
|
||||
DB = common.DB
|
||||
|
||||
|
||||
class TestORM(common.TransactionCase):
|
||||
|
|
|
@ -6,22 +6,21 @@ import openerp
|
|||
from openerp import SUPERUSER_ID
|
||||
import common
|
||||
|
||||
DB = common.DB
|
||||
ADMIN_USER_ID = common.ADMIN_USER_ID
|
||||
|
||||
def registry(model):
|
||||
return openerp.modules.registry.RegistryManager.get(DB)[model]
|
||||
return openerp.modules.registry.RegistryManager.get(common.get_db_name())[model]
|
||||
|
||||
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):
|
||||
registry = openerp.modules.registry.RegistryManager.get(DB)
|
||||
registry = openerp.modules.registry.RegistryManager.get(common.get_db_name())
|
||||
return registry.get(module_name)
|
||||
|
||||
def reload_registry():
|
||||
openerp.modules.registry.RegistryManager.new(
|
||||
DB, update_module=True)
|
||||
common.get_db_name(), update_module=True)
|
||||
|
||||
def search_registry(model_name, domain):
|
||||
cr = cursor()
|
||||
|
|
|
@ -452,7 +452,7 @@ class TestTemplating(ViewCase):
|
|||
def setUp(self):
|
||||
import openerp.modules
|
||||
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
|
||||
# fuck off
|
||||
self._pool._init = False
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import openerp.tests.common
|
||||
|
||||
DB = openerp.tests.common.DB
|
||||
|
||||
class test_xmlrpc(openerp.tests.common.HttpCase):
|
||||
at_install = False
|
||||
|
@ -9,15 +8,17 @@ class test_xmlrpc(openerp.tests.common.HttpCase):
|
|||
|
||||
def test_01_xmlrpc_login(self):
|
||||
""" 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)
|
||||
|
||||
def test_xmlrpc_ir_model_search(self):
|
||||
""" Try a search on the object service. """
|
||||
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)
|
||||
ids = o.execute(DB, 1, 'admin', 'ir.model', 'search', [], {})
|
||||
ids = o.execute(db_name, 1, 'admin', 'ir.model', 'search', [], {})
|
||||
self.assertIsInstance(ids, list)
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -31,16 +31,21 @@ _logger = logging.getLogger(__name__)
|
|||
ADDONS_PATH = openerp.tools.config['addons_path']
|
||||
HOST = '127.0.0.1'
|
||||
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
|
||||
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):
|
||||
""" 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
|
||||
|
@ -127,7 +132,7 @@ class TransactionCase(BaseCase):
|
|||
"""
|
||||
|
||||
def setUp(self):
|
||||
self.registry = RegistryManager.get(DB)
|
||||
self.registry = RegistryManager.get(get_db_name())
|
||||
#: current transaction's cursor
|
||||
self.cr = self.cursor()
|
||||
self.uid = openerp.SUPERUSER_ID
|
||||
|
@ -149,7 +154,7 @@ class SingleTransactionCase(BaseCase):
|
|||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.registry = RegistryManager.get(DB)
|
||||
cls.registry = RegistryManager.get(get_db_name())
|
||||
cls.cr = cls.registry.cursor()
|
||||
cls.uid = openerp.SUPERUSER_ID
|
||||
cls.env = api.Environment(cls.cr, cls.uid, {})
|
||||
|
@ -200,7 +205,7 @@ class HttpCase(TransactionCase):
|
|||
# setup a magic session_id that will be rollbacked
|
||||
self.session = openerp.http.root.session_store.new()
|
||||
self.session_id = self.session.sid
|
||||
self.session.db = DB
|
||||
self.session.db = get_db_name()
|
||||
openerp.http.root.session_store.save(self.session)
|
||||
# setup an url opener helper
|
||||
self.opener = urllib2.OpenerDirector()
|
||||
|
@ -222,7 +227,7 @@ class HttpCase(TransactionCase):
|
|||
|
||||
def authenticate(self, user, password):
|
||||
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)
|
||||
assert auth.getcode() < 400, "Auth failure %d" % auth.getcode()
|
||||
|
||||
|
@ -322,7 +327,7 @@ class HttpCase(TransactionCase):
|
|||
options = {
|
||||
'timeout' : timeout,
|
||||
'port': PORT,
|
||||
'db': DB,
|
||||
'db': get_db_name(),
|
||||
'session_id': self.session_id,
|
||||
}
|
||||
options.update(kw)
|
||||
|
@ -352,7 +357,7 @@ class HttpCase(TransactionCase):
|
|||
"""
|
||||
options = {
|
||||
'port': PORT,
|
||||
'db': DB,
|
||||
'db': get_db_name(),
|
||||
'url_path': url_path,
|
||||
'code': code,
|
||||
'ready': ready,
|
||||
|
|
Loading…
Reference in New Issue