Docgenie-API / api /tests /conftest.py
Ahadhassan-2003
deploy: update HF Space
dc4e6da
"""
Shared fixtures and configuration for the DocGenie API test suite.
All tests target the deployed HuggingFace Space:
https://text-to-document-generation-docgenie-api.hf.space
The /generate/pdf and /generate/async endpoints both require a valid
`request_id` that exists in the Supabase `document_requests` table.
Since we are exercising the *deployed* API (read-only from our perspective),
tests that need a request_id receive a FAKE UUID — this intentionally
surfaces the 404 path (which is a valid functional test for those endpoints).
The suite is designed so every test is safe to run repeatedly.
"""
import time
import pytest
import requests
# ---------------------------------------------------------------------------
# Constants
# ---------------------------------------------------------------------------
BASE_URL = "https://text-to-document-generation-docgenie-api.hf.space"
TIMEOUT = 30 # seconds per HTTP request
SEED_IMAGE_URL = "https://ocr.space/Content/Images/receipt-ocr-original.webp"
# A random UUID that will *never* exist in Supabase — used to verify 404 paths.
NONEXISTENT_REQUEST_ID = "00000000-0000-0000-0000-000000000000"
NONEXISTENT_USER_ID = 999_999_999
MINIMAL_PROMPT_PARAMS = {
"language": "English",
"doc_type": "receipts",
"num_solutions": 1,
"enable_handwriting": False,
"enable_visual_elements": False,
"enable_ocr": False,
"enable_bbox_normalization": False,
"enable_gt_verification": False,
"enable_analysis": False,
"enable_debug_visualization": False,
"enable_dataset_export": False,
"output_detail": "minimal",
}
MINIMAL_GENERATE_PAYLOAD = {
"request_id": NONEXISTENT_REQUEST_ID,
"seed_images": [SEED_IMAGE_URL],
"google_drive_token": None,
"google_drive_refresh_token": None,
"prompt_params": MINIMAL_PROMPT_PARAMS,
}
# ---------------------------------------------------------------------------
# Session-scoped fixtures
# ---------------------------------------------------------------------------
@pytest.fixture(scope="session")
def base_url() -> str:
return BASE_URL
@pytest.fixture(scope="session")
def http() -> requests.Session:
"""Shared requests.Session with sensible defaults."""
s = requests.Session()
s.headers.update({"Content-Type": "application/json"})
return s
@pytest.fixture(scope="session")
def health_response(http, base_url):
"""Fetch /health once and share across all tests that need it."""
r = http.get(f"{base_url}/health", timeout=TIMEOUT)
return r
@pytest.fixture(scope="session")
def root_response(http, base_url):
"""Fetch / once and share across all tests that need it."""
r = http.get(f"{base_url}/", timeout=TIMEOUT)
return r