2013-08-06 12:50:22 +00:00
|
|
|
(function() {
|
|
|
|
|
2012-02-23 12:34:16 +00:00
|
|
|
openerp.test_support = {
|
2013-08-06 12:50:22 +00:00
|
|
|
|
2012-08-14 15:29:00 +00:00
|
|
|
setup_session: function (session) {
|
2012-02-23 12:34:16 +00:00
|
|
|
var origin = location.protocol+"//"+location.host;
|
2012-08-14 15:29:00 +00:00
|
|
|
_.extend(session, {
|
2012-02-23 12:34:16 +00:00
|
|
|
origin: origin,
|
|
|
|
prefix: origin,
|
|
|
|
server: origin, // keep chs happy
|
|
|
|
//openerp.web.qweb.default_dict['_s'] = this.origin;
|
2012-08-14 15:29:00 +00:00
|
|
|
rpc_function: session.rpc_json,
|
2012-02-23 12:34:16 +00:00
|
|
|
session_id: false,
|
|
|
|
uid: false,
|
|
|
|
username: false,
|
|
|
|
user_context: {},
|
|
|
|
db: false,
|
|
|
|
// this.module_list = openerp._modules.slice();
|
|
|
|
// this.module_loaded = {};
|
|
|
|
// _(this.module_list).each(function (mod) {
|
|
|
|
// self.module_loaded[mod] = true;
|
|
|
|
// });
|
|
|
|
context: {},
|
|
|
|
shortcuts: [],
|
|
|
|
active_id: null
|
|
|
|
});
|
2012-08-14 15:29:00 +00:00
|
|
|
return session.session_reload();
|
2012-02-23 12:34:16 +00:00
|
|
|
},
|
2012-02-27 08:51:28 +00:00
|
|
|
module: function (title, tested_core, nonliterals) {
|
2012-02-23 12:34:16 +00:00
|
|
|
var conf = QUnit.config.openerp = {};
|
|
|
|
QUnit.module(title, {
|
|
|
|
setup: function () {
|
|
|
|
QUnit.stop();
|
|
|
|
var oe = conf.openerp = window.openerp.init();
|
|
|
|
window.openerp.web[tested_core](oe);
|
2012-08-14 15:29:00 +00:00
|
|
|
var done = openerp.test_support.setup_session(oe.session);
|
2012-02-27 08:51:28 +00:00
|
|
|
if (nonliterals) {
|
2012-10-30 14:06:30 +00:00
|
|
|
done = done.then(function () {
|
2012-08-14 15:29:00 +00:00
|
|
|
return oe.session.rpc('/tests/add_nonliterals', {
|
2012-02-27 08:51:28 +00:00
|
|
|
domains: nonliterals.domains || [],
|
|
|
|
contexts: nonliterals.contexts || []
|
2012-10-30 14:06:30 +00:00
|
|
|
}).done(function (r) {
|
2012-02-27 08:51:28 +00:00
|
|
|
oe.domains = r.domains;
|
|
|
|
oe.contexts = r.contexts;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
done.always(QUnit.start)
|
2012-10-30 14:06:30 +00:00
|
|
|
.done(function () {
|
2012-02-23 12:34:16 +00:00
|
|
|
conf.openerp = oe;
|
2012-10-30 14:06:30 +00:00
|
|
|
}).fail(function (e) {
|
2012-02-23 12:34:16 +00:00
|
|
|
QUnit.test(title, function () {
|
|
|
|
console.error(e);
|
|
|
|
QUnit.ok(false, 'Could not obtain a session:' + e.debug);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
test: function (title, fn) {
|
|
|
|
var conf = QUnit.config.openerp;
|
|
|
|
QUnit.test(title, function () {
|
|
|
|
QUnit.stop();
|
|
|
|
fn(conf.openerp);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
expect: function (promise, fn) {
|
|
|
|
promise.always(QUnit.start)
|
|
|
|
.done(function () { QUnit.ok(false, 'RPC requests should not succeed'); })
|
|
|
|
.fail(function (e) {
|
|
|
|
if (e.code !== 200) {
|
|
|
|
QUnit.equal(e.code, 200, 'Testing connector should raise RPC faults');
|
2012-02-27 08:51:28 +00:00
|
|
|
if (typeof console !== 'undefined' && console.error) {
|
|
|
|
console.error(e.data.debug);
|
|
|
|
}
|
|
|
|
return;
|
2012-02-23 12:34:16 +00:00
|
|
|
}
|
2013-01-30 15:25:52 +00:00
|
|
|
fn(e.data.name);
|
2013-07-25 10:33:01 +00:00
|
|
|
});
|
2012-02-23 12:34:16 +00:00
|
|
|
}
|
|
|
|
};
|
2013-08-06 12:50:22 +00:00
|
|
|
|
|
|
|
})();
|