Skip to content

Commit ec6655a

Browse files
Merge pull request #851 from adamtheturtle/auth-failure
Add AuthFailure exception
2 parents 6dd5277 + c4dedbe commit ec6655a

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

dev-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PyYAML==3.13
22
Pygments==2.2.0
3-
VWS-Python-Mock==2018.10.01.1
3+
VWS-Python-Mock==2018.10.02.0
44
autoflake==1.2
55
check-manifest==0.37
66
codecov==2.0.15 # Upload coverage data

src/vws/exceptions.py

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

5252

53+
class AuthenticationFailure(Exception):
54+
"""
55+
Exception raised when Vuforia returns a response with a result code
56+
'AuthenticationFailure'.
57+
"""
58+
59+
def __init__(self, response: Response) -> None:
60+
"""
61+
Args:
62+
response: The response to a request to Vuforia.
63+
"""
64+
super().__init__()
65+
self.response = response
66+
67+
5368
class TargetStatusProcessing(Exception):
5469
"""
5570
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
@@ -15,6 +15,7 @@
1515

1616
from vws._authorization import authorization_header, rfc_1123_date
1717
from vws.exceptions import (
18+
AuthenticationFailure,
1819
BadImage,
1920
Fail,
2021
ImageTooLarge,
@@ -102,6 +103,7 @@ def _raise_for_result_code(
102103
return
103104

104105
exception = {
106+
'AuthenticationFailure': AuthenticationFailure,
105107
'BadImage': BadImage,
106108
'Fail': Fail,
107109
'ImageTooLarge': ImageTooLarge,

tests/test_exceptions.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from vws import VWS
1616
from vws.exceptions import (
17+
AuthenticationFailure,
1718
BadImage,
1819
Fail,
1920
ImageTooLarge,
@@ -97,7 +98,7 @@ def test_request_quota_reached() -> None:
9798

9899
def test_fail(high_quality_image: io.BytesIO) -> None:
99100
"""
100-
A ``Fail`` exception is raised when there are authentication issues.
101+
A ``Fail`` exception is raised when the server access key does not exist.
101102
"""
102103
with MockVWS():
103104
client = VWS(
@@ -201,3 +202,26 @@ def test_metadata_too_large(
201202
)
202203

203204
assert exc.value.response.status_code == codes.UNPROCESSABLE_ENTITY
205+
206+
207+
def test_authentication_failure(high_quality_image: io.BytesIO) -> None:
208+
"""
209+
An ``AuthenticationFailure`` exception is raised when the server access key
210+
does not exist.
211+
"""
212+
database = VuforiaDatabase()
213+
with MockVWS() as mock:
214+
mock.add_database(database=database)
215+
client = VWS(
216+
server_access_key=database.server_access_key.decode(),
217+
server_secret_key='a',
218+
)
219+
220+
with pytest.raises(AuthenticationFailure) as exc:
221+
client.add_target(
222+
name='x',
223+
width=1,
224+
image=high_quality_image,
225+
)
226+
227+
assert exc.value.response.status_code == codes.UNAUTHORIZED

0 commit comments

Comments
 (0)