File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 33# Copyright (c) Jupyter Development Team.
44# Distributed under the terms of the Modified BSD License.
55
6+ import json
67from tornado import web
78import terminado
89from notebook ._tz import utcnow
@@ -19,11 +20,17 @@ def get(self, term_name):
1920
2021
2122class NewTerminalHandler (IPythonHandler ):
22- """Render the terminal interface."""
23+ """Renders a new terminal interface using the named argument ."""
2324 @web .authenticated
2425 def get (self , term_name ):
25- self .terminal_manager .create_with_name (term_name )
2626 new_path = self .request .path .replace ("new/{}" .format (term_name ), term_name )
27+ if term_name in self .terminal_manager .terminals :
28+ self .set_header ('Location' , new_path )
29+ self .set_status (302 )
30+ self .finish (json .dumps (self .terminal_manager .get_terminal_model (term_name )))
31+ return
32+
33+ self .terminal_manager .create_with_name (term_name )
2734 self .redirect (new_path )
2835
2936
Original file line number Diff line number Diff line change @@ -76,8 +76,16 @@ def test_create_terminal_via_get(self):
7676 self .assertIsInstance (foo_term , dict )
7777 self .assertEqual (foo_term ['name' ], 'foo' )
7878
79- with assert_http_error (409 ):
80- self .term_api ._req ('GET' , 'terminals/new/foo' )
79+ # hit the same endpoint a second time and ensure 302 with Location is returned
80+ r = self .term_api ._req ('GET' , 'terminals/new/foo' )
81+ # Access the "interesting" response from the history
82+ self .assertEqual (len (r .history ), 1 )
83+ r = r .history [0 ]
84+ foo_term = r .json ()
85+ self .assertEqual (r .status_code , 302 )
86+ self .assertEqual (r .headers ['Location' ], self .url_prefix + "terminals/foo" )
87+ self .assertIsInstance (foo_term , dict )
88+ self .assertEqual (foo_term ['name' ], 'foo' )
8189
8290 r = self .term_api .shutdown ('foo' )
8391 self .assertEqual (r .status_code , 204 )
You can’t perform that action at this time.
0 commit comments