Files
novalon-manage-system/tests_suite/fixtures/api_fixtures.py
T
张翔 c50ccd258f feat: 重构测试框架并优化代码结构
refactor(tests): 将e2e_tests迁移到tests_suite和api_integration_tests
style: 为Java类添加文档注释
docs: 更新.gitignore和配置文件
test: 添加性能测试和Playwright测试脚本
chore: 清理旧测试文件和配置
2026-03-14 13:49:39 +08:00

47 lines
1.4 KiB
Python

import pytest
from typing import Generator, Dict, Any
from httpx import AsyncClient, Client
from playwright.sync_api import Page, BrowserContext
from config import settings
@pytest.fixture(scope="session")
def api_base_url() -> str:
return settings.API_BASE_URL
@pytest.fixture(scope="session")
def web_base_url() -> str:
return settings.WEB_BASE_URL
@pytest.fixture(scope="function")
def api_client(api_base_url: str) -> Generator[Client, None, None]:
with Client(base_url=api_base_url, timeout=settings.REQUEST_TIMEOUT) as client:
yield client
@pytest.fixture(scope="function")
def async_api_client(api_base_url: str) -> Generator[AsyncClient, None, None]:
async with AsyncClient(base_url=api_base_url, timeout=settings.REQUEST_TIMEOUT) as client:
yield client
@pytest.fixture(scope="function")
def auth_headers(api_client: Client) -> Dict[str, str]:
response = api_client.post(
"/api/auth/login",
json={
"username": settings.TEST_USERNAME,
"password": settings.TEST_PASSWORD
}
)
data = response.json()
token = data.get("token", data.get("access_token", ""))
return {"Authorization": f"Bearer {token}"}
@pytest.fixture(scope="function")
def authenticated_client(api_client: Client, auth_headers: Dict[str, str]) -> Client:
api_client.headers.update(auth_headers)
return api_client