Files
disknext/tests/integration/api/test_object.py
于小丘 69f852a4ce
Some checks failed
Test / test (push) Failing after 1m4s
fix: align all 212 tests with current API and add CI workflows
Update integration tests to match actual endpoint responses: remove
data wrappers, use snake_case fields, correct HTTP methods (PUT→POST
for directory create), status codes (200→204 for mutations), and
request formats (params→json for 2FA). Fix root-level and unit tests
for DatabaseManager migration, model CRUD patterns, and JWT setup.
Add GitHub Actions and Gitea CI configs with ubuntu-latest + Python 3.13.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 14:21:40 +08:00

182 lines
4.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
对象操作端点集成测试
"""
import pytest
from httpx import AsyncClient
from uuid import UUID
# ==================== 删除对象测试 ====================
@pytest.mark.asyncio
async def test_object_delete_requires_auth(async_client: AsyncClient):
"""测试删除对象需要认证"""
response = await async_client.request(
"DELETE",
"/api/v1/object/",
json={"ids": ["00000000-0000-0000-0000-000000000000"]}
)
assert response.status_code == 401
@pytest.mark.asyncio
async def test_object_delete_single(
async_client: AsyncClient,
auth_headers: dict[str, str],
test_directory_structure: dict[str, UUID]
):
"""测试删除单个对象"""
file_id = test_directory_structure["file_id"]
response = await async_client.request(
"DELETE",
"/api/v1/object/",
headers=auth_headers,
json={"ids": [str(file_id)]}
)
assert response.status_code == 204
@pytest.mark.asyncio
async def test_object_delete_nonexistent(
async_client: AsyncClient,
auth_headers: dict[str, str]
):
"""测试删除不存在的对象返回 204幂等"""
fake_id = "00000000-0000-0000-0000-000000000001"
response = await async_client.request(
"DELETE",
"/api/v1/object/",
headers=auth_headers,
json={"ids": [fake_id]}
)
assert response.status_code == 204
# ==================== 移动对象测试 ====================
@pytest.mark.asyncio
async def test_object_move_requires_auth(async_client: AsyncClient):
"""测试移动对象需要认证"""
response = await async_client.patch(
"/api/v1/object/",
json={
"src_ids": ["00000000-0000-0000-0000-000000000000"],
"dst_id": "00000000-0000-0000-0000-000000000001"
}
)
assert response.status_code == 401
@pytest.mark.asyncio
async def test_object_move_success(
async_client: AsyncClient,
auth_headers: dict[str, str],
test_directory_structure: dict[str, UUID]
):
"""测试成功移动对象"""
file_id = test_directory_structure["file_id"]
images_id = test_directory_structure["images_id"]
response = await async_client.patch(
"/api/v1/object/",
headers=auth_headers,
json={
"src_ids": [str(file_id)],
"dst_id": str(images_id)
}
)
assert response.status_code == 204
@pytest.mark.asyncio
async def test_object_move_to_invalid_target(
async_client: AsyncClient,
auth_headers: dict[str, str],
test_directory_structure: dict[str, UUID]
):
"""测试无效目标返回 404"""
file_id = test_directory_structure["file_id"]
invalid_dst = "00000000-0000-0000-0000-000000000001"
response = await async_client.patch(
"/api/v1/object/",
headers=auth_headers,
json={
"src_ids": [str(file_id)],
"dst_id": invalid_dst
}
)
assert response.status_code == 404
@pytest.mark.asyncio
async def test_object_move_to_file(
async_client: AsyncClient,
auth_headers: dict[str, str],
test_directory_structure: dict[str, UUID]
):
"""测试移动到文件返回 400"""
docs_id = test_directory_structure["docs_id"]
file_id = test_directory_structure["file_id"]
response = await async_client.patch(
"/api/v1/object/",
headers=auth_headers,
json={
"src_ids": [str(docs_id)],
"dst_id": str(file_id)
}
)
assert response.status_code == 400
# ==================== 其他对象操作测试 ====================
@pytest.mark.asyncio
async def test_object_copy_endpoint_exists(
async_client: AsyncClient,
auth_headers: dict[str, str]
):
"""测试复制对象端点存在"""
response = await async_client.post(
"/api/v1/object/copy",
headers=auth_headers,
json={"src_id": "00000000-0000-0000-0000-000000000000"}
)
# 未实现的端点
assert response.status_code in [200, 204, 404, 422, 501]
@pytest.mark.asyncio
async def test_object_rename_endpoint_exists(
async_client: AsyncClient,
auth_headers: dict[str, str]
):
"""测试重命名对象端点存在"""
response = await async_client.post(
"/api/v1/object/rename",
headers=auth_headers,
json={
"id": "00000000-0000-0000-0000-000000000000",
"name": "newname"
}
)
# 未实现的端点
assert response.status_code in [200, 204, 404, 422, 501]
@pytest.mark.asyncio
async def test_object_property_endpoint_exists(
async_client: AsyncClient,
auth_headers: dict[str, str]
):
"""测试获取对象属性端点存在"""
response = await async_client.get(
"/api/v1/object/property/00000000-0000-0000-0000-000000000000",
headers=auth_headers
)
# 未实现的端点
assert response.status_code in [200, 404, 501]