Files
django-vue3-admin/backend/tests/conftest.py
T
lewis_yan 5d0274c519 test: add MinIO file upload integration tests
- 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
2026-04-03 16:52:56 +08:00

34 lines
738 B
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 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