Skip to content

Commit 51c5ae7

Browse files
Merge pull request #833 from adamtheturtle/a-few-more-exceptions
Add a few more exception tests
2 parents 5fe99ff + d4b4771 commit 51c5ae7

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

src/vws/exceptions.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ def __init__(self, response: Response) -> None:
2020
self.response = response
2121

2222

23+
class Fail(Exception):
24+
"""
25+
Exception raised when Vuforia returns a response with a result code
26+
'Fail'.
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
36+
37+
2338
class BadImage(Exception):
2439
"""
2540
Exception raised when Vuforia returns a response with a result code

src/vws/vws.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from vws._authorization import authorization_header, rfc_1123_date
1717
from vws.exceptions import (
1818
BadImage,
19+
Fail,
1920
ImageTooLarge,
2021
MetadataTooLarge,
2122
TargetNameExist,
@@ -101,6 +102,7 @@ def _raise_for_result_code(
101102

102103
exception = {
103104
'BadImage': BadImage,
105+
'Fail': Fail,
104106
'ImageTooLarge': ImageTooLarge,
105107
'MetadataTooLarge': MetadataTooLarge,
106108
'TargetNameExist': TargetNameExist,

tests/test_exceptions.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
import random
77

88
import pytest
9+
from mock_vws import MockVWS
910
from PIL import Image
1011
from requests import codes
1112

1213
from vws import VWS
1314
from vws.exceptions import (
1415
BadImage,
16+
Fail,
1517
ImageTooLarge,
1618
MetadataTooLarge,
1719
TargetNameExist,
@@ -90,6 +92,26 @@ def test_request_quota_reached() -> None:
9092
"""
9193

9294

95+
def test_fail(high_quality_image: io.BytesIO) -> None:
96+
"""
97+
A ``Fail`` exception is raised when there are authentication issues.
98+
"""
99+
with MockVWS() as mock:
100+
client = VWS(
101+
server_access_key='a',
102+
server_secret_key=mock.server_secret_key,
103+
)
104+
105+
with pytest.raises(Fail) as exc:
106+
client.add_target(
107+
name='x',
108+
width=1,
109+
image=high_quality_image,
110+
)
111+
112+
assert exc.value.response.status_code == codes.BAD_REQUEST
113+
114+
93115
def test_bad_image(client: VWS) -> None:
94116
"""
95117
A ``BadImage`` exception is raised when a non-image is given.

0 commit comments

Comments
 (0)