2
2
import os
3
3
from aiohttp import web
4
4
from app .user_manager import UserManager
5
+ from unittest .mock import patch
5
6
6
7
pytestmark = (
7
8
pytest .mark .asyncio
@@ -53,7 +54,7 @@ async def test_listuserdata_recursive(aiohttp_client, app, tmp_path):
53
54
client = await aiohttp_client (app )
54
55
resp = await client .get ("/userdata?dir=test_dir&recurse=true" )
55
56
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" }
57
58
58
59
59
60
async 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):
80
81
resp = await client .get ("/userdata?dir=test_dir&recurse=true&split=true" )
81
82
assert resp .status == 200
82
83
assert await resp .json () == [
83
- [os . path . join ( "subdir" , " file1.txt") , "subdir" , "file1.txt" ]
84
+ ["subdir/ file1.txt" , "subdir" , "file1.txt" ]
84
85
]
85
86
86
87
87
88
async def test_listuserdata_invalid_directory (aiohttp_client , app ):
88
89
client = await aiohttp_client (app )
89
90
resp = await client .get ("/userdata?dir=" )
90
91
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