Skip to content

Commit 3d0f29b

Browse files
committed
Merge remote-tracking branch 'origin/master' into delete-document-errors
2 parents 02efa2f + 1450d05 commit 3d0f29b

File tree

2 files changed

+101
-10
lines changed

2 files changed

+101
-10
lines changed

src/vws/vws.py

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ def add_target(
190190
Add a target to a Vuforia Web Services database.
191191
192192
See
193-
https://library.vuforia.com/articles/Solution/How-To-Use-the-Vuforia-Web-Services-API#How-To-Add-a-Target.
193+
https://library.vuforia.com/articles/Solution/How-To-Use-the-Vuforia-Web-Services-API#How-To-Add-a-Target
194+
for parameter details.
194195
195196
Args:
196197
name: The name of the target.
@@ -275,14 +276,18 @@ def get_target_record(self, target_id: str) -> Dict[str, Union[str, int]]:
275276

276277
return dict(response.json()['target_record'])
277278

278-
@timeout_decorator.timeout(seconds=60 * 5)
279-
def wait_for_target_processed(self, target_id: str) -> None:
279+
def _wait_for_target_processed(
280+
self,
281+
target_id: str,
282+
seconds_between_requests: float,
283+
) -> None:
280284
"""
281-
Wait up to five minutes (arbitrary) for a target to get past the
282-
processing stage.
285+
Wait indefinitely for a target to get past the processing stage.
283286
284287
Args:
285288
target_id: The ID of the target to wait for.
289+
seconds_between_requests: The number of seconds to wait between
290+
requests made while polling the target status.
286291
287292
Raises:
288293
~vws.exceptions.AuthenticationFailure: The secret key is not
@@ -299,10 +304,35 @@ def wait_for_target_processed(self, target_id: str) -> None:
299304
if report['status'] != 'processing':
300305
return
301306

302-
# We wait 0.2 seconds rather than less than that to decrease the
303-
# number of calls made to the API, to decrease the likelihood of
304-
# hitting the request quota.
305-
sleep(0.2)
307+
sleep(seconds_between_requests)
308+
309+
@timeout_decorator.timeout(seconds=60 * 5)
310+
def wait_for_target_processed(self, target_id: str) -> None:
311+
"""
312+
Wait up to five minutes (arbitrary) for a target to get past the
313+
processing stage.
314+
315+
Args:
316+
target_id: The ID of the target to wait for.
317+
318+
Raises:
319+
~vws.exceptions.AuthenticationFailure: The secret key is not
320+
correct.
321+
~vws.exceptions.Fail: There was an error with the request. For
322+
example, the given access key does not match a known database.
323+
TimeoutError: The target remained in the processing stage for more
324+
than five minutes.
325+
~vws.exceptions.UnknownTarget: The given target ID does not match a
326+
target in the database.
327+
"""
328+
# We wait 0.2 seconds rather than less than that to decrease the
329+
# number of calls made to the API, to decrease the likelihood of
330+
# hitting the request quota.
331+
seconds_between_requests = 0.2
332+
self._wait_for_target_processed(
333+
target_id=target_id,
334+
seconds_between_requests=seconds_between_requests,
335+
)
306336

307337
def list_targets(self) -> List[str]:
308338
"""
@@ -413,3 +443,34 @@ def delete_target(self, target_id: str) -> None:
413443
request_path=f'/targets/{target_id}',
414444
expected_result_code='Success',
415445
)
446+
447+
def get_duplicate_targets(self, target_id: str) -> List[str]:
448+
"""
449+
Get targets which may be considered duplicates of a given target.
450+
451+
See
452+
https://library.vuforia.com/articles/Solution/How-To-Use-the-Vuforia-Web-Services-API.html#How-To-Check-for-Duplicate-Targets.
453+
454+
Args:
455+
target_id: The ID of the target to delete.
456+
457+
Returns:
458+
The target IDs of duplicate targets.
459+
460+
Raises:
461+
~vws.exceptions.AuthenticationFailure: The secret key is not
462+
correct.
463+
~vws.exceptions.Fail: There was an error with the request. For
464+
example, the given access key does not match a known database.
465+
~vws.exceptions.UnknownTarget: The given target ID does not match a
466+
target in the database.
467+
~vws.exceptions.ProjectInactive: The project is inactive.
468+
"""
469+
response = self._make_request(
470+
method='GET',
471+
content=b'',
472+
request_path=f'/duplicates/{target_id}',
473+
expected_result_code='Success',
474+
)
475+
476+
return list(response.json()['similar_targets'])

tests/test_vws.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Tests for helper function for adding a target to a Vuforia database.
2+
Tests for helper functions for managing a Vuforia database.
33
"""
44

55
import io
@@ -278,3 +278,33 @@ def test_wait_for_target_processed(
278278
client.wait_for_target_processed(target_id=target_id)
279279
report = client.get_target_summary_report(target_id=target_id)
280280
assert report['status'] != 'processing'
281+
282+
283+
class TestGetDuplicateTargets:
284+
"""
285+
Tests for getting duplicate targets.
286+
"""
287+
288+
def test_get_duplicate_targets(
289+
self,
290+
client: VWS,
291+
high_quality_image: io.BytesIO,
292+
) -> None:
293+
"""
294+
It is possible to get the IDs of similar targets.
295+
"""
296+
target_id = client.add_target(
297+
name='x',
298+
width=1,
299+
image=high_quality_image,
300+
)
301+
similar_target_id = client.add_target(
302+
name='a',
303+
width=1,
304+
image=high_quality_image,
305+
)
306+
307+
client.wait_for_target_processed(target_id=target_id)
308+
client.wait_for_target_processed(target_id=similar_target_id)
309+
duplicates = client.get_duplicate_targets(target_id=target_id)
310+
assert duplicates == [similar_target_id]

0 commit comments

Comments
 (0)