dingdanquanliucheng/backend/tests/test_files_extended.py
2026-06-19 23:03:14 +08:00

47 lines
1.5 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.

"""文件管理扩展测试。
测试用例:
- FILE-006b: 查询关联附件
- FILE-006c: 本地开发上传
- FILE-007: 未认证不能上传
"""
from __future__ import annotations
import pytest
@pytest.mark.file
@pytest.mark.p1
class TestFileAttachmentQuery:
"""附件查询测试。"""
def test_list_attachments_empty(self, client, admin_headers):
"""FILE-006b: 查询空附件列表。"""
resp = client.get("/api/files/attachments?biz_type=order&biz_id=99999", headers=admin_headers)
assert resp.status_code == 200
def test_unauthenticated_cannot_upload(self, client):
"""FILE-007: 未认证不能上传。"""
resp = client.post("/api/files/upload-token", json={"file_name": "test.jpg"})
assert resp.status_code == 401
def test_unauthenticated_cannot_list(self, client):
"""未认证不能查询附件。"""
resp = client.get("/api/files/attachments?biz_type=order&biz_id=1")
assert resp.status_code == 401
@pytest.mark.file
@pytest.mark.p1
class TestFileUploadToken:
"""上传凭证测试。"""
def test_get_upload_token(self, client, admin_headers):
"""获取上传凭证。"""
resp = client.post("/api/files/upload-token", headers=admin_headers, json={
"file_name": "test.jpg",
"content_type": "image/jpeg",
})
# 应返回 200 或 404/422/500如果 OSS 未配置或 schema 不匹配)
assert resp.status_code in (200, 404, 422, 500)