mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 16:56:22 +02:00
feat: Add end-to-end tests for document upload pipeline and shared test utilities
- Introduced new test files for end-to-end testing of document uploads, including support for .txt, .md, and .pdf formats. - Created shared fixtures and helper functions for authentication, document management, and cleanup. - Added sample documents for testing purposes. - Established a conftest.py file to provide reusable fixtures across test modules.
This commit is contained in:
parent
b7447b26f9
commit
41eb68663a
10 changed files with 802 additions and 0 deletions
73
surfsense_backend/tests/conftest.py
Normal file
73
surfsense_backend/tests/conftest.py
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
"""Root conftest — shared fixtures available to all test modules."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
from collections.abc import AsyncGenerator
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from tests.utils.helpers import (
|
||||
BACKEND_URL,
|
||||
TEST_SEARCH_SPACE_ID,
|
||||
auth_headers,
|
||||
delete_document,
|
||||
get_auth_token,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def backend_url() -> str:
|
||||
return BACKEND_URL
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def search_space_id() -> int:
|
||||
return TEST_SEARCH_SPACE_ID
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
async def auth_token(backend_url: str) -> str:
|
||||
"""Authenticate once per session and return the JWT token."""
|
||||
async with httpx.AsyncClient(
|
||||
base_url=backend_url, timeout=30.0
|
||||
) as client:
|
||||
return await get_auth_token(client)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def headers(auth_token: str) -> dict[str, str]:
|
||||
"""Authorization headers reused across all tests in the session."""
|
||||
return auth_headers(auth_token)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def client(backend_url: str) -> AsyncGenerator[httpx.AsyncClient]:
|
||||
"""Per-test async HTTP client pointing at the running backend."""
|
||||
async with httpx.AsyncClient(
|
||||
base_url=backend_url, timeout=180.0
|
||||
) as c:
|
||||
yield c
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cleanup_doc_ids() -> list[int]:
|
||||
"""Accumulator for document IDs that should be deleted after the test."""
|
||||
return []
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
async def _cleanup_documents(
|
||||
client: httpx.AsyncClient,
|
||||
headers: dict[str, str],
|
||||
cleanup_doc_ids: list[int],
|
||||
):
|
||||
"""
|
||||
Runs after every test. Deletes any document IDs that were appended to
|
||||
the ``cleanup_doc_ids`` list during the test body.
|
||||
"""
|
||||
yield
|
||||
for doc_id in cleanup_doc_ids:
|
||||
with contextlib.suppress(Exception):
|
||||
await delete_document(client, headers, doc_id)
|
||||
Loading…
Add table
Add a link
Reference in a new issue