Show More
@@ -48,6 +48,10 define([ | |||
|
48 | 48 | * POST /api/sessions |
|
49 | 49 | */ |
|
50 | 50 | Session.prototype.start = function (success, error) { |
|
51 | if (this.kernel !== null) { | |
|
52 | throw new Error("session has already been started"); | |
|
53 | }; | |
|
54 | ||
|
51 | 55 | var that = this; |
|
52 | 56 | var on_success = function (data, status, xhr) { |
|
53 | 57 | var kernel_service_url = utils.url_path_join(that.base_url, "api/kernels"); |
@@ -95,9 +99,17 define([ | |||
|
95 | 99 | * PATCH /api/sessions/[:session_id] |
|
96 | 100 | */ |
|
97 | 101 | Session.prototype.change = function (notebook_name, notebook_path, kernel_name, success, error) { |
|
102 | if (notebook_name !== undefined) { | |
|
98 | 103 | this.notebook_model.name = notebook_name; |
|
104 | } | |
|
105 | if (notebook_path !== undefined) { | |
|
99 | 106 | this.notebook_model.path = notebook_path; |
|
107 | } | |
|
108 | if (kernel_name !== undefined) { | |
|
100 | 109 | this.kernel_model.name = kernel_name; |
|
110 | } | |
|
111 | ||
|
112 | console.log(JSON.stringify(this._get_model())); | |
|
101 | 113 | |
|
102 | 114 | $.ajax(this.session_url, { |
|
103 | 115 | processData: false, |
@@ -111,7 +123,7 define([ | |||
|
111 | 123 | }; |
|
112 | 124 | |
|
113 | 125 | Session.prototype.rename_notebook = function (name, path, success, error) { |
|
114 |
this.change(name, path, |
|
|
126 | this.change(name, path, undefined, success, error); | |
|
115 | 127 | }; |
|
116 | 128 | |
|
117 | 129 | /** |
@@ -4,21 +4,107 | |||
|
4 | 4 | // |
|
5 | 5 | |
|
6 | 6 | casper.notebook_test(function () { |
|
7 | var that = this; | |
|
8 | var get_info = function () { | |
|
9 | return that.evaluate(function () { | |
|
10 | return JSON.parse(JSON.stringify(IPython.notebook.session._get_model())); | |
|
11 | }); | |
|
12 | }; | |
|
13 | ||
|
14 | // test that the kernel is running | |
|
7 | 15 | this.then(function () { |
|
8 | 16 | this.test.assert(this.kernel_running(), 'session: kernel is running'); |
|
9 | 17 | }); |
|
10 | 18 | |
|
19 | // test list | |
|
11 | 20 | this.thenEvaluate(function () { |
|
12 |
IPython. |
|
|
21 | IPython._sessions = null; | |
|
22 | IPython.notebook.session.list(function (data) { | |
|
23 | IPython._sessions = data; | |
|
24 | }); | |
|
25 | }); | |
|
26 | this.waitFor(function () { | |
|
27 | return this.evaluate(function () { | |
|
28 | return IPython._sessions !== null; | |
|
29 | }); | |
|
30 | }); | |
|
31 | this.then(function () { | |
|
32 | var num_sessions = this.evaluate(function () { | |
|
33 | return IPython._sessions.length; | |
|
34 | }); | |
|
35 | this.test.assertEquals(num_sessions, 1, 'one session running'); | |
|
13 | 36 | }); |
|
14 | 37 | |
|
38 | // test get_info | |
|
39 | var session_info = get_info(); | |
|
40 | this.thenEvaluate(function () { | |
|
41 | IPython._session_info = null; | |
|
42 | IPython.notebook.session.get_info(function (data) { | |
|
43 | IPython._session_info = data; | |
|
44 | }); | |
|
45 | }); | |
|
15 | 46 | this.waitFor(function () { |
|
16 | 47 | return this.evaluate(function () { |
|
17 | return IPython.notebook.kernel.is_fully_disconnected(); | |
|
48 | return IPython._session_info !== null; | |
|
18 | 49 | }); |
|
19 | 50 | }); |
|
51 | this.then(function () { | |
|
52 | var new_session_info = this.evaluate(function () { | |
|
53 | return IPython._session_info; | |
|
54 | }); | |
|
55 | this.test.assertEquals(session_info.notebook.name, new_session_info.notebook.name, 'session: notebook name correct'); | |
|
56 | this.test.assertEquals(session_info.notebook.path, new_session_info.notebook.path, 'session: notebook path correct'); | |
|
57 | this.test.assertEquals(session_info.kernel.name, new_session_info.kernel.name, 'session: kernel name correct'); | |
|
58 | this.test.assertEquals(session_info.kernel.id, new_session_info.kernel.id, 'session: kernel id correct'); | |
|
59 | }); | |
|
60 | ||
|
61 | // test rename_notebook | |
|
62 | // | |
|
63 | // TODO: the PATCH request isn't supported by phantom, so this test always | |
|
64 | // fails, see https://github.com/ariya/phantomjs/issues/11384 | |
|
65 | // when this is fixed we can properly run this test | |
|
66 | // | |
|
67 | // this.thenEvaluate(function () { | |
|
68 | // IPython._renamed = false; | |
|
69 | // IPython.notebook.session.rename_notebook( | |
|
70 | // "foo", | |
|
71 | // "bar", | |
|
72 | // function (data) { | |
|
73 | // IPython._renamed = true; | |
|
74 | // } | |
|
75 | // ); | |
|
76 | // }); | |
|
77 | // this.waitFor(function () { | |
|
78 | // return this.evaluate(function () { | |
|
79 | // return IPython._renamed; | |
|
80 | // }); | |
|
81 | // }); | |
|
82 | // this.then(function () { | |
|
83 | // var info = get_info(); | |
|
84 | // this.test.assertEquals(info.notebook.name, "foo", "notebook was renamed"); | |
|
85 | // this.test.assertEquals(info.notebook.path, "bar", "notebook path was changed"); | |
|
86 | // }); | |
|
20 | 87 | |
|
88 | // test delete | |
|
89 | this.thenEvaluate(function () { | |
|
90 | IPython.notebook.session.delete(); | |
|
91 | }); | |
|
92 | this.waitFor(function () { | |
|
93 | return this.evaluate(function () { | |
|
94 | return IPython.notebook.kernel.is_fully_disconnected(); | |
|
95 | }); | |
|
96 | }); | |
|
21 | 97 | this.then(function () { |
|
22 | 98 | this.test.assert(!this.kernel_running(), 'session deletes kernel'); |
|
23 | 99 | }); |
|
100 | ||
|
101 | // test start after delete -- should throw an error | |
|
102 | this.then(function () { | |
|
103 | var start = function () { | |
|
104 | this.evaluate(function () { | |
|
105 | IPython.notebook.session.start(); | |
|
106 | }); | |
|
107 | }; | |
|
108 | this.test.assertRaises(start, [], 'error raised on start after delete'); | |
|
109 | }); | |
|
24 | 110 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now