DocHub/backend/tests/test_local_file_client.py
Tianyang 4c19fad561 refactor: replace Garage/S3 storage with local filesystem storage
Single-node deployment doesn't benefit from S3 abstraction overhead;
LocalFileClient keeps the same interface DocumentService depends on,
backed by a STORAGE_DIR volume mount instead of a separate Garage service.
2026-08-01 16:30:02 +08:00

55 lines
1.6 KiB
Python

import pytest
from app.local_file_client import LocalFileClient
@pytest.fixture
def client(tmp_path):
return LocalFileClient(str(tmp_path))
def test_put_and_get_object_roundtrip(client):
client.put_object("产品文档/架构设计.md", b"# hi", "text/markdown")
assert client.get_object("产品文档/架构设计.md") == b"# hi"
def test_get_object_raises_file_not_found_for_missing_key(client):
with pytest.raises(FileNotFoundError):
client.get_object("不存在/文档.md")
def test_delete_object_removes_file(client):
client.put_object("产品文档/旧文档.md", b"old", "text/markdown")
client.delete_object("产品文档/旧文档.md")
with pytest.raises(FileNotFoundError):
client.get_object("产品文档/旧文档.md")
def test_delete_object_raises_file_not_found_for_missing_key(client):
with pytest.raises(FileNotFoundError):
client.delete_object("不存在/文档.md")
def test_list_objects_returns_files_and_dirs_at_prefix(client):
client.put_object("产品文档/架构设计.md", b"# hi", "text/markdown")
client.put_object("团队规范/编码规范.md", b"# rules", "text/markdown")
result = client.list_objects("产品文档/")
assert len(result) == 1
assert result[0]["key"] == "产品文档/架构设计.md"
assert result[0]["size"] == 4
assert result[0]["is_dir"] is False
def test_list_objects_returns_empty_list_for_missing_prefix(client):
assert client.list_objects("不存在/") == []
def test_resolve_path_rejects_path_traversal(client):
with pytest.raises(ValueError):
client.get_object("../../etc/passwd")