Skip to content

Commit 68413fe

Browse files
committed
cover tests
1 parent afe0654 commit 68413fe

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

_test_unstructured_client/unit/test_server_urls.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,125 @@ async def test_async_endpoint_uses_correct_url(monkeypatch, case: URLTestCase):
155155
pytest.fail(
156156
f"{case.description}: Expected {case.expected_url}, got {e}"
157157
)
158+
159+
160+
@pytest.mark.parametrize(
161+
"case",
162+
[
163+
URLTestCase(
164+
description="non UNST domain client-level URL, no path",
165+
sdk_endpoint_name="general.partition",
166+
client_url="http://localhost:8000",
167+
endpoint_url=None,
168+
expected_url="http://localhost:8000"
169+
),
170+
URLTestCase(
171+
description="non UNST domain client-level URL, with path",
172+
sdk_endpoint_name="general.partition",
173+
client_url="http://localhost:8000/my/endpoint",
174+
endpoint_url=None,
175+
expected_url="http://localhost:8000/my/endpoint"
176+
),
177+
URLTestCase(
178+
description="non UNST domain endpoint-level URL, no path",
179+
sdk_endpoint_name="general.partition",
180+
client_url=None,
181+
endpoint_url="http://localhost:8000",
182+
expected_url="http://localhost:8000"
183+
),
184+
URLTestCase(
185+
description="non UNST domain endpoint-level URL, with path",
186+
sdk_endpoint_name="general.partition",
187+
client_url=None,
188+
endpoint_url="http://localhost:8000/my/endpoint",
189+
expected_url="http://localhost:8000/my/endpoint"
190+
),
191+
URLTestCase(
192+
description="UNST domain client-level URL, no path",
193+
sdk_endpoint_name="general.partition",
194+
client_url="https://unstructured-000mock.api.unstructuredapp.io",
195+
endpoint_url=None,
196+
expected_url="https://unstructured-000mock.api.unstructuredapp.io"
197+
),
198+
URLTestCase(
199+
description="UNST domain client-level URL, with path",
200+
sdk_endpoint_name="general.partition",
201+
client_url="https://unstructured-000mock.api.unstructuredapp.io/my/endpoint/",
202+
endpoint_url=None,
203+
expected_url="https://unstructured-000mock.api.unstructuredapp.io"
204+
),
205+
URLTestCase(
206+
description="UNST domain endpoint-level URL, no path",
207+
sdk_endpoint_name="general.partition",
208+
client_url=None,
209+
endpoint_url="https://unstructured-000mock.api.unstructuredapp.io",
210+
expected_url="https://unstructured-000mock.api.unstructuredapp.io"
211+
),
212+
URLTestCase(
213+
description="UNST domain endpoint-level URL, with path",
214+
sdk_endpoint_name="general.partition",
215+
client_url=None,
216+
endpoint_url="https://unstructured-000mock.api.unstructuredapp.io/my/endpoint/",
217+
expected_url="https://unstructured-000mock.api.unstructuredapp.io"
218+
),
219+
URLTestCase(
220+
description="default URL fallback",
221+
sdk_endpoint_name="general.partition",
222+
client_url=None,
223+
endpoint_url=None,
224+
expected_url="https://api.unstructuredapp.io"
225+
),
226+
URLTestCase(
227+
description="default URL fallback",
228+
sdk_endpoint_name="destinations.create_destination",
229+
client_url=None,
230+
endpoint_url=None,
231+
expected_url="https://platform.unstructuredapp.io"
232+
),
233+
URLTestCase(
234+
description="default URL fallback",
235+
sdk_endpoint_name="sources.create_source",
236+
client_url=None,
237+
endpoint_url=None,
238+
expected_url="https://platform.unstructuredapp.io"
239+
),
240+
URLTestCase(
241+
description="default URL fallback",
242+
sdk_endpoint_name="jobs.get_job",
243+
client_url=None,
244+
endpoint_url=None,
245+
expected_url="https://platform.unstructuredapp.io"
246+
),
247+
URLTestCase(
248+
description="default URL fallback",
249+
sdk_endpoint_name="workflows.create_workflow",
250+
client_url=None,
251+
endpoint_url=None,
252+
expected_url="https://platform.unstructuredapp.io"
253+
),
254+
]
255+
)
256+
def test_endpoint_uses_correct_url(monkeypatch, case: URLTestCase):
257+
if case.client_url:
258+
s = UnstructuredClient(server_url=case.client_url)
259+
else:
260+
s = UnstructuredClient()
261+
262+
client_method = get_client_method_with_mock(
263+
case.sdk_endpoint_name,
264+
s,
265+
case.expected_url,
266+
monkeypatch
267+
)
268+
269+
try:
270+
if case.endpoint_url:
271+
client_method(request={}, server_url=case.endpoint_url)
272+
else:
273+
client_method(request={})
274+
except BaseUrlCorrect:
275+
pass
276+
except BaseUrlIncorrect as e:
277+
pytest.fail(
278+
f"{case.description}: Expected {case.expected_url}, got {e}"
279+
)

0 commit comments

Comments
 (0)