Skip to content

Commit 28b9253

Browse files
Merge pull request #1107 from adamtheturtle/capture-target-id
Add target ID property to UnknownTarget exception
2 parents ee22718 + dc8081b commit 28b9253

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/vws/exceptions.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Custom exceptions for Vuforia errors.
33
"""
4+
from urllib.parse import urlparse
45

56
import requests
67
from requests import Response
@@ -89,6 +90,16 @@ def response(self) -> Response:
8990
"""
9091
return self._response
9192

93+
@property
94+
def target_id(self) -> str:
95+
"""
96+
The unknown target ID.
97+
"""
98+
path = urlparse(self.response.url).path
99+
# Every HTTP path which can raise this error is in the format
100+
# `/something/{target_id}`.
101+
return path.split(sep='/', maxsplit=2)[-1]
102+
92103

93104
class Fail(Exception):
94105
"""

tests/test_exceptions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ def test_image_too_large(
4949
assert exc.value.response.status_code == codes.UNPROCESSABLE_ENTITY
5050

5151

52-
def test_invalid_given_id(vws_client: VWS) -> None:
52+
@pytest.mark.parametrize('target_id', ['x', 'x/1'])
53+
def test_invalid_given_id(vws_client: VWS, target_id: str) -> None:
5354
"""
5455
Giving an invalid ID to a helper which requires a target ID to be given
5556
causes an ``UnknownTarget`` exception to be raised.
5657
"""
5758
with pytest.raises(UnknownTarget) as exc:
58-
vws_client.delete_target(target_id='x')
59+
vws_client.delete_target(target_id=target_id)
5960
assert exc.value.response.status_code == codes.NOT_FOUND
61+
assert exc.value.target_id == target_id
6062

6163

6264
def test_add_bad_name(vws_client: VWS, high_quality_image: io.BytesIO) -> None:

0 commit comments

Comments
 (0)