This commit is contained in:
kodi
2026-03-11 15:25:32 +01:00
parent 6a1a575383
commit d1f018a130
22 changed files with 909 additions and 49 deletions
@@ -21,13 +21,21 @@ from backend.app.services.browse_service import BrowseService
class BrowseApiGoldenTest(unittest.TestCase):
def setUp(self) -> None:
self.temp_dir = tempfile.TemporaryDirectory()
self.root = Path(self.temp_dir.name) / "root"
self.volumes_root = Path(self.temp_dir.name) / "Volumes"
self.volumes_root.mkdir(parents=True, exist_ok=True)
self.root = self.volumes_root / "8TB"
self.root.mkdir(parents=True, exist_ok=True)
self.second_root = self.volumes_root / "8TB_RAID1"
self.second_root.mkdir(parents=True, exist_ok=True)
self.unconfigured_root = self.volumes_root / "Other"
self.unconfigured_root.mkdir(parents=True, exist_ok=True)
folder = self.root / "folder"
folder.mkdir()
file_path = self.root / "video.mkv"
file_path.write_bytes(b"abc")
second_file = self.second_root / "archive.txt"
second_file.write_text("z", encoding="utf-8")
hidden_dir = self.root / ".hidden_dir"
hidden_dir.mkdir()
@@ -35,14 +43,14 @@ class BrowseApiGoldenTest(unittest.TestCase):
hidden_file.write_bytes(b"x")
mtime = 1710000000
for path in [folder, file_path, hidden_dir, hidden_file]:
for path in [folder, file_path, hidden_dir, hidden_file, second_file]:
Path(path).touch()
Path(path).chmod(0o755)
import os
os.utime(path, (mtime, mtime))
service = BrowseService(
path_guard=PathGuard({"storage1": str(self.root)}),
path_guard=PathGuard({"storage1": str(self.root), "storage2": str(self.second_root)}),
filesystem=FilesystemAdapter(),
)
async def _override_browse_service() -> BrowseService:
@@ -100,6 +108,49 @@ class BrowseApiGoldenTest(unittest.TestCase):
self.assertEqual(directory_names, [".hidden_dir", "folder"])
self.assertEqual(file_names, [".secret", "video.mkv"])
def test_browse_virtual_volumes_lists_only_configured_mounts(self) -> None:
response = self._get("/Volumes")
self.assertEqual(response.status_code, 200)
self.assertEqual(
response.json(),
{
"path": "/Volumes",
"directories": [
{"name": "8TB", "path": "/Volumes/8TB", "modified": ""},
{"name": "8TB_RAID1", "path": "/Volumes/8TB_RAID1", "modified": ""},
],
"files": [],
},
)
def test_browse_virtual_mount_maps_to_configured_root(self) -> None:
response = self._get("/Volumes/8TB")
self.assertEqual(response.status_code, 200)
modified = datetime.fromtimestamp(1710000000, tz=timezone.utc).isoformat().replace("+00:00", "Z")
self.assertEqual(
response.json(),
{
"path": "/Volumes/8TB",
"directories": [
{
"name": "folder",
"path": "/Volumes/8TB/folder",
"modified": modified,
}
],
"files": [
{
"name": "video.mkv",
"path": "/Volumes/8TB/video.mkv",
"size": 3,
"modified": modified,
}
],
},
)
if __name__ == "__main__":
unittest.main()
@@ -41,13 +41,16 @@ class UiSmokeGoldenTest(unittest.TestCase):
self.assertIn("F6", body)
self.assertIn("F7", body)
self.assertIn("F8", body)
self.assertIn("Alt+R", body)
self.assertIn('id="viewer-modal"', body)
self.assertIn('id="viewer-content"', body)
self.assertIn('id="editor-modal"', body)
self.assertIn('id="editor-content"', body)
self.assertIn('id="editor-save-btn"', body)
self.assertIn('id="editor-cancel-btn"', body)
self.assertIn('id="rename-move-popup"', body)
self.assertIn('id="rename-move-input"', body)
self.assertIn('id="batch-move-popup"', body)
self.assertIn('id="batch-move-apply-btn"', body)
self.assertIn('id="mkdir-btn"', body)
self.assertIn('id="copy-btn"', body)
self.assertIn('id="move-btn"', body)
@@ -77,6 +80,8 @@ class UiSmokeGoldenTest(unittest.TestCase):
static_root = Path(mount.app.directory)
self.assertTrue((static_root / "app.js").exists())
self.assertTrue((static_root / "style.css").exists())
app_js = (static_root / "app.js").read_text(encoding="utf-8")
self.assertIn('currentPath: "/Volumes"', app_js)
app_js_url = app.url_path_for("ui", path="/app.js")
style_css_url = app.url_path_for("ui", path="/style.css")
+19
View File
@@ -11,6 +11,25 @@ from backend.app.config import get_settings
class ConfigTest(unittest.TestCase):
def test_default_root_aliases_include_storage1_and_storage2(self) -> None:
original = os.environ.get("WEBMANAGER_ROOT_ALIASES")
try:
os.environ.pop("WEBMANAGER_ROOT_ALIASES", None)
settings = get_settings()
finally:
if original is None:
os.environ.pop("WEBMANAGER_ROOT_ALIASES", None)
else:
os.environ["WEBMANAGER_ROOT_ALIASES"] = original
self.assertEqual(
settings.root_aliases,
{
"storage1": "/Volumes/8TB",
"storage2": "/Volumes/8TB_RAID1",
},
)
def test_default_task_db_path_is_backend_data_absolute(self) -> None:
original = os.environ.get("WEBMANAGER_TASK_DB_PATH")
try: