Skip to content

Commit 40f2855

Browse files
committed
Add test case for renaming non-existent files
- Test that renaming non-existent files returns 404 instead of 500 - Covers both file and directory rename scenarios - Validates proper error message format
1 parent f2e0519 commit 40f2855

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/services/contents/test_manager.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,21 @@ async def test_rename(jp_contents_manager):
854854
await ensure_async(cm.new_untitled("foo/bar_diff", ext=".ipynb"))
855855

856856

857+
async def test_rename_nonexistent(jp_contents_manager):
858+
"""Test renaming a non-existent file/directory returns 404 error"""
859+
cm = jp_contents_manager
860+
861+
# Test with non-existent file
862+
with pytest.raises(HTTPError) as e:
863+
await ensure_async(cm.rename("nonexistent_file.txt", "new_name.txt"))
864+
assert expected_http_error(e, 404, expected_message="File or directory does not exist: nonexistent_file.txt")
865+
866+
# Test with non-existent directory
867+
with pytest.raises(HTTPError) as e:
868+
await ensure_async(cm.rename("nonexistent_dir", "new_dir"))
869+
assert expected_http_error(e, 404, expected_message="File or directory does not exist: nonexistent_dir")
870+
871+
857872
async def test_delete_root(jp_contents_manager):
858873
cm = jp_contents_manager
859874
with pytest.raises(HTTPError) as e:

0 commit comments

Comments
 (0)