Download api/tests/conftest.py from Text-to-Document-Generation/Docgenie-API: direct link, hf CLI and curl.
- Browser
- Download file 2.74 kB
-
https://huggingface.co/spaces/Text-to-Document-Generation/Docgenie-API/resolve/main/api/tests/conftest.py
- Command line
-
hf download hf://spaces/Text-to-Document-Generation/Docgenie-API/api/tests/conftest.py
-
curl -L -o conftest.py https://huggingface.co/spaces/Text-to-Document-Generation/Docgenie-API/resolve/main/api/tests/conftest.py
2.74 kB
| """ | |
| 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 | |
| # --------------------------------------------------------------------------- | |
| def base_url() -> str: | |
| return BASE_URL | |
| def http() -> requests.Session: | |
| """Shared requests.Session with sensible defaults.""" | |
| s = requests.Session() | |
| s.headers.update({"Content-Type": "application/json"}) | |
| return s | |
| 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 | |
| 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 | |