Skip to content

Commit 01b7ccc

Browse files
paulkarayanclaude
andcommitted
test: pin that a non-Unstructured host keeps its subpath
The base URL is now cleaned in BaseSDK._get_url, which every operation passes through, so a self-hosted deployment behind a subpath is the regression this change could cause. The existing server-url cases mock _build_request and so cannot see it; assert on the request that is actually sent instead. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 6438c3c commit 01b7ccc

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

_test_unstructured_client/unit/test_server_urls.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,54 @@ def capture(request: httpx.Request) -> httpx.Response:
280280
client.jobs.list_jobs(request={})
281281

282282
assert sent == ["https://platform-api.transform.unstructured.io/api/v1/jobs/"]
283+
284+
285+
@pytest.mark.parametrize(
286+
"client_url,endpoint_url,expected_url",
287+
[
288+
# -- a self-hosted deployment at the root --
289+
(
290+
"http://localhost:8000",
291+
None,
292+
"http://localhost:8000/api/v1/jobs/",
293+
),
294+
(
295+
None,
296+
"http://localhost:8000",
297+
"http://localhost:8000/api/v1/jobs/",
298+
),
299+
# -- and one behind a subpath, whose path must survive --
300+
(
301+
"http://localhost:8000/my/endpoint",
302+
None,
303+
"http://localhost:8000/my/endpoint/api/v1/jobs/",
304+
),
305+
(
306+
None,
307+
"http://localhost:8000/my/endpoint",
308+
"http://localhost:8000/my/endpoint/api/v1/jobs/",
309+
),
310+
],
311+
)
312+
def test_non_unstructured_host_keeps_its_path(client_url, endpoint_url, expected_url):
313+
"""A host that is not ours may legitimately serve the API beneath a subpath."""
314+
import httpx
315+
316+
sent = []
317+
318+
def capture(request: httpx.Request) -> httpx.Response:
319+
sent.append(str(request.url))
320+
return httpx.Response(200, json=[])
321+
322+
client = UnstructuredClient(
323+
api_key_auth="fake-key",
324+
server_url=client_url,
325+
client=httpx.Client(transport=httpx.MockTransport(capture)),
326+
)
327+
328+
if endpoint_url:
329+
client.jobs.list_jobs(request={}, server_url=endpoint_url)
330+
else:
331+
client.jobs.list_jobs(request={})
332+
333+
assert sent == [expected_url]

0 commit comments

Comments
 (0)