@@ -54,7 +54,7 @@ def tearDown(self):
5454 self .term_api .shutdown (k ['name' ])
5555
5656 def test_no_terminals (self ):
57- # Make sure there are no terminals running at the start
57+ # Make sure there are no terminals are running at the start
5858 terminals = self .term_api .list ().json ()
5959 self .assertEqual (terminals , [])
6060
@@ -65,6 +65,74 @@ def test_create_terminal(self):
6565 self .assertEqual (r .status_code , 200 )
6666 self .assertIsInstance (term1 , dict )
6767
68+ def test_create_terminal_via_get (self ):
69+ # Test creation of terminal via GET against terminals/new/<name>
70+ r = self .term_api ._req ('GET' , 'terminals/new' )
71+ self .assertEqual (r .status_code , 200 )
72+
73+ r = self .term_api .get ('1' )
74+ term1 = r .json ()
75+ self .assertEqual (r .status_code , 200 )
76+ self .assertIsInstance (term1 , dict )
77+ self .assertEqual (term1 ['name' ], '1' )
78+
79+ # hit the same endpoint a second time and ensure a second named terminal is created
80+ r = self .term_api ._req ('GET' , 'terminals/new' )
81+ self .assertEqual (r .status_code , 200 )
82+
83+ r = self .term_api .get ('2' )
84+ term2 = r .json ()
85+ self .assertEqual (r .status_code , 200 )
86+ self .assertIsInstance (term2 , dict )
87+ self .assertEqual (term2 ['name' ], '2' )
88+
89+ r = self .term_api .shutdown ('2' )
90+ self .assertEqual (r .status_code , 204 )
91+
92+ # Make sure there is 1 terminal running
93+ terminals = self .term_api .list ().json ()
94+ self .assertEqual (len (terminals ), 1 )
95+
96+ r = self .term_api .shutdown ('1' )
97+ self .assertEqual (r .status_code , 204 )
98+
99+ # Make sure there are no terminals are running
100+ terminals = self .term_api .list ().json ()
101+ self .assertEqual (len (terminals ), 0 )
102+
103+ def test_create_terminal_with_name (self ):
104+ # Test creation of terminal via GET against terminals/new/<name>
105+ r = self .term_api ._req ('GET' , 'terminals/new/foo' )
106+ self .assertEqual (r .status_code , 200 )
107+
108+ r = self .term_api .get ('foo' )
109+ foo_term = r .json ()
110+ self .assertEqual (r .status_code , 200 )
111+ self .assertIsInstance (foo_term , dict )
112+ self .assertEqual (foo_term ['name' ], 'foo' )
113+
114+ # hit the same endpoint a second time and ensure 302 with Location is returned
115+ r = self .term_api ._req ('GET' , 'terminals/new/foo' )
116+ # Access the "interesting" response from the history
117+ self .assertEqual (len (r .history ), 1 )
118+ r = r .history [0 ]
119+ foo_term = r .json ()
120+ self .assertEqual (r .status_code , 302 )
121+ self .assertEqual (r .headers ['Location' ], self .url_prefix + "terminals/foo" )
122+ self .assertIsInstance (foo_term , dict )
123+ self .assertEqual (foo_term ['name' ], 'foo' )
124+
125+ r = self .term_api .shutdown ('foo' )
126+ self .assertEqual (r .status_code , 204 )
127+
128+ # Make sure there are no terminals are running
129+ terminals = self .term_api .list ().json ()
130+ self .assertEqual (len (terminals ), 0 )
131+
132+ # hit terminals/new/new and ensure that 400 is raised
133+ with assert_http_error (400 ):
134+ self .term_api ._req ('GET' , 'terminals/new/new' )
135+
68136 def test_terminal_root_handler (self ):
69137 # POST request
70138 r = self .term_api .start ()
0 commit comments