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