Skip to content

Commit b4ecf17

Browse files
adamtheturtleclaude
andcommitted
Simplify path-prefix tests: use MockVWS + ConnectionError
Instead of using responses directly, set up MockVWS at the bare URL and assert ConnectionError when the client uses a path-prefix URL. With the old urljoin code the prefix would be silently dropped so the request would succeed; with string concatenation the prefix is preserved, the mock has no handler for it, and ConnectionError is raised as expected. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 365c501 commit b4ecf17

File tree

2 files changed

+22
-53
lines changed

2 files changed

+22
-53
lines changed

tests/test_query.py

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
import datetime
44
import io
5-
import secrets
65
import uuid
76
from typing import BinaryIO
87

98
import pytest
109
import requests
11-
import responses as responses_mock
1210
from freezegun import freeze_time
1311
from mock_vws import MockVWS
1412
from mock_vws.database import CloudDatabase
@@ -193,38 +191,24 @@ def test_custom_base_url(image: io.BytesIO | BinaryIO) -> None:
193191
assert match.target_id == target_id
194192

195193
@staticmethod
196-
@responses_mock.activate
197194
def test_custom_base_url_with_path_prefix(
198195
image: io.BytesIO | BinaryIO,
199196
) -> None:
200197
"""
201198
A base VWQ URL with a path prefix is used as-is, without the
202-
prefix
203-
being dropped.
199+
prefix being dropped.
204200
"""
205-
base_vwq_url = "http://example.com/prefix"
206-
responses_mock.add(
207-
method=responses_mock.POST,
208-
url="http://example.com/prefix/v1/query",
209-
json={
210-
"result_code": "Success",
211-
"results": [],
212-
"query_id": "abc",
213-
},
214-
status=200,
215-
)
216-
cloud_reco_client = CloudRecoService(
217-
client_access_key=secrets.token_hex(),
218-
client_secret_key=secrets.token_hex(),
219-
base_vwq_url=base_vwq_url,
220-
)
221-
222-
cloud_reco_client.query(image=image)
201+
with MockVWS(base_vwq_url="http://example.com") as mock:
202+
database = CloudDatabase()
203+
mock.add_cloud_database(cloud_database=database)
204+
cloud_reco_client = CloudRecoService(
205+
client_access_key=database.client_access_key,
206+
client_secret_key=database.client_secret_key,
207+
base_vwq_url="http://example.com/prefix",
208+
)
223209

224-
assert len(responses_mock.calls) == 1
225-
assert responses_mock.calls[0].request.url == (
226-
"http://example.com/prefix/v1/query"
227-
)
210+
with pytest.raises(requests.exceptions.ConnectionError):
211+
cloud_reco_client.query(image=image)
228212

229213

230214
class TestMaxNumResults:

tests/test_vws.py

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import pytest
1111
import requests
12-
import responses as responses_mock
1312
from freezegun import freeze_time
1413
from mock_vws import MockVWS
1514
from mock_vws.database import CloudDatabase
@@ -248,36 +247,22 @@ def test_custom_base_url(image: io.BytesIO | BinaryIO) -> None:
248247
)
249248

250249
@staticmethod
251-
@responses_mock.activate
252250
def test_custom_base_url_with_path_prefix() -> None:
253251
"""
254252
A base VWS URL with a path prefix is used as-is, without the
255-
prefix
256-
being dropped.
253+
prefix being dropped.
257254
"""
258-
base_vws_url = "http://example.com/prefix"
259-
responses_mock.add(
260-
method=responses_mock.GET,
261-
url="http://example.com/prefix/targets",
262-
json={
263-
"result_code": "Success",
264-
"results": [],
265-
"transaction_id": "abc",
266-
},
267-
status=200,
268-
)
269-
vws_client = VWS(
270-
server_access_key=secrets.token_hex(),
271-
server_secret_key=secrets.token_hex(),
272-
base_vws_url=base_vws_url,
273-
)
274-
275-
vws_client.list_targets()
255+
with MockVWS(base_vws_url="http://example.com") as mock:
256+
database = CloudDatabase()
257+
mock.add_cloud_database(cloud_database=database)
258+
vws_client = VWS(
259+
server_access_key=database.server_access_key,
260+
server_secret_key=database.server_secret_key,
261+
base_vws_url="http://example.com/prefix",
262+
)
276263

277-
assert len(responses_mock.calls) == 1
278-
assert responses_mock.calls[0].request.url == (
279-
"http://example.com/prefix/targets"
280-
)
264+
with pytest.raises(requests.exceptions.ConnectionError):
265+
vws_client.list_targets()
281266

282267

283268
class TestListTargets:

0 commit comments

Comments
 (0)