mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-24 12:05:22 +08:00
Update session tests
This commit is contained in:
parent
99f686918b
commit
befe8eb720
IPython/html
@ -48,6 +48,10 @@ define([
|
||||
* POST /api/sessions
|
||||
*/
|
||||
Session.prototype.start = function (success, error) {
|
||||
if (this.kernel !== null) {
|
||||
throw new Error("session has already been started");
|
||||
};
|
||||
|
||||
var that = this;
|
||||
var on_success = function (data, status, xhr) {
|
||||
var kernel_service_url = utils.url_path_join(that.base_url, "api/kernels");
|
||||
@ -95,23 +99,31 @@ define([
|
||||
* PATCH /api/sessions/[:session_id]
|
||||
*/
|
||||
Session.prototype.change = function (notebook_name, notebook_path, kernel_name, success, error) {
|
||||
this.notebook_model.name = notebook_name;
|
||||
this.notebook_model.path = notebook_path;
|
||||
this.kernel_model.name = kernel_name;
|
||||
if (notebook_name !== undefined) {
|
||||
this.notebook_model.name = notebook_name;
|
||||
}
|
||||
if (notebook_path !== undefined) {
|
||||
this.notebook_model.path = notebook_path;
|
||||
}
|
||||
if (kernel_name !== undefined) {
|
||||
this.kernel_model.name = kernel_name;
|
||||
}
|
||||
|
||||
console.log(JSON.stringify(this._get_model()));
|
||||
|
||||
$.ajax(this.session_url, {
|
||||
processData: false,
|
||||
cache: false,
|
||||
type: "PATCH",
|
||||
data: JSON.stringify(this._get_model()),
|
||||
dataType : "json",
|
||||
dataType: "json",
|
||||
success: this._on_success(success),
|
||||
error: this._on_error(error)
|
||||
});
|
||||
};
|
||||
|
||||
Session.prototype.rename_notebook = function (name, path, success, error) {
|
||||
this.change(name, path, this.kernel_model.name, success, error);
|
||||
this.change(name, path, undefined, success, error);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -4,21 +4,107 @@
|
||||
//
|
||||
|
||||
casper.notebook_test(function () {
|
||||
var that = this;
|
||||
var get_info = function () {
|
||||
return that.evaluate(function () {
|
||||
return JSON.parse(JSON.stringify(IPython.notebook.session._get_model()));
|
||||
});
|
||||
};
|
||||
|
||||
// test that the kernel is running
|
||||
this.then(function () {
|
||||
this.test.assert(this.kernel_running(), 'session: kernel is running');
|
||||
});
|
||||
|
||||
// test list
|
||||
this.thenEvaluate(function () {
|
||||
IPython._sessions = null;
|
||||
IPython.notebook.session.list(function (data) {
|
||||
IPython._sessions = data;
|
||||
});
|
||||
});
|
||||
this.waitFor(function () {
|
||||
return this.evaluate(function () {
|
||||
return IPython._sessions !== null;
|
||||
});
|
||||
});
|
||||
this.then(function () {
|
||||
var num_sessions = this.evaluate(function () {
|
||||
return IPython._sessions.length;
|
||||
});
|
||||
this.test.assertEquals(num_sessions, 1, 'one session running');
|
||||
});
|
||||
|
||||
// test get_info
|
||||
var session_info = get_info();
|
||||
this.thenEvaluate(function () {
|
||||
IPython._session_info = null;
|
||||
IPython.notebook.session.get_info(function (data) {
|
||||
IPython._session_info = data;
|
||||
});
|
||||
});
|
||||
this.waitFor(function () {
|
||||
return this.evaluate(function () {
|
||||
return IPython._session_info !== null;
|
||||
});
|
||||
});
|
||||
this.then(function () {
|
||||
var new_session_info = this.evaluate(function () {
|
||||
return IPython._session_info;
|
||||
});
|
||||
this.test.assertEquals(session_info.notebook.name, new_session_info.notebook.name, 'session: notebook name correct');
|
||||
this.test.assertEquals(session_info.notebook.path, new_session_info.notebook.path, 'session: notebook path correct');
|
||||
this.test.assertEquals(session_info.kernel.name, new_session_info.kernel.name, 'session: kernel name correct');
|
||||
this.test.assertEquals(session_info.kernel.id, new_session_info.kernel.id, 'session: kernel id correct');
|
||||
});
|
||||
|
||||
// test rename_notebook
|
||||
//
|
||||
// TODO: the PATCH request isn't supported by phantom, so this test always
|
||||
// fails, see https://github.com/ariya/phantomjs/issues/11384
|
||||
// when this is fixed we can properly run this test
|
||||
//
|
||||
// this.thenEvaluate(function () {
|
||||
// IPython._renamed = false;
|
||||
// IPython.notebook.session.rename_notebook(
|
||||
// "foo",
|
||||
// "bar",
|
||||
// function (data) {
|
||||
// IPython._renamed = true;
|
||||
// }
|
||||
// );
|
||||
// });
|
||||
// this.waitFor(function () {
|
||||
// return this.evaluate(function () {
|
||||
// return IPython._renamed;
|
||||
// });
|
||||
// });
|
||||
// this.then(function () {
|
||||
// var info = get_info();
|
||||
// this.test.assertEquals(info.notebook.name, "foo", "notebook was renamed");
|
||||
// this.test.assertEquals(info.notebook.path, "bar", "notebook path was changed");
|
||||
// });
|
||||
|
||||
// test delete
|
||||
this.thenEvaluate(function () {
|
||||
IPython.notebook.session.delete();
|
||||
});
|
||||
|
||||
this.waitFor(function () {
|
||||
return this.evaluate(function () {
|
||||
return IPython.notebook.kernel.is_fully_disconnected();
|
||||
});
|
||||
});
|
||||
|
||||
this.then(function () {
|
||||
this.test.assert(!this.kernel_running(), 'session deletes kernel');
|
||||
});
|
||||
|
||||
// test start after delete -- should throw an error
|
||||
this.then(function () {
|
||||
var start = function () {
|
||||
this.evaluate(function () {
|
||||
IPython.notebook.session.start();
|
||||
});
|
||||
};
|
||||
this.test.assertRaises(start, [], 'error raised on start after delete');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user