[FIX] modules initialization when testing

broken "adaptation" to single-instance openerp would only initialize the first
set of dependencies, any further module would see its test runs without itself
or its dependencies being guaranteed to be initialized/installed into the
current openerp instance.

bzr revid: xmo@openerp.com-20140131152640-coxqulkdb0xupbvq
This commit is contained in:
Xavier Morel
2014-01-31 16:26:40 +01:00
parent b78703c122
commit ae3223907b
+32 -6
View File
@@ -15,6 +15,37 @@ openerp.testing = {};
list_editable: ['list', 'form', 'data'],
};
var initialized = [];
/**
* openerp.init is a broken-ass piece of shit, makes it impossible to
* progressively add modules, using it, retarded openerp_inited flag
* means the first tests being run get their dependencies loaded
* (basically just base and web), and for *every other module* the tests
* run without the dependencies being correctly loaded
*/
function init(modules) {
if (!initialized.length) {
openerp.init(modules);
initialized = openerp._modules.slice();
return;
}
var to_initialize = _.difference(modules, initialized);
for (var i = 0; i < to_initialize.length; i++) {
var modname = to_initialize[i];
var fct = openerp[modname];
if (typeof fct === 'function') {
var module = openerp[modname] = {};
for(var k in fct) {
if (!fct.hasOwnProperty(k)) { continue; }
module[k] = fct[k];
}
fct(openerp, module)
}
initialized.push(modname);
openerp._modules.push(modname);
}
}
testing.dependencies = window['oe_all_dependencies'] || [];
testing.current_module = null;
testing.templates = { };
@@ -165,8 +196,6 @@ openerp.testing = {};
});
};
var openerp_inited = false;
var db = window['oe_db_info'];
testing.section = function (name, options, body) {
if (_.isFunction(options)) {
@@ -243,10 +272,7 @@ openerp.testing = {};
QUnit.test(name, function () {
var instance = openerp;
if (!openerp_inited) {
openerp.init(module_deps);
openerp_inited = true;
}
init(module_deps);
instance.session = new instance.web.Session();
instance.session.uid = 42;
if (_.isNumber(opts.asserts)) {