Skip to content

Commit b0c7ea9

Browse files
Merge pull request #816 from adamtheturtle/test-delete
Add tests for delete
2 parents c824fd9 + 75bf5c3 commit b0c7ea9

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

src/vws/exceptions.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,18 @@ def __init__(self, response: Response) -> None:
1818
"""
1919
super().__init__()
2020
self.response = response
21+
22+
23+
class TargetStatusProcessing(Exception):
24+
"""
25+
Exception raised when Vuforia returns a response with a result code
26+
'TargetStatusProcessing'.
27+
"""
28+
29+
def __init__(self, response: Response) -> None:
30+
"""
31+
Args:
32+
response: The response to a request to Vuforia.
33+
"""
34+
super().__init__()
35+
self.response = response

src/vws/vws.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from requests import Response
1616

1717
from vws._authorization import authorization_header, rfc_1123_date
18-
from vws.exceptions import UnknownTarget
18+
from vws.exceptions import TargetStatusProcessing, UnknownTarget
1919

2020

2121
def _target_api_request(
@@ -106,6 +106,7 @@ class _ResultCodes(Enum):
106106

107107
_EXCEPTIONS = {
108108
_ResultCodes.UNKNOWN_TARGET: UnknownTarget,
109+
_ResultCodes.TARGET_STATUS_PROCESSING: TargetStatusProcessing,
109110
}
110111

111112

@@ -302,9 +303,9 @@ def delete_target(self, target_id: str) -> None:
302303
response = _target_api_request(
303304
server_access_key=self._server_access_key,
304305
server_secret_key=self._server_secret_key,
305-
method='GET',
306+
method='DELETE',
306307
content=b'',
307-
request_path=f'/summary/{target_id}',
308+
request_path=f'/targets/{target_id}',
308309
base_vws_url=self._base_vws_url,
309310
)
310311

tests/test_delete_target.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,45 @@
44

55
import io
66

7+
import pytest
8+
from requests import codes
9+
710
from vws import VWS
11+
from vws.exceptions import TargetStatusProcessing, UnknownTarget
812

913

1014
class TestDelete:
1115
"""
1216
Test for deleting a target.
1317
"""
1418

19+
def test_target_processing(
20+
self,
21+
client: VWS,
22+
high_quality_image: io.BytesIO,
23+
) -> None:
24+
"""
25+
A ``TargetStatusProcessing`` exception is raised if trying to delete a
26+
target which is processing.
27+
"""
28+
target_id = client.add_target(
29+
name='x',
30+
width=1,
31+
image=high_quality_image,
32+
)
33+
34+
with pytest.raises(TargetStatusProcessing) as exc:
35+
client.delete_target(target_id=target_id)
36+
37+
assert exc.value.response.status_code == codes.FORBIDDEN
38+
1539
def test_delete_target(
1640
self,
1741
client: VWS,
1842
high_quality_image: io.BytesIO,
1943
) -> None:
2044
"""
21-
it is possible to delete a target.
45+
It is possible to delete a target.
2246
"""
2347
target_id = client.add_target(
2448
name='x',
@@ -28,3 +52,5 @@ def test_delete_target(
2852

2953
client.wait_for_target_processed(target_id=target_id)
3054
client.delete_target(target_id=target_id)
55+
with pytest.raises(UnknownTarget):
56+
client.get_target_record(target_id=target_id)

0 commit comments

Comments
 (0)