mirror of
https://github.com/huge-dream/django-vue3-admin.git
synced 2026-10-02 16:37:50 +00:00
- Add FileListFactory for test data creation - Add TestFileUpload with 4 test cases: - test_upload_file_success (requires MinIO running) - test_upload_file_unauthenticated (passes without MinIO) - test_upload_image_success (requires MinIO running) - test_upload_without_file (passes without MinIO) - Fix admin_user/normal_user fixtures to use factory_boy sequence to avoid username collision
34 lines
738 B
Python
34 lines
738 B
Python
import pytest
|
||
from rest_framework.test import APIClient
|
||
|
||
|
||
@pytest.fixture
|
||
def api_client():
|
||
"""匿名 API 客户端"""
|
||
return APIClient()
|
||
|
||
|
||
@pytest.fixture
|
||
def authenticate(api_client, admin_user):
|
||
"""已认证的 API 客户端(管理员)"""
|
||
api_client.force_authenticate(user=admin_user)
|
||
return api_client
|
||
|
||
|
||
@pytest.fixture
|
||
def admin_user(db):
|
||
"""创建管理员用户(每个测试独立事务,测试后自动 rollback)"""
|
||
from tests.factories.system_factory import UserFactory
|
||
|
||
user = UserFactory(admin=True)
|
||
return user
|
||
|
||
|
||
@pytest.fixture
|
||
def normal_user(db):
|
||
"""创建普通用户"""
|
||
from tests.factories.system_factory import UserFactory
|
||
|
||
user = UserFactory()
|
||
return user
|