File size: 2,742 Bytes
dc4e6da | 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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | """
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
|