mirror of
https://github.com/jupyter/notebook.git
synced 2025-02-17 12:39:54 +08:00
Allow for redundant accesses of same endpoint
This commit is contained in:
parent
ac50d2e530
commit
7778dc3202
@ -3,6 +3,7 @@
|
||||
# Copyright (c) Jupyter Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
|
||||
import json
|
||||
from tornado import web
|
||||
import terminado
|
||||
from notebook._tz import utcnow
|
||||
@ -19,11 +20,17 @@ class TerminalHandler(IPythonHandler):
|
||||
|
||||
|
||||
class NewTerminalHandler(IPythonHandler):
|
||||
"""Render the terminal interface."""
|
||||
"""Renders a new terminal interface using the named argument."""
|
||||
@web.authenticated
|
||||
def get(self, term_name):
|
||||
self.terminal_manager.create_with_name(term_name)
|
||||
new_path = self.request.path.replace("new/{}".format(term_name), term_name)
|
||||
if term_name in self.terminal_manager.terminals:
|
||||
self.set_header('Location', new_path)
|
||||
self.set_status(302)
|
||||
self.finish(json.dumps(self.terminal_manager.get_terminal_model(term_name)))
|
||||
return
|
||||
|
||||
self.terminal_manager.create_with_name(term_name)
|
||||
self.redirect(new_path)
|
||||
|
||||
|
||||
|
@ -76,8 +76,16 @@ class TerminalAPITest(NotebookTestBase):
|
||||
self.assertIsInstance(foo_term, dict)
|
||||
self.assertEqual(foo_term['name'], 'foo')
|
||||
|
||||
with assert_http_error(409):
|
||||
self.term_api._req('GET', 'terminals/new/foo')
|
||||
# hit the same endpoint a second time and ensure 302 with Location is returned
|
||||
r = self.term_api._req('GET', 'terminals/new/foo')
|
||||
# Access the "interesting" response from the history
|
||||
self.assertEqual(len(r.history), 1)
|
||||
r = r.history[0]
|
||||
foo_term = r.json()
|
||||
self.assertEqual(r.status_code, 302)
|
||||
self.assertEqual(r.headers['Location'], self.url_prefix + "terminals/foo")
|
||||
self.assertIsInstance(foo_term, dict)
|
||||
self.assertEqual(foo_term['name'], 'foo')
|
||||
|
||||
r = self.term_api.shutdown('foo')
|
||||
self.assertEqual(r.status_code, 204)
|
||||
|
Loading…
Reference in New Issue
Block a user