summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2014-02-03 13:05:53 +0100
committerXavier Morel <xmo@openerp.com>2014-02-03 13:05:53 +0100
commit5de043e044ae34d84832fceeb3ca3090f75f730b (patch)
treeb9eed13a8001640ca58063a22fecf5e92cfa04a3 /addons
parent0aa0bbd539be03b90670906d8e21f2cc45f8e72f (diff)
parente9a3d8bcec151937fd983b0d658a1ed9144d7ff4 (diff)
[FIX] various issues with JS tests
bzr revid: xmo@openerp.com-20140203120553-foe2jutor33j1b8q
Diffstat (limited to 'addons')
-rw-r--r--addons/web/static/src/js/testing.js38
-rw-r--r--addons/web/static/test/jsonrpc.js2
-rw-r--r--addons/web/tests/qunitsuite/suite.py2
-rw-r--r--addons/web/tests/test_js.py6
-rw-r--r--addons/web_tests_demo/static/test/demo.js34
5 files changed, 50 insertions, 32 deletions
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)) {
diff --git a/addons/web/static/test/jsonrpc.js b/addons/web/static/test/jsonrpc.js
index ef0c1fbc44c..96b10f0fee1 100644
--- a/addons/web/static/test/jsonrpc.js
+++ b/addons/web/static/test/jsonrpc.js
@@ -156,7 +156,6 @@ ropenerp.testing.section('jsonrpc-auth', {
rpc: "rpc",
},
function (test) {
- return;
test('basic-auth', {asserts: 3}, function () {
var db = ropenerp.session.db;
var session = new openerp.Session(null, null, {override_session: true});
@@ -182,7 +181,6 @@ function (test) {
session2 = new openerp.Session(null, null, {session_id: session.session_id});
equal(session2.uid, undefined, "uid should be undefined");
equal(session2.override_session, true, "overwrite_session should be true");
- console.log("session_id", session.session_id);
return session2.session_reload();
}).then(function() {
equal(session2.uid, session.uid);
diff --git a/addons/web/tests/qunitsuite/suite.py b/addons/web/tests/qunitsuite/suite.py
index 3aed7b133f1..84092c687b4 100644
--- a/addons/web/tests/qunitsuite/suite.py
+++ b/addons/web/tests/qunitsuite/suite.py
@@ -110,6 +110,8 @@ class QUnitSuite(unittest.TestSuite):
self._test.failed = True
result.addFailure(
self._test, self.failure_to_str(*args[2:]))
+ elif event_name == 'console':
+ print args[1]
return False
diff --git a/addons/web/tests/test_js.py b/addons/web/tests/test_js.py
index b37c082739f..a126ce4b2f3 100644
--- a/addons/web/tests/test_js.py
+++ b/addons/web/tests/test_js.py
@@ -10,12 +10,6 @@ class WebSuite(QUnitSuite):
'/web/tests',
'mod=*&source={db}&supadmin={supadmin}&password={password}'.format(
db=tools.config['db_name'],
- # al: i dont understand why both are needed, db_password is the
- # password for postgres and should not appear here of that i'm
- # sure
- #
- # But runbot provides it with this wrong key so i let it here
- # until it's fixed
supadmin=tools.config['db_password'] or 'admin',
password=tools.config['admin_passwd'] or 'admin'),
''
diff --git a/addons/web_tests_demo/static/test/demo.js b/addons/web_tests_demo/static/test/demo.js
index 0ca10ba642c..2ead2902828 100644
--- a/addons/web_tests_demo/static/test/demo.js
+++ b/addons/web_tests_demo/static/test/demo.js
@@ -1,7 +1,5 @@
-// niv: I desactivate these until the testing framework has been adapted to better use
-// the new way to declare JavaScript modules
-/*openerp.testing.section('basic section', function (test) {
+openerp.testing.section('basic section', function (test) {
test('my first test', function () {
ok(true, "this test has run");
});
@@ -88,18 +86,18 @@
});
});
-// test('actual RPC', {rpc: 'rpc', asserts: 4}, function (instance) {
-// var Model = new instance.web.Model('web_tests_demo.model');
-// return Model.call('create', [{name: "Bob"}])
-// .then(function (id) {
-// return Model.call('read', [[id]]);
-// }).then(function (records) {
-// strictEqual(records.length, 1);
-// var record = records[0];
-// strictEqual(record.name, "Bob");
-// strictEqual(record.thing, false);
-// // default value
-// strictEqual(record.other, 'bob');
-// });
-// });
-});*/
+ test('actual RPC', {rpc: 'rpc', asserts: 4}, function (instance) {
+ var Model = new instance.web.Model('web_tests_demo.model');
+ return Model.call('create', [{name: "Bob"}])
+ .then(function (id) {
+ return Model.call('read', [[id]]);
+ }).then(function (records) {
+ strictEqual(records.length, 1);
+ var record = records[0];
+ strictEqual(record.name, "Bob");
+ strictEqual(record.thing, false);
+ // default value
+ strictEqual(record.other, 'bob');
+ });
+ });
+});