Show More
@@ -45,7 +45,8 b' class MainKernelHandler(IPythonHandler):' | |||
|
45 | 45 | km = self.kernel_manager |
|
46 | 46 | kernel_id = km.start_kernel() |
|
47 | 47 | model = km.kernel_model(kernel_id, self.ws_url) |
|
48 | self.set_header('Location', '{0}kernels/{1}'.format(self.base_kernel_url, kernel_id)) | |
|
48 | self.set_header('Location', '{0}api/kernels/{1}'.format(self.base_kernel_url, kernel_id)) | |
|
49 | self.set_status(201) | |
|
49 | 50 | self.finish(jsonapi.dumps(model)) |
|
50 | 51 | |
|
51 | 52 | |
@@ -57,6 +58,7 b' class KernelHandler(IPythonHandler):' | |||
|
57 | 58 | @json_errors |
|
58 | 59 | def get(self, kernel_id): |
|
59 | 60 | km = self.kernel_manager |
|
61 | km._check_kernel_id(kernel_id) | |
|
60 | 62 | model = km.kernel_model(kernel_id, self.ws_url) |
|
61 | 63 | self.finish(jsonapi.dumps(model)) |
|
62 | 64 |
@@ -66,16 +66,19 b' class MappingKernelManager(MultiKernelManager):' | |||
|
66 | 66 | 'dead', |
|
67 | 67 | ) |
|
68 | 68 | else: |
|
69 | self._check_kernel_id(kernel_id) | |
|
69 | 70 | self.log.info("Using existing kernel: %s" % kernel_id) |
|
70 | 71 | return kernel_id |
|
71 | 72 | |
|
72 | 73 | def shutdown_kernel(self, kernel_id, now=False): |
|
73 | 74 | """Shutdown a kernel by kernel_id""" |
|
75 | self._check_kernel_id(kernel_id) | |
|
74 | 76 | super(MappingKernelManager, self).shutdown_kernel(kernel_id, now=now) |
|
75 | 77 | |
|
76 | 78 | def kernel_model(self, kernel_id, ws_url): |
|
77 | 79 | """Return a dictionary of kernel information described in the |
|
78 | 80 | JSON standard model.""" |
|
81 | self._check_kernel_id(kernel_id) | |
|
79 | 82 | model = {"id":kernel_id, "ws_url": ws_url} |
|
80 | 83 | return model |
|
81 | 84 |
@@ -31,24 +31,70 b' class KernelAPITest(NotebookTestBase):' | |||
|
31 | 31 | # POST request |
|
32 | 32 | r = requests.post(self.base_url()) |
|
33 | 33 | data = r.json() |
|
34 | status = r.status_code | |
|
35 | header = r.headers | |
|
36 | self.assertIn('location', header) | |
|
37 | self.assertEquals(header['location'], '/api/kernels/' + data['id']) | |
|
38 | self.assertEquals(status, 201) | |
|
34 | 39 | assert isinstance(data, dict) |
|
35 | 40 | |
|
36 | 41 | # GET request |
|
37 | 42 | r = requests.get(self.base_url()) |
|
43 | status = r.status_code | |
|
44 | self.assertEquals(status, 200) | |
|
38 | 45 | assert isinstance(r.json(), list) |
|
39 | 46 | self.assertEqual(r.json()[0]['id'], data['id']) |
|
40 | 47 | |
|
48 | # create another kernel and check that they both are added to the | |
|
49 | # list of kernels from a GET request | |
|
50 | data2 = self.mkkernel() | |
|
51 | assert isinstance(data2, dict) | |
|
52 | r = requests.get(self.base_url()) | |
|
53 | kernels = r.json() | |
|
54 | status = r.status_code | |
|
55 | self.assertEquals(status, 200) | |
|
56 | assert isinstance(kernels, list) | |
|
57 | self.assertEquals(len(kernels), 2) | |
|
58 | ||
|
41 | 59 | def test_kernel_handler(self): |
|
42 | # GET kernel with id | |
|
60 | # GET kernel with given id | |
|
43 | 61 | data = self.mkkernel() |
|
44 | 62 | url = self.base_url() +'/' + data['id'] |
|
45 | 63 | r = requests.get(url) |
|
46 | assert isinstance(r.json(), dict) | |
|
47 | self.assertIn('id', r.json()) | |
|
48 |
self.assertEqual( |
|
|
64 | data1 = r.json() | |
|
65 | status = r.status_code | |
|
66 | self.assertEquals(status, 200) | |
|
67 | assert isinstance(data1, dict) | |
|
68 | self.assertIn('id', data1) | |
|
69 | self.assertIn('ws_url', data1) | |
|
70 | self.assertEqual(data1['id'], data['id']) | |
|
71 | ||
|
72 | # Request a bad kernel id and check that a JSON | |
|
73 | # message is returned! | |
|
74 | bad_id = '111-111-111-111-111' | |
|
75 | bad_url = self.base_url() + '/' + bad_id | |
|
76 | r = requests.get(bad_url) | |
|
77 | status = r.status_code | |
|
78 | message = r.json() | |
|
79 | self.assertEquals(status, 404) | |
|
80 | assert isinstance(message, dict) | |
|
81 | self.assertIn('message', message) | |
|
82 | self.assertEquals(message['message'], 'Kernel does not exist: ' + bad_id) | |
|
49 | 83 | |
|
50 | 84 | # DELETE kernel with id |
|
51 | 85 | r = requests.delete(url) |
|
52 | 86 | self.assertEqual(r.status_code, 204) |
|
53 | 87 | r = requests.get(self.base_url()) |
|
54 | 88 | self.assertEqual(r.json(), []) |
|
89 | ||
|
90 | # Request to delete a non-existent kernel id | |
|
91 | bad_id = '111-111-111-111-111' | |
|
92 | bad_url = self.base_url() + '/' + bad_id | |
|
93 | r = requests.delete(bad_url) | |
|
94 | status = r.status_code | |
|
95 | message = r.json() | |
|
96 | self.assertEquals(status, 404) | |
|
97 | assert isinstance(message, dict) | |
|
98 | self.assertIn('message', message) | |
|
99 | self.assertEquals(message['message'], 'Kernel does not exist: ' + bad_id) | |
|
100 | No newline at end of file |
@@ -47,15 +47,15 b' class SessionRootHandler(IPythonHandler):' | |||
|
47 | 47 | km = self.kernel_manager |
|
48 | 48 | model = self.get_json_body() |
|
49 | 49 | if model is None: |
|
50 | raise HTTPError(400, "No JSON data provided") | |
|
50 | raise web.HTTPError(400, "No JSON data provided") | |
|
51 | 51 | try: |
|
52 | 52 | name = model['notebook']['name'] |
|
53 | 53 | except KeyError: |
|
54 | raise HTTPError(400, "Missing field in JSON data: name") | |
|
54 | raise web.HTTPError(400, "Missing field in JSON data: name") | |
|
55 | 55 | try: |
|
56 | 56 | path = model['notebook']['path'] |
|
57 | 57 | except KeyError: |
|
58 | raise HTTPError(400, "Missing field in JSON data: path") | |
|
58 | raise web.HTTPError(400, "Missing field in JSON data: path") | |
|
59 | 59 | # Check to see if session exists |
|
60 | 60 | if sm.session_exists(name=name, path=path): |
|
61 | 61 | model = sm.get_session(name=name, path=path) |
General Comments 0
You need to be logged in to leave comments.
Login now