File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed
Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff 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+
2338class BadImage (Exception ):
2439 """
2540 Exception raised when Vuforia returns a response with a result code
Original file line number Diff line number Diff line change 1616from vws ._authorization import authorization_header , rfc_1123_date
1717from 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 ,
Original file line number Diff line number Diff line change 66import random
77
88import pytest
9+ from mock_vws import MockVWS
910from PIL import Image
1011from requests import codes
1112
1213from vws import VWS
1314from 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+
93115def test_bad_image (client : VWS ) -> None :
94116 """
95117 A ``BadImage`` exception is raised when a non-image is given.
You can’t perform that action at this time.
0 commit comments