From b61997e71671c7640ca3fe271804de46550c8502 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Thu, 14 Nov 2013 10:46:24 +0100 Subject: [FIX] web: correct url matching in tests bzr revid: chs@openerp.com-20131114094624-588lvc9vunwa99d8 --- addons/web/static/src/js/testing.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'addons/web/static/src/js/testing.js') diff --git a/addons/web/static/src/js/testing.js b/addons/web/static/src/js/testing.js index a7768f0ca24..f607b278437 100644 --- a/addons/web/static/src/js/testing.js +++ b/addons/web/static/src/js/testing.js @@ -58,8 +58,7 @@ openerp.testing = {}; } var fn, params; var needle = rparams.model + ':' + rparams.method; - if (url.url === '/web/dataset/call_kw' - && needle in this.responses) { + if (url.url.substr(0, 20) === '/web/dataset/call_kw' && needle in this.responses) { fn = this.responses[needle]; params = [ rparams.args || [], -- cgit v1.2.3 From ae3223907b5d33f95c2215824cce1d5a179f6f29 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 31 Jan 2014 16:26:40 +0100 Subject: [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 --- addons/web/static/src/js/testing.js | 38 +++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'addons/web/static/src/js/testing.js') diff --git a/addons/web/static/src/js/testing.js b/addons/web/static/src/js/testing.js index f607b278437..c4f5aeebd60 100644 --- a/addons/web/static/src/js/testing.js +++ b/addons/web/static/src/js/testing.js @@ -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)) { -- cgit v1.2.3 From b79f35471ecd27f1372849a9fd63cac7f740d2fd Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Fri, 21 Feb 2014 10:55:00 +0100 Subject: [FIX] testing: rpc tests works directly on the source database instead of copying it bzr revid: chs@openerp.com-20140221095500-5cer5exzdei76y1d --- addons/web/static/src/js/testing.js | 33 +++++---------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) (limited to 'addons/web/static/src/js/testing.js') diff --git a/addons/web/static/src/js/testing.js b/addons/web/static/src/js/testing.js index c4f5aeebd60..41dd2f03ad9 100644 --- a/addons/web/static/src/js/testing.js +++ b/addons/web/static/src/js/testing.js @@ -305,39 +305,16 @@ openerp.testing = {}; case 'rpc': async = true; (function () { - // Bunch of random base36 characters - var dbname = 'test_' + Math.random().toString(36).slice(2); - // Add db setup/teardown at the start of the stack + // Add a session setup at the start of the stack to ensure user is logged in case_stack = case_stack.unshift(function (instance) { // FIXME hack: don't want the session to go through shitty loading process of everything instance.session.session_init = testing.noop; instance.session.load_modules = testing.noop; instance.session.session_bind(); - return instance.session.rpc('/web/database/duplicate', { - fields: [ - {name: 'super_admin_pwd', value: db.supadmin}, - {name: 'db_original_name', value: db.source}, - {name: 'db_name', value: dbname} - ] - }).then(function (result) { - if (result.error) { - return $.Deferred().reject(result.error).promise(); - } - return instance.session.session_authenticate( - dbname, 'admin', db.password, true); - }); - }, function (instance) { - return instance.session.rpc('/web/database/drop', { - fields: [ - {name: 'drop_pwd', value: db.supadmin}, - {name: 'drop_db', value: dbname} - ] - }).then(function (result) { - if (result.error) { - return $.Deferred().reject(result.error).promise(); - } - return result; - }); + if (instance.session.session_is_valid()) { + return $.when(); + } + return instance.session.session_authenticate(db.source, 'admin', db.password, true); }); })(); } -- cgit v1.2.3 From bb7eb5269917cfde51abb50a4dca175ddd371fb9 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 21 Feb 2014 15:35:18 +0100 Subject: [REM] RPC from js/qunit tests They're a pain in the ass, they never worked right and they're basically useless. Screw it. bzr revid: xmo@openerp.com-20140221143518-hv3rjkw2b00ughvh --- addons/web/static/src/js/testing.js | 50 ------------------------------------- 1 file changed, 50 deletions(-) (limited to 'addons/web/static/src/js/testing.js') diff --git a/addons/web/static/src/js/testing.js b/addons/web/static/src/js/testing.js index 41dd2f03ad9..1f1c718ad5f 100644 --- a/addons/web/static/src/js/testing.js +++ b/addons/web/static/src/js/testing.js @@ -196,7 +196,6 @@ openerp.testing = {}; }); }; - var db = window['oe_db_info']; testing.section = function (name, options, body) { if (_.isFunction(options)) { body = options; @@ -235,40 +234,6 @@ openerp.testing = {}; .push(env._oe.setup, env._oe.teardown) .push(options.setup, options.teardown); var opts = _.defaults({}, options, env._oe); - // FIXME: if this test is ignored, will still query - if (opts.rpc === 'rpc' && !db) { - QUnit.config.autostart = false; - db = { - source: null, - supadmin: null, - password: null - }; - var $msg = $('
') - .append('

A test needs to clone a database

') - .append('

Please provide the source clone information

') - .append(' Source DB: ').append('').append('
') - .append(' DB Password: ').append('').append('
') - .append('Admin Password: ').append('').append('
') - .append('') - .submit(function (e) { - e.preventDefault(); - e.stopPropagation(); - db.source = $msg.find('input[name=source]').val(); - db.supadmin = $msg.find('input[name=supadmin]').val(); - db.password = $msg.find('input[name=password]').val(); - QUnit.start(); - $.unblockUI(); - }); - $.blockUI({ - message: $msg, - css: { - fontFamily: 'monospace', - textAlign: 'left', - whiteSpace: 'pre-wrap', - cursor: 'default' - } - }); - } QUnit.test(name, function () { var instance = openerp; @@ -302,21 +267,6 @@ openerp.testing = {}; instance.session.responses[spec] = handler; }; break; - case 'rpc': - async = true; - (function () { - // Add a session setup at the start of the stack to ensure user is logged in - case_stack = case_stack.unshift(function (instance) { - // FIXME hack: don't want the session to go through shitty loading process of everything - instance.session.session_init = testing.noop; - instance.session.load_modules = testing.noop; - instance.session.session_bind(); - if (instance.session.session_is_valid()) { - return $.when(); - } - return instance.session.session_authenticate(db.source, 'admin', db.password, true); - }); - })(); } // Always execute tests asynchronously -- cgit v1.2.3