@@ -406,35 +406,44 @@ async def test_400(jp_file_contents_manager_class, tmp_path): # noqa
406406
407407
408408async def test_404 (jp_file_contents_manager_class , tmp_path ):
409+ # setup
410+ td = str (tmp_path )
411+ cm = jp_file_contents_manager_class (root_dir = td )
412+
409413 # Test visible file in hidden folder
410- with pytest .raises (HTTPError ) as excinfo :
411- td = str (tmp_path )
412- cm = jp_file_contents_manager_class (root_dir = td )
413- hidden_dir = ".hidden"
414- file_in_hidden_path = os .path .join (hidden_dir , "visible.txt" )
415- _make_dir (cm , hidden_dir )
416- model = await ensure_async (cm .new (path = file_in_hidden_path ))
417- os_path = cm ._get_os_path (model ["path" ])
414+ cm .allow_hidden = True
415+ hidden_dir = ".hidden"
416+ file_in_hidden_path = os .path .join (hidden_dir , "visible.txt" )
417+ _make_dir (cm , hidden_dir )
418+ model = await ensure_async (cm .new (path = file_in_hidden_path ))
419+ os_path = cm ._get_os_path (model ["path" ])
420+ cm .allow_hidden = False
418421
419- try :
420- result = await ensure_async (cm .get (os_path , "w" ))
421- except HTTPError as e :
422- assert e .status_code == 404
422+ with pytest .raises (HTTPError ) as excinfo :
423+ await ensure_async (cm .get (os_path ))
424+ assert excinfo .value .status_code == 404
423425
424426 # Test hidden file in visible folder
427+ cm .allow_hidden = True
428+ hidden_dir = "visible"
429+ file_in_hidden_path = os .path .join (hidden_dir , ".hidden.txt" )
430+ _make_dir (cm , hidden_dir )
431+ model = await ensure_async (cm .new (path = file_in_hidden_path ))
432+ os_path = cm ._get_os_path (model ["path" ])
433+ cm .allow_hidden = False
434+
425435 with pytest .raises (HTTPError ) as excinfo :
426- td = str (tmp_path )
427- cm = jp_file_contents_manager_class (root_dir = td )
428- hidden_dir = "visible"
429- file_in_hidden_path = os .path .join (hidden_dir , ".hidden.txt" )
430- _make_dir (cm , hidden_dir )
431- model = await ensure_async (cm .new (path = file_in_hidden_path ))
432- os_path = cm ._get_os_path (model ["path" ])
436+ await ensure_async (cm .get (os_path ))
437+ assert excinfo .value .status_code == 404
433438
434- try :
435- result = await ensure_async (cm .get (os_path , "w" ))
436- except HTTPError as e :
437- assert e .status_code == 404
439+ # Test file not found
440+ td = str (tmp_path )
441+ cm = jp_file_contents_manager_class (root_dir = td )
442+ not_a_file = "foo.bar"
443+
444+ with pytest .raises (HTTPError ) as excinfo :
445+ await ensure_async (cm .get (not_a_file ))
446+ assert excinfo .value .status_code == 404
438447
439448
440449async def test_escape_root (jp_file_contents_manager_class , tmp_path ):
0 commit comments