-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_routers.py
More file actions
208 lines (153 loc) · 8.36 KB
/
test_routers.py
File metadata and controls
208 lines (153 loc) · 8.36 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
"""
Test functions in /src/api/app/routers.
- Note: Tests require running Docker services.
"""
from pathlib import Path
import requests
def test_router_marker(ocr_forwarding_api_port: str) -> None:
"""Test healthcheck for marker."""
response = requests.get(f"http://127.0.0.1:{ocr_forwarding_api_port}/marker/health", timeout=5)
assert response.status_code == requests.codes.ok
assert response.json() == {"service": "marker", "status": "healthy"}
def test_router_sparrow(ocr_forwarding_api_port: str) -> None:
"""
Test healthcheck for sparrow.
- Note: uses sparrow devs' own API.
"""
response = requests.get(f"http://127.0.0.1:{ocr_forwarding_api_port}/sparrow-ocr", timeout=5)
assert response.status_code == requests.codes.ok
assert response.json() == {"message": "Sparrow OCR API"}
def test_router_docling(ocr_forwarding_api_port: str) -> None:
"""Test healthcheck for docling."""
response = requests.get(f"http://127.0.0.1:{ocr_forwarding_api_port}/docling/health", timeout=5)
assert response.status_code == requests.codes.ok
assert response.json() == {"service": "docling", "status": "healthy"}
def test_router_paddleocr(ocr_forwarding_api_port: str) -> None:
"""Test healthcheck for paddleocr."""
response = requests.get(f"http://127.0.0.1:{ocr_forwarding_api_port}/paddleocr/health", timeout=5)
assert response.status_code == requests.codes.ok
assert response.json() == {"service": "paddleocr", "status": "healthy"}
def test_router_kreuzberg(ocr_forwarding_api_port: str) -> None:
"""Test healthcheck for kreuzberg."""
response = requests.get(f"http://127.0.0.1:{ocr_forwarding_api_port}/kreuzberg/health", timeout=5)
assert response.status_code == requests.codes.ok
assert response.json() == {"service": "kreuzberg", "status": "healthy"}
def test_inference_single_file_upload_marker(ocr_forwarding_api_port: str, single_pdf_filepath: Path) -> None:
"""Test PDF conversion using marker with single file endpoint."""
url = f"http://127.0.0.1:{ocr_forwarding_api_port}/marker/inference_single"
single_pdf_filename = single_pdf_filepath.name
with Path.open(single_pdf_filepath, "rb") as f:
files = {"file_upload": (single_pdf_filename, f, "application/pdf")}
headers = {"accept": "application/json"}
response = requests.post(url, files=files, headers=headers, timeout=60 * 60)
assert response.status_code == requests.codes.ok
assert response.json()["duration_in_second"] > 0
assert response.json()["filename"] in single_pdf_filename
def test_inference_single_file_upload_sparrow(ocr_forwarding_api_port: str, single_pdf_filepath: Path) -> None:
"""Test PDF conversion using sparrow with single file endpoint."""
url = f"http://127.0.0.1:{ocr_forwarding_api_port}/sparrow-ocr/inference_single"
single_pdf_filename = single_pdf_filepath.name
with Path.open(single_pdf_filepath, "rb") as f:
files = {"file_upload": (single_pdf_filename, f, "application/pdf")}
headers = {"accept": "application/json"}
response = requests.post(url, files=files, headers=headers, timeout=60 * 60)
assert response.status_code == requests.codes.ok
assert response.json()["duration_in_second"] > 0
assert response.json()["filename"] in single_pdf_filename
def test_inference_single_file_upload_docling(ocr_forwarding_api_port: str, single_pdf_filepath: Path) -> None:
"""Test PDF conversion using Docling with single file endpoint."""
url = f"http://127.0.0.1:{ocr_forwarding_api_port}/docling/inference_single"
single_pdf_filename = single_pdf_filepath.name
with Path.open(single_pdf_filepath, "rb") as f:
files = {"file_upload": (single_pdf_filename, f, "application/pdf")}
headers = {"accept": "application/json"}
response = requests.post(url, files=files, headers=headers, timeout=60 * 60)
assert response.status_code == requests.codes.ok
assert response.json()["duration_in_second"] > 0
assert response.json()["filename"] in single_pdf_filename
def test_inference_single_file_upload_paddleocr(ocr_forwarding_api_port: str, single_pdf_filepath: Path) -> None:
"""Test PDF conversion using marker with single file endpoint."""
url = f"http://127.0.0.1:{ocr_forwarding_api_port}/paddleocr/inference_single"
single_pdf_filename = single_pdf_filepath.name
with Path.open(single_pdf_filepath, "rb") as f:
files = {"file_upload": (single_pdf_filename, f, "application/pdf")}
response = requests.post(url, files=files, timeout=60 * 60)
assert response.status_code == requests.codes.ok
assert response.json()["duration_in_second"] > 0
assert response.json()["filename"] in single_pdf_filename
def test_inference_single_file_upload_kreuzberg(ocr_forwarding_api_port: str, single_pdf_filepath: Path) -> None:
"""Test PDF conversion using marker with single file endpoint."""
url = f"http://127.0.0.1:{ocr_forwarding_api_port}/kreuzberg-ocr/inference_single"
single_pdf_filename = single_pdf_filepath.name
with Path.open(single_pdf_filepath, "rb") as f:
files = {"file_upload": (single_pdf_filename, f, "application/pdf")}
response = requests.post(url, files=files, timeout=60 * 60)
assert response.status_code == requests.codes.ok
assert response.json()["duration_in_second"] >= 0
assert response.json()["filename"] == single_pdf_filename
def test_inference_on_folder_marker(ocr_forwarding_api_port: str) -> None:
"""
Test PDF conversion using marker pointed at a folder of files.
Note:
- may take ~minutes to perform inference
- four possible files assertion depending on whether testing single_synthetic_doc or multiple_synthetic_docs folder
"""
response = requests.post(f"http://127.0.0.1:{ocr_forwarding_api_port}/marker/inference_folder", timeout=60 * 60)
assert response.status_code == requests.codes.ok
assert response.json()["total_duration_in_second"] > 0
assert response.json()["result"][0]["filename"] in {
"ms-note-one-page.pdf",
"uk-hospital-note.pdf",
"uk-hospital-note-2.pdf",
"uk-hospital-note-3.pdf",
}
def test_inference_on_folder_sparrow(ocr_forwarding_api_port: str) -> None:
"""
Test PDF conversion using sparrow pointed at a folder of files.
Note:
- may take ~minutes to perform inference
- four possible files assertion depending on whether testing single_synthetic_doc or multiple_synthetic_docs folder
"""
response = requests.post(
f"http://127.0.0.1:{ocr_forwarding_api_port}/sparrow-ocr/inference_folder", timeout=60 * 60
)
assert response.status_code == requests.codes.ok
assert response.json()["total_duration_in_second"] > 0
assert response.json()["result"][0]["filename"] in {
"ms-note-one-page.pdf",
"uk-hospital-note.pdf",
"uk-hospital-note-2.pdf",
"uk-hospital-note-3.pdf",
}
def test_inference_on_folder_docling(ocr_forwarding_api_port: str) -> None:
"""
Test PDF conversion using Docling pointed at a folder of files.
Note:
- may take ~minutes to perform inference
- four possible files assertion depending on whether testing single_synthetic_doc or multiple_synthetic_docs folder
"""
response = requests.post(f"http://127.0.0.1:{ocr_forwarding_api_port}/docling/inference_folder", timeout=60 * 60)
assert response.status_code == requests.codes.ok
assert response.json()["total_duration_in_second"] > 0
assert response.json()["result"][0]["filename"] in {
"ms-note-one-page.pdf",
"uk-hospital-note.pdf",
"uk-hospital-note-2.pdf",
"uk-hospital-note-3.pdf",
}
def test_inference_on_folder_paddleocr(ocr_forwarding_api_port: str) -> None:
"""
Test PDF conversion using Docling pointed at a folder of files.
Note:
- may take ~minutes to perform inference
- four possible files assertion depending on whether testing single_synthetic_doc or multiple_synthetic_docs folder
"""
response = requests.post(f"http://127.0.0.1:{ocr_forwarding_api_port}/paddleocr/inference_folder", timeout=60 * 60)
assert response.status_code == requests.codes.ok
assert response.json()["total_duration_in_second"] > 0
assert response.json()["result"][0]["filename"] in {
"ms-note-one-page.pdf",
"uk-hospital-note.pdf",
"uk-hospital-note-2.pdf",
"uk-hospital-note-3.pdf",
}