Skip to content

Commit 545e91d

Browse files
Merge pull request #2867 from VWS-Python/adamtheturtle/fix-duplicate-fixture
Replace urljoin with string concatenation for base URL construction
2 parents 4a497c2 + 13a0047 commit 545e91d

5 files changed

Lines changed: 54 additions & 6 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ optional-dependencies.dev = [
8282
"ty==0.0.17",
8383
"types-requests==2.32.4.20260107",
8484
"vulture==2.14",
85-
"vws-python-mock==2026.2.21",
85+
"vws-python-mock==2026.2.22.2",
8686
"vws-test-fixtures==2023.3.5",
8787
"yamlfix==1.19.1",
8888
"zizmor==1.22.0",

src/vws/_vws_request.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
API.
33
"""
44

5-
from urllib.parse import urljoin
6-
75
import requests
86
from beartype import BeartypeConf, beartype
97
from vws_auth_tools import authorization_header, rfc_1123_date
@@ -64,7 +62,7 @@ def target_api_request(
6462
**extra_headers,
6563
}
6664

67-
url = urljoin(base=base_vws_url, url=request_path)
65+
url = base_vws_url.rstrip("/") + request_path
6866

6967
requests_response = requests.request(
7068
method=method,

src/vws/query.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import json
66
from http import HTTPMethod, HTTPStatus
77
from typing import Any, BinaryIO
8-
from urllib.parse import urljoin
98

109
import requests
1110
from beartype import BeartypeConf, beartype
@@ -146,7 +145,7 @@ def query(
146145

147146
requests_response = requests.request(
148147
method=method,
149-
url=urljoin(base=self._base_vwq_url, url=request_path),
148+
url=self._base_vwq_url.rstrip("/") + request_path,
150149
headers=headers,
151150
data=content,
152151
timeout=self._request_timeout_seconds,

tests/test_query.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,39 @@ def test_custom_base_url(image: io.BytesIO | BinaryIO) -> None:
190190
match = matches[0]
191191
assert match.target_id == target_id
192192

193+
@staticmethod
194+
def test_custom_base_url_with_path_prefix(
195+
image: io.BytesIO | BinaryIO,
196+
) -> None:
197+
"""
198+
A base VWQ URL with a path prefix is used as-is, without the
199+
prefix being dropped.
200+
"""
201+
base_vwq_url = "http://example.com/prefix"
202+
with MockVWS(base_vwq_url=base_vwq_url) as mock:
203+
database = CloudDatabase()
204+
mock.add_cloud_database(cloud_database=database)
205+
vws_client = VWS(
206+
server_access_key=database.server_access_key,
207+
server_secret_key=database.server_secret_key,
208+
)
209+
target_id = vws_client.add_target(
210+
name="x",
211+
width=1,
212+
image=image,
213+
active_flag=True,
214+
application_metadata=None,
215+
)
216+
vws_client.wait_for_target_processed(target_id=target_id)
217+
cloud_reco_client = CloudRecoService(
218+
client_access_key=database.client_access_key,
219+
client_secret_key=database.client_secret_key,
220+
base_vwq_url=base_vwq_url,
221+
)
222+
223+
matches = cloud_reco_client.query(image=image)
224+
assert len(matches) == 1
225+
193226

194227
class TestMaxNumResults:
195228
"""Tests for the ``max_num_results`` parameter of ``query``."""

tests/test_vws.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,24 @@ def test_custom_base_url(image: io.BytesIO | BinaryIO) -> None:
246246
application_metadata=None,
247247
)
248248

249+
@staticmethod
250+
def test_custom_base_url_with_path_prefix() -> None:
251+
"""
252+
A base VWS URL with a path prefix is used as-is, without the
253+
prefix being dropped.
254+
"""
255+
base_vws_url = "http://example.com/prefix"
256+
with MockVWS(base_vws_url=base_vws_url) as mock:
257+
database = CloudDatabase()
258+
mock.add_cloud_database(cloud_database=database)
259+
vws_client = VWS(
260+
server_access_key=database.server_access_key,
261+
server_secret_key=database.server_secret_key,
262+
base_vws_url=base_vws_url,
263+
)
264+
265+
assert not vws_client.list_targets()
266+
249267

250268
class TestListTargets:
251269
"""Tests for listing targets."""

0 commit comments

Comments
 (0)