Skip to content

Commit f7fd904

Browse files
Merge pull request #797 from adamtheturtle/test-target-list
Add function for listing targets
2 parents 719c1d6 + aa5fd16 commit f7fd904

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/vws/vws.py

Lines changed: 19 additions & 1 deletion
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, Union
9+
from typing import Any, Dict, List, Union
1010
from urllib.parse import urljoin
1111

1212
import requests
@@ -179,3 +179,21 @@ def wait_for_target_processed(self, target_id: str) -> None:
179179
# number of calls made to the API, to decrease the likelihood of
180180
# hitting the request quota.
181181
sleep(0.2)
182+
183+
def list_targets(self) -> List[str]:
184+
"""
185+
Get a list of targets.
186+
187+
Returns:
188+
The IDs of all targets in the database.
189+
"""
190+
response = _target_api_request(
191+
server_access_key=self._server_access_key,
192+
server_secret_key=self._server_secret_key,
193+
method='GET',
194+
content=b'',
195+
request_path='/targets',
196+
base_vws_url=self._base_vws_url,
197+
)
198+
199+
return list(response.json()['results'])

tests/test_target_list.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
Tests for helper function for getting a list of targets.
3+
"""
4+
5+
import io
6+
7+
from vws import VWS
8+
9+
10+
class TestListTargets:
11+
"""
12+
Test for listing targets.
13+
"""
14+
15+
def test_list_targets(
16+
self,
17+
client: VWS,
18+
high_quality_image: io.BytesIO,
19+
) -> None:
20+
"""
21+
It is possible to get a list of target IDs.
22+
"""
23+
id_1 = client.add_target(name='x', width=1, image=high_quality_image)
24+
id_2 = client.add_target(name='a', width=1, image=high_quality_image)
25+
assert sorted(client.list_targets()) == sorted([id_1, id_2])

0 commit comments

Comments
 (0)