Allow the deprecated session API to work

Steven Silvester 10 years ago
parent 6486b2430f
commit 8c6257bea5

@ -40,6 +40,12 @@ class SessionRootHandler(APIHandler):
if model is None:
raise web.HTTPError(400, "No JSON data provided")
if model.get('notebook') is not None:
if model['notebook'].get('path') is not None:
self.log.warn('Sessions API changed, see updated swagger docs')
model['path'] = model['notebook']['path']
model['type'] = 'notebook'
try:
path = model['path']
except KeyError:
@ -112,6 +118,11 @@ class SessionHandler(APIHandler):
before = yield gen.maybe_future(sm.get_session(session_id=session_id))
changes = {}
if 'notebook' in model:
if 'path' in model['notebook']:
self.log.warn('Sessions API changed, see updated swagger docs')
model['path'] = model['notebook']['path']
model['type'] = 'notebook'
if 'path' in model:
changes['path'] = model['path']
if 'type' in model:

@ -209,6 +209,7 @@ class SessionManager(LoggingConfigurable):
'id': row['session_id'],
'path': row['path'],
'type': row['type'],
'notebook': {'path': row['path']}, # provide deprecated API
'kernel': self.kernel_manager.kernel_model(row['kernel_id'])
}
return model

@ -46,10 +46,20 @@ class SessionAPI(object):
'id': kernel_id}})
return self._req('POST', '', body)
def create_deprecated(self, path):
body = json.dumps({'notebook': {'path': path},
'kernel': {'name': 'python',
'id': 'foo'}})
return self._req('POST', '', body)
def modify_path(self, id, path):
body = json.dumps({'path': path})
return self._req('PATCH', id, body)
def modify_path_deprecated(self, id, path):
body = json.dumps({'notebook': {'path': path}})
return self._req('PATCH', id, body)
def modify_type(self, id, type):
body = json.dumps({'type': type})
return self._req('PATCH', id, body)
@ -132,6 +142,14 @@ class SessionAPITest(NotebookTestBase):
self.assertEqual(newsession['path'], 'foo/abc123')
self.assertEqual(newsession['type'], 'console')
def test_create_deprecated(self):
resp = self.sess_api.create_deprecated('foo/nb1.ipynb')
self.assertEqual(resp.status_code, 201)
newsession = resp.json()
self.assertEqual(newsession['path'], 'foo/nb1.ipynb')
self.assertEqual(newsession['type'], 'notebook')
self.assertEqual(newsession['notebook']['path'], 'foo/nb1.ipynb')
def test_create_with_kernel_id(self):
# create a new kernel
r = requests.post(url_path_join(self.base_url(), 'api/kernels'))
@ -175,6 +193,14 @@ class SessionAPITest(NotebookTestBase):
self.assertEqual(changed['id'], sid)
self.assertEqual(changed['path'], 'nb2.ipynb')
def test_modify_path_deprecated(self):
newsession = self.sess_api.create('foo/nb1.ipynb').json()
sid = newsession['id']
changed = self.sess_api.modify_path_deprecated(sid, 'nb2.ipynb').json()
self.assertEqual(changed['id'], sid)
self.assertEqual(changed['notebook']['path'], 'nb2.ipynb')
def test_modify_type(self):
newsession = self.sess_api.create('foo/nb1.ipynb').json()
sid = newsession['id']

Loading…
Cancel
Save