Files
django-vue3-admin/backend/conftest.py
T
lewis_yan 45eccc45ec test: update Django+DRF testing infrastructure
- pytest.ini: use application.test_settings for MSSQL compatibility
- conftest.py: move to backend root; use UserFactory with Sequence
- application/test_settings.py: NoCreateTestDatabase patch for MSSQL
- test_serializers.py: use chinese error keys (django_restql behavior)
- test_views.py: use API response code assertions (SuccessResponse format)
2026-04-02 10:26:12 +08:00

35 lines
755 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,username 使用 Sequence 确保唯一)"""
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