-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_endpoint.py
More file actions
102 lines (83 loc) · 3.06 KB
/
Copy pathtest_endpoint.py
File metadata and controls
102 lines (83 loc) · 3.06 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3
"""
Quick test script for the new process endpoint with optional document_id.
Run this after starting the FastAPI server.
"""
import subprocess
import time
import sys
def test_endpoint():
"""Test the new process endpoint."""
print("=" * 60)
print("Testing: /api/v1/documents/process with optional document_id")
print("=" * 60)
# First, make sure the server is running
print("\n⏳ Waiting for server to be ready...")
for i in range(5):
try:
import requests
response = requests.get("http://localhost:8000/api/v1/health")
if response.status_code == 200:
print("✅ Server is ready!")
break
except:
if i < 4:
print(f" Attempt {i+1}/5 - Server not ready yet...")
time.sleep(1)
print("\n" + "=" * 60)
print("Test 1: Process with auto-generated document_id")
print("=" * 60)
curl_cmd_1 = [
"curl", "-X", "POST",
"http://localhost:8000/api/v1/documents/process",
"-H", "X-API-Key: test-key",
"-F", "file=@documents/test01.png"
]
print(f"\n$ curl -X POST http://localhost:8000/api/v1/documents/process \\")
print(f" -H 'X-API-Key: test-key' \\")
print(f" -F 'file=@documents/test01.png'")
print("\nResponse:")
try:
result = subprocess.run(curl_cmd_1, capture_output=True, text=True)
print(result.stdout)
if result.stderr:
print("Error:", result.stderr)
except Exception as e:
print(f"Error running curl: {e}")
print("\n" + "=" * 60)
print("Test 2: Process with custom document_id")
print("=" * 60)
curl_cmd_2 = [
"curl", "-X", "POST",
"http://localhost:8000/api/v1/documents/process?document_id=my-test-doc-001",
"-H", "X-API-Key: test-key",
"-F", "file=@documents/test01.png"
]
print(f"\n$ curl -X POST 'http://localhost:8000/api/v1/documents/process?document_id=my-test-doc-001' \\")
print(f" -H 'X-API-Key: test-key' \\")
print(f" -F 'file=@documents/test01.png'")
print("\nResponse:")
try:
result = subprocess.run(curl_cmd_2, capture_output=True, text=True)
print(result.stdout)
if result.stderr:
print("Error:", result.stderr)
except Exception as e:
print(f"Error running curl: {e}")
print("\n" + "=" * 60)
print("✅ Tests completed!")
print("=" * 60)
print("\nDocumentation:")
print(" - See PROCESS_ENDPOINT.md for full endpoint documentation")
print(" - See examples/test_process_with_id.py for Python examples")
print(" - Access API docs at: http://localhost:8000/docs")
if __name__ == "__main__":
print("""
📋 QUICK TEST SCRIPT
Before running this script, make sure:
1. The FastAPI server is running: python -m uvicorn app.main:app --reload
2. You're in the project root directory
3. You have curl installed (usually pre-installed on macOS/Linux)
""")
input("Press Enter to start tests...")
test_endpoint()