Spaces:
Sleeping
Sleeping
File size: 1,485 Bytes
46eecf4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | """Pytest configuration and fixtures."""
import asyncio
from typing import AsyncGenerator, Generator
import pytest
from fastapi.testclient import TestClient
from httpx import AsyncClient, ASGITransport
from app.main import app, create_app
@pytest.fixture(scope="session")
def event_loop() -> Generator[asyncio.AbstractEventLoop, None, None]:
"""Create event loop for async tests."""
loop = asyncio.new_event_loop()
yield loop
loop.close()
@pytest.fixture
def client() -> Generator[TestClient, None, None]:
"""Create sync test client."""
with TestClient(app) as c:
yield c
@pytest.fixture
async def async_client() -> AsyncGenerator[AsyncClient, None]:
"""Create async test client."""
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as c:
yield c
@pytest.fixture
def sample_task() -> dict:
"""Sample task data for testing."""
return {
"task_id": "test_task_001",
"task_name": "Extract Product Info",
"task_type": "extraction",
"target_fields": ["name", "price", "description"],
"target_url": "https://example.com/product/123",
}
@pytest.fixture
def sample_action() -> dict:
"""Sample action data for testing."""
return {
"action_type": "extract_field",
"parameters": {
"field_name": "price",
"selector": ".product-price",
},
"confidence": 0.95,
}
|