|
3 | 3 | import json
|
4 | 4 | import time
|
5 | 5 |
|
6 |
| -import requests |
7 |
| -from tornado.websocket import websocket_connect |
| 6 | +from tornado.httpclient import HTTPRequest |
8 | 7 | from tornado.ioloop import IOLoop
|
| 8 | +from tornado.websocket import websocket_connect |
9 | 9 |
|
10 | 10 | from jupyter_client.kernelspec import NATIVE_KERNEL_NAME
|
11 | 11 |
|
|
14 | 14 |
|
15 | 15 | class KernelAPI(object):
|
16 | 16 | """Wrapper for kernel REST API requests"""
|
17 |
| - def __init__(self, request): |
| 17 | + def __init__(self, request, base_url, headers): |
18 | 18 | self.request = request
|
| 19 | + self.base_url = base_url |
| 20 | + self.headers = headers |
19 | 21 |
|
20 | 22 | def _req(self, verb, path, body=None):
|
21 | 23 | response = self.request(verb,
|
@@ -51,16 +53,21 @@ def restart(self, id):
|
51 | 53 |
|
52 | 54 | def websocket(self, id):
|
53 | 55 | loop = IOLoop()
|
54 |
| - f = websocket_connect(url_path_join( |
55 |
| - self.base_url.replace('http', 'ws', 1), 'api/kernels', id, 'channels'), |
56 |
| - io_loop=loop) |
| 56 | + req = HTTPRequest( |
| 57 | + url_path_join(self.base_url.replace('http', 'ws', 1), 'api/kernels', id, 'channels'), |
| 58 | + headers=self.headers, |
| 59 | + ) |
| 60 | + f = websocket_connect(req, io_loop=loop) |
57 | 61 | return loop.run_sync(lambda : f)
|
58 | 62 |
|
59 | 63 |
|
60 | 64 | class KernelAPITest(NotebookTestBase):
|
61 | 65 | """Test the kernels web service API"""
|
62 | 66 | def setUp(self):
|
63 |
| - self.kern_api = KernelAPI(self.request) |
| 67 | + self.kern_api = KernelAPI(self.request, |
| 68 | + base_url=self.base_url(), |
| 69 | + headers=self.auth_headers(), |
| 70 | + ) |
64 | 71 |
|
65 | 72 | def tearDown(self):
|
66 | 73 | for k in self.kern_api.list().json():
|
|
0 commit comments