22import os
33from aiohttp import web
44from app .user_manager import UserManager
5+ from unittest .mock import patch
56
67pytestmark = (
78 pytest .mark .asyncio
@@ -53,7 +54,7 @@ async def test_listuserdata_recursive(aiohttp_client, app, tmp_path):
5354 client = await aiohttp_client (app )
5455 resp = await client .get ("/userdata?dir=test_dir&recurse=true" )
5556 assert resp .status == 200
56- assert set (await resp .json ()) == {"file1.txt" , os . path . join ( "subdir" , " file2.txt") }
57+ assert set (await resp .json ()) == {"file1.txt" , "subdir/ file2.txt" }
5758
5859
5960async def test_listuserdata_full_info (aiohttp_client , app , tmp_path ):
@@ -80,11 +81,40 @@ async def test_listuserdata_split_path(aiohttp_client, app, tmp_path):
8081 resp = await client .get ("/userdata?dir=test_dir&recurse=true&split=true" )
8182 assert resp .status == 200
8283 assert await resp .json () == [
83- [os . path . join ( "subdir" , " file1.txt") , "subdir" , "file1.txt" ]
84+ ["subdir/ file1.txt" , "subdir" , "file1.txt" ]
8485 ]
8586
8687
8788async def test_listuserdata_invalid_directory (aiohttp_client , app ):
8889 client = await aiohttp_client (app )
8990 resp = await client .get ("/userdata?dir=" )
9091 assert resp .status == 400
92+
93+
94+ async def test_listuserdata_normalized_separator (aiohttp_client , app , tmp_path ):
95+ os_sep = "\\ "
96+ with patch ("os.sep" , os_sep ):
97+ with patch ("os.path.sep" , os_sep ):
98+ os .makedirs (tmp_path / "test_dir" / "subdir" )
99+ with open (tmp_path / "test_dir" / "subdir" / "file1.txt" , "w" ) as f :
100+ f .write ("test content" )
101+
102+ client = await aiohttp_client (app )
103+ resp = await client .get ("/userdata?dir=test_dir&recurse=true" )
104+ assert resp .status == 200
105+ result = await resp .json ()
106+ assert len (result ) == 1
107+ assert "/" in result [0 ] # Ensure forward slash is used
108+ assert "\\ " not in result [0 ] # Ensure backslash is not present
109+ assert result [0 ] == "subdir/file1.txt"
110+
111+ # Test with full_info
112+ resp = await client .get (
113+ "/userdata?dir=test_dir&recurse=true&full_info=true"
114+ )
115+ assert resp .status == 200
116+ result = await resp .json ()
117+ assert len (result ) == 1
118+ assert "/" in result [0 ]["path" ] # Ensure forward slash is used
119+ assert "\\ " not in result [0 ]["path" ] # Ensure backslash is not present
120+ assert result [0 ]["path" ] == "subdir/file1.txt"
0 commit comments