@@ -185,37 +185,26 @@ def test_403(self):
185185 def test_400 (self ):
186186 #Test Delete behavior
187187 #Test delete of file in hidden directory
188- with self .assertRaises (HTTPError ) as excinfo :
189- with TemporaryDirectory () as td :
190- cm = FileContentsManager (root_dir = td )
191- hidden_dir = '.hidden'
192- file_in_hidden_path = os .path .join (hidden_dir ,'visible.txt' )
193- _make_dir (cm , hidden_dir )
194- model = cm .new (path = file_in_hidden_path )
195- os_path = cm ._get_os_path (model ['path' ])
188+ with TemporaryDirectory () as td :
189+ cm = FileContentsManager (root_dir = td )
190+ hidden_dir = '.hidden'
191+ file_in_hidden_path = os .path .join (hidden_dir ,'visible.txt' )
192+ _make_dir (cm , hidden_dir )
193+
194+ with self .assertRaises (HTTPError ) as excinfo :
195+ cm .delete_file (file_in_hidden_path )
196+ self .assertEqual (excinfo .exception .status_code , 400 )
196197
197- try :
198- result = cm .delete_file (os_path )
199- except HTTPError as e :
200- self .assertEqual (e .status_code , 400 )
201- else :
202- self .fail ("Should have raised HTTPError(400)" )
203198 #Test delete hidden file in visible directory
204- with self .assertRaises (HTTPError ) as excinfo :
205- with TemporaryDirectory () as td :
206- cm = FileContentsManager (root_dir = td )
207- hidden_dir = 'visible'
208- file_in_hidden_path = os .path .join (hidden_dir ,'.hidden.txt' )
209- _make_dir (cm , hidden_dir )
210- model = cm .new (path = file_in_hidden_path )
211- os_path = cm ._get_os_path (model ['path' ])
199+ with TemporaryDirectory () as td :
200+ cm = FileContentsManager (root_dir = td )
201+ hidden_dir = 'visible'
202+ file_in_hidden_path = os .path .join (hidden_dir ,'.hidden.txt' )
203+ _make_dir (cm , hidden_dir )
212204
213- try :
214- result = cm .delete_file (os_path )
215- except HTTPError as e :
216- self .assertEqual (e .status_code , 400 )
217- else :
218- self .fail ("Should have raised HTTPError(400)" )
205+ with self .assertRaises (HTTPError ) as excinfo :
206+ cm .delete_file (file_in_hidden_path )
207+ self .assertEqual (excinfo .exception .status_code , 400 )
219208
220209 #Test Save behavior
221210 #Test save of file in hidden directory
@@ -253,76 +242,56 @@ def test_400(self):
253242
254243 #Test rename behavior
255244 #Test rename with source file in hidden directory
256- with self .assertRaises (HTTPError ) as excinfo :
257- with TemporaryDirectory () as td :
258- cm = FileContentsManager (root_dir = td )
259- hidden_dir = '.hidden'
260- file_in_hidden_path = os .path .join (hidden_dir ,'visible.txt' )
261- _make_dir (cm , hidden_dir )
262- model = cm .new (path = file_in_hidden_path )
263- old_path = cm ._get_os_path (model ['path' ])
264- new_path = "new.txt"
245+ with TemporaryDirectory () as td :
246+ cm = FileContentsManager (root_dir = td )
247+ hidden_dir = '.hidden'
248+ file_in_hidden_path = os .path .join (hidden_dir ,'visible.txt' )
249+ _make_dir (cm , hidden_dir )
250+ old_path = file_in_hidden_path
251+ new_path = "new.txt"
265252
266- try :
267- result = cm .rename_file (old_path , new_path )
268- except HTTPError as e :
269- self .assertEqual (e .status_code , 400 )
270- else :
271- self .fail ("Should have raised HTTPError(400)" )
253+ with self .assertRaises (HTTPError ) as excinfo :
254+ cm .rename_file (old_path , new_path )
255+ self .assertEqual (excinfo .exception .status_code , 400 )
272256
273257 #Test rename of dest file in hidden directory
274- with self .assertRaises (HTTPError ) as excinfo :
275- with TemporaryDirectory () as td :
276- cm = FileContentsManager (root_dir = td )
277- hidden_dir = '.hidden'
278- file_in_hidden_path = os .path .join (hidden_dir ,'visible.txt' )
279- _make_dir (cm , hidden_dir )
280- model = cm .new (path = file_in_hidden_path )
281- new_path = cm ._get_os_path (model ['path' ])
282- old_path = "old.txt"
258+ with TemporaryDirectory () as td :
259+ cm = FileContentsManager (root_dir = td )
260+ hidden_dir = '.hidden'
261+ file_in_hidden_path = os .path .join (hidden_dir ,'visible.txt' )
262+ _make_dir (cm , hidden_dir )
263+ new_path = file_in_hidden_path
264+ old_path = "old.txt"
283265
284- try :
285- result = cm .rename_file (old_path , new_path )
286- except HTTPError as e :
287- self .assertEqual (e .status_code , 400 )
288- else :
289- self .fail ("Should have raised HTTPError(400)" )
266+ with self .assertRaises (HTTPError ) as excinfo :
267+ cm .rename_file (old_path , new_path )
268+ self .assertEqual (excinfo .exception .status_code , 400 )
290269
291270 #Test rename with hidden source file in visible directory
292- with self .assertRaises (HTTPError ) as excinfo :
293- with TemporaryDirectory () as td :
294- cm = FileContentsManager (root_dir = td )
295- hidden_dir = 'visible'
296- file_in_hidden_path = os .path .join (hidden_dir ,'.hidden.txt' )
297- _make_dir (cm , hidden_dir )
298- model = cm .new (path = file_in_hidden_path )
299- old_path = cm ._get_os_path (model ['path' ])
300- new_path = "new.txt"
271+ with TemporaryDirectory () as td :
272+ cm = FileContentsManager (root_dir = td )
273+ hidden_dir = 'visible'
274+ file_in_hidden_path = os .path .join (hidden_dir ,'.hidden.txt' )
275+ _make_dir (cm , hidden_dir )
276+ old_path = file_in_hidden_path
277+ new_path = "new.txt"
301278
302- try :
303- result = cm .rename_file (old_path , new_path )
304- except HTTPError as e :
305- self .assertEqual (e .status_code , 400 )
306- else :
307- self .fail ("Should have raised HTTPError(400)" )
279+ with self .assertRaises (HTTPError ) as excinfo :
280+ cm .rename_file (old_path , new_path )
281+ self .assertEqual (excinfo .exception .status_code , 400 )
308282
309283 #Test rename with hidden dest file in visible directory
310- with self .assertRaises (HTTPError ) as excinfo :
311- with TemporaryDirectory () as td :
312- cm = FileContentsManager (root_dir = td )
313- hidden_dir = 'visible'
314- file_in_hidden_path = os .path .join (hidden_dir ,'.hidden.txt' )
315- _make_dir (cm , hidden_dir )
316- model = cm .new (path = file_in_hidden_path )
317- new_path = cm ._get_os_path (model ['path' ])
318- old_path = "old.txt"
319-
320- try :
321- result = cm .rename_file (old_path , new_path )
322- except HTTPError as e :
323- self .assertEqual (e .status_code , 400 )
324- else :
325- self .fail ("Should have raised HTTPError(400)" )
284+ with TemporaryDirectory () as td :
285+ cm = FileContentsManager (root_dir = td )
286+ hidden_dir = 'visible'
287+ file_in_hidden_path = os .path .join (hidden_dir ,'.hidden.txt' )
288+ _make_dir (cm , hidden_dir )
289+ new_path = file_in_hidden_path
290+ old_path = "old.txt"
291+
292+ with self .assertRaises (HTTPError ) as excinfo :
293+ cm .rename_file (old_path , new_path )
294+ self .assertEqual (excinfo .exception .status_code , 400 )
326295
327296 @skipIf (sys .platform .startswith ('win' ), "Can't test hidden files on Windows" )
328297 def test_404 (self ):
0 commit comments