Skip to content

Commit 2fb0c9c

Browse files
Merge pull request #802 from adamtheturtle/target-record
Change `get` function to get just a record
2 parents 70cfa1f + a43d243 commit 2fb0c9c

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

src/vws/vws.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import io
77
import json
88
from time import sleep
9-
from typing import Any, Dict, List, Union
9+
from typing import Dict, List, Union
1010
from urllib.parse import urljoin
1111

1212
import requests
@@ -105,6 +105,9 @@ def add_target(
105105
"""
106106
Add a target to a Vuforia Web Services database.
107107
108+
See
109+
https://library.vuforia.com/articles/Solution/How-To-Use-the-Vuforia-Web-Services-API#How-To-Add-a-Target.
110+
108111
Args:
109112
name: The name of the target.
110113
width: The width of the target.
@@ -137,9 +140,12 @@ def add_target(
137140

138141
return str(response.json()['target_id'])
139142

140-
def get_target(self, target_id: str) -> Dict[str, Any]:
143+
def get_target_record(self, target_id: str) -> Dict[str, Union[str, int]]:
141144
"""
142-
Get details of a given target.
145+
Get a given target's target record from the Target Management System.
146+
147+
See
148+
https://library.vuforia.com/articles/Solution/How-To-Use-the-Vuforia-Web-Services-API#How-To-Add-a-Target.
143149
144150
Args:
145151
target_id: The ID of the target to get details of.
@@ -156,7 +162,7 @@ def get_target(self, target_id: str) -> Dict[str, Any]:
156162
base_vws_url=self._base_vws_url,
157163
)
158164

159-
return dict(response.json())
165+
return dict(response.json()['target_record'])
160166

161167
@timeout_decorator.timeout(seconds=60 * 5)
162168
def wait_for_target_processed(self, target_id: str) -> None:
@@ -172,15 +178,20 @@ def wait_for_target_processed(self, target_id: str) -> None:
172178
than five minutes.
173179
"""
174180
while True:
175-
target_details = self.get_target(target_id=target_id)
176-
if target_details['status'] != 'processing':
181+
report = self.get_target_summary_report(target_id=target_id)
182+
if report['status'] != 'processing':
177183
return
178184

179185
# We wait 0.2 seconds rather than less than that to decrease the
180186
# number of calls made to the API, to decrease the likelihood of
181187
# hitting the request quota.
182188
sleep(0.2)
183189

190+
# We wait 0.2 seconds rather than less than that to decrease the
191+
# number of calls made to the API, to decrease the likelihood of
192+
# hitting the request quota.
193+
sleep(0.2)
194+
184195
def list_targets(self) -> List[str]:
185196
"""
186197
List target IDs.

tests/test_add_target.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ def test_add_target(
3030
width=width,
3131
image=high_quality_image,
3232
)
33-
get_result = client.get_target(target_id=target_id)
34-
target_record = get_result['target_record']
33+
target_record = client.get_target_record(target_id=target_id)
3534
assert target_record['name'] == name
3635
assert target_record['width'] == width
3736
assert target_record['active_flag'] is True
@@ -91,8 +90,7 @@ def test_default(
9190
width=1,
9291
image=high_quality_image,
9392
)
94-
get_result = client.get_target(target_id=target_id)
95-
target_record = get_result['target_record']
93+
target_record = client.get_target_record(target_id=target_id)
9694
assert target_record['active_flag'] is True
9795

9896
@pytest.mark.parametrize('active_flag', [True, False])
@@ -111,7 +109,5 @@ def test_given(
111109
image=high_quality_image,
112110
active_flag=active_flag,
113111
)
114-
115-
get_result = client.get_target(target_id=target_id)
116-
target_record = get_result['target_record']
112+
target_record = client.get_target_record(target_id=target_id)
117113
assert target_record['active_flag'] is active_flag
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Tests for helper function for getting details of a target from a Vuforia
2+
Tests for helper function for getting a record of a target from a Vuforia
33
database.
44
"""
55

@@ -8,33 +8,26 @@
88
from vws import VWS
99

1010

11-
class TestGetTarget:
11+
class TestGetTargetRecord:
1212
"""
13-
Tests for getting details of a target.
13+
Tests for getting a record of a target.
1414
"""
1515

16-
def test_get_target(
16+
def test_get_target_record(
1717
self,
1818
client: VWS,
1919
high_quality_image: io.BytesIO,
2020
) -> None:
2121
"""
22-
Details of a target are returned by ``get_target``.
22+
Details of a target are returned by ``get_target_record``.
2323
"""
2424
target_id = client.add_target(
2525
name='x',
2626
width=1,
2727
image=high_quality_image,
2828
)
2929

30-
result = client.get_target(target_id=target_id)
31-
expected_keys = {
32-
'result_code',
33-
'transaction_id',
34-
'target_record',
35-
'status',
36-
}
37-
assert result.keys() == expected_keys
30+
result = client.get_target_record(target_id=target_id)
3831

3932
expected_keys = {
4033
'target_id',
@@ -44,4 +37,4 @@ def test_get_target(
4437
'tracking_rating',
4538
'reco_rating',
4639
}
47-
assert result['target_record'].keys() == expected_keys
40+
assert result.keys() == expected_keys

tests/test_wait_for_target_processed.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def test_wait_for_target_processed(
2525
width=1,
2626
image=high_quality_image,
2727
)
28-
target_details = client.get_target(target_id=target_id)
29-
assert target_details['status'] == 'processing'
28+
report = client.get_target_summary_report(target_id=target_id)
29+
assert report['status'] == 'processing'
3030
client.wait_for_target_processed(target_id=target_id)
31-
target_details = client.get_target(target_id=target_id)
32-
assert target_details['status'] != 'processing'
31+
report = client.get_target_summary_report(target_id=target_id)
32+
assert report['status'] != 'processing'

0 commit comments

Comments
 (0)