diff options
| author | Damián Soriano <ds@adhoc.com.ar> | 2015-06-08 08:44:46 +0100 |
|---|---|---|
| committer | Olivier Dony <odo@openerp.com> | 2015-06-12 12:43:01 +0200 |
| commit | 2df9060d97a201c2f54c6d79af13ffca45f91cef (patch) | |
| tree | 634e4238bcb8e058190798974f152bc1462e5dcb /openerp/tests | |
| parent | de20e18faa50a5cc40ab0b8d610cd69fd70c78cc (diff) | |
[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
Diffstat (limited to 'openerp/tests')
| -rw-r--r-- | openerp/tests/common.py | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/openerp/tests/common.py b/openerp/tests/common.py index c23c9974a83..912ebea5799 100644 --- a/openerp/tests/common.py +++ b/openerp/tests/common.py @@ -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, |
