Skip to content

Commit 65c497c

Browse files
Merge pull request #1037 from adamtheturtle/vwq-custom
Add custom VWQ URL
2 parents 2fa5401 + d98538c commit 65c497c

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/vws/query.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ def __init__(
2121
self,
2222
client_access_key: str,
2323
client_secret_key: str,
24+
base_vwq_url: str = 'https://cloudreco.vuforia.com',
2425
) -> None:
2526
"""
2627
Args:
2728
client_access_key: A VWS client access key.
2829
client_secret_key: A VWS client secret key.
30+
base_vwq_url: The base URL for the VWQ API.
2931
"""
3032
self._client_access_key = client_access_key.encode()
3133
self._client_secret_key = client_secret_key.encode()
34+
self._base_vwq_url = base_vwq_url
3235

3336
def query(self, image: io.BytesIO) -> List[Dict[str, Any]]:
3437
"""
@@ -70,10 +73,9 @@ def query(self, image: io.BytesIO) -> List[Dict[str, Any]]:
7073
'Content-Type': content_type_header,
7174
}
7275

73-
base_vwq_url = 'https://cloudreco.vuforia.com'
7476
response = requests.request(
7577
method=method,
76-
url=urljoin(base=base_vwq_url, url=request_path),
78+
url=urljoin(base=self._base_vwq_url, url=request_path),
7779
headers=headers,
7880
data=content,
7981
)

tests/test_query.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import io
66
import uuid
77

8+
from mock_vws import MockVWS
9+
from mock_vws.database import VuforiaDatabase
10+
811
from vws import VWS, CloudRecoService
912

1013

@@ -43,6 +46,43 @@ def test_match(
4346
assert matching_target['target_id'] == target_id
4447

4548

49+
class TestCustomBaseVWQURL:
50+
"""
51+
Tests for using a custom base VWQ URL.
52+
"""
53+
54+
def test_custom_base_url(self, high_quality_image: io.BytesIO) -> None:
55+
"""
56+
It is possible to use query a target to a database under a custom VWQ
57+
URL.
58+
"""
59+
base_vwq_url = 'http://example.com'
60+
with MockVWS(base_vwq_url=base_vwq_url) as mock:
61+
database = VuforiaDatabase()
62+
mock.add_database(database=database)
63+
vws_client = VWS(
64+
server_access_key=database.server_access_key,
65+
server_secret_key=database.server_secret_key,
66+
)
67+
68+
target_id = vws_client.add_target(
69+
name='x',
70+
width=1,
71+
image=high_quality_image,
72+
)
73+
74+
vws_client.wait_for_target_processed(target_id=target_id)
75+
76+
cloud_reco_client = CloudRecoService(
77+
client_access_key=database.client_access_key,
78+
client_secret_key=database.client_secret_key,
79+
base_vwq_url=base_vwq_url,
80+
)
81+
82+
[match] = cloud_reco_client.query(image=high_quality_image)
83+
assert match['target_id'] == target_id
84+
85+
4686
class TestMaxNumResults:
4787
"""
4888
Tests for the ``max_num_results`` parameter of ``query``.

0 commit comments

Comments
 (0)