Skip to content

Commit 9bf4add

Browse files
Merge pull request #889 from adamtheturtle/get-duplicates
Get duplicates
2 parents 990613d + 15e1420 commit 9bf4add

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

src/vws/vws.py

Lines changed: 33 additions & 1 deletion
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.
@@ -411,3 +412,34 @@ def delete_target(self, target_id: str) -> None:
411412
request_path=f'/targets/{target_id}',
412413
expected_result_code='Success',
413414
)
415+
416+
def get_duplicate_targets(self, target_id: str) -> List[str]:
417+
"""
418+
Get targets which may be considered duplicates of a given target.
419+
420+
See
421+
https://library.vuforia.com/articles/Solution/How-To-Use-the-Vuforia-Web-Services-API.html#How-To-Check-for-Duplicate-Targets.
422+
423+
Args:
424+
target_id: The ID of the target to delete.
425+
426+
Returns:
427+
The target IDs of duplicate targets.
428+
429+
Raises:
430+
~vws.exceptions.AuthenticationFailure: The secret key is not
431+
correct.
432+
~vws.exceptions.Fail: There was an error with the request. For
433+
example, the given access key does not match a known database.
434+
~vws.exceptions.UnknownTarget: The given target ID does not match a
435+
target in the database.
436+
~vws.exceptions.ProjectInactive: The project is inactive.
437+
"""
438+
response = self._make_request(
439+
method='GET',
440+
content=b'',
441+
request_path=f'/duplicates/{target_id}',
442+
expected_result_code='Success',
443+
)
444+
445+
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)