Skip to content

Commit 04f62d4

Browse files
committed
Passing delete tests
1 parent c824fd9 commit 04f62d4

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,44 @@
44

55
import io
66

7-
from vws import VWS
7+
import pytest
8+
from requests import codes
89

10+
from vws import VWS
11+
from vws.exceptions import TargetStatusProcessing, UnknownTarget
912

1013
class TestDelete:
1114
"""
1215
Test for deleting a target.
1316
"""
1417

18+
def test_target_processing(
19+
self,
20+
client: VWS,
21+
high_quality_image: io.BytesIO,
22+
) -> None:
23+
"""
24+
A ``TargetStatusProcessing`` exception is raised if trying to delete a
25+
target which is processing.
26+
"""
27+
target_id = client.add_target(
28+
name='x',
29+
width=1,
30+
image=high_quality_image,
31+
)
32+
33+
with pytest.raises(TargetStatusProcessing) as exc:
34+
client.delete_target(target_id=target_id)
35+
36+
assert exc.value.response.status_code == codes.FORBIDDEN
37+
1538
def test_delete_target(
1639
self,
1740
client: VWS,
1841
high_quality_image: io.BytesIO,
1942
) -> None:
2043
"""
21-
it is possible to delete a target.
44+
It is possible to delete a target.
2245
"""
2346
target_id = client.add_target(
2447
name='x',
@@ -28,3 +51,5 @@ def test_delete_target(
2851

2952
client.wait_for_target_processed(target_id=target_id)
3053
client.delete_target(target_id=target_id)
54+
with pytest.raises(UnknownTarget):
55+
client.get_target_record(target_id=target_id)

0 commit comments

Comments
 (0)