File tree Expand file tree Collapse file tree 4 files changed +45
-24
lines changed
Expand file tree Collapse file tree 4 files changed +45
-24
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 BadImage (Exception ):
24+ """
25+ Exception raised when Vuforia returns a response with a result code
26+ 'BadImage'.
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 TargetStatusProcessing (Exception ):
2439 """
2540 Exception raised when Vuforia returns a response with a result code
Original file line number Diff line number Diff line change 1515
1616from vws ._authorization import authorization_header , rfc_1123_date
1717from vws .exceptions import (
18+ BadImage ,
1819 ImageTooLarge ,
1920 MetadataTooLarge ,
2021 TargetNameExist ,
@@ -99,6 +100,7 @@ def _raise_for_result_code(
99100 return
100101
101102 exception = {
103+ 'BadImage' : BadImage ,
102104 'ImageTooLarge' : ImageTooLarge ,
103105 'MetadataTooLarge' : MetadataTooLarge ,
104106 'TargetNameExist' : TargetNameExist ,
Original file line number Diff line number Diff line change 66
77import pytest
88from mock_vws import MockVWS
9- from requests import codes
109
1110from vws import VWS
12- from vws .exceptions import TargetNameExist
1311
1412
1513class TestSuccess :
@@ -51,28 +49,6 @@ def test_add_two_targets(
5149 client .add_target (name = 'a' , width = 1 , image = high_quality_image )
5250
5351
54- class TestName :
55- """
56- Tests for the ``name`` parameter to ``add_target``.
57- """
58-
59- def test_add_two_targets_same_name (
60- self ,
61- client : VWS ,
62- high_quality_image : io .BytesIO ,
63- ) -> None :
64- """
65- A ``TargetNameExist`` exception is raised after adding two targets with
66- the same name.
67- """
68- client .add_target (name = 'x' , width = 1 , image = high_quality_image )
69-
70- with pytest .raises (TargetNameExist ) as exc :
71- client .add_target (name = 'x' , width = 1 , image = high_quality_image )
72-
73- assert exc .value .response .status_code == codes .FORBIDDEN
74-
75-
7652class TestCustomBaseURL :
7753 """
7854 Tests for adding images to databases under custom VWS URLs.
Original file line number Diff line number Diff line change 1111
1212from vws import VWS
1313from vws .exceptions import (
14+ BadImage ,
1415 ImageTooLarge ,
1516 MetadataTooLarge ,
17+ TargetNameExist ,
1618 TargetStatusProcessing ,
1719 UnknownTarget ,
1820)
@@ -88,6 +90,32 @@ def test_request_quota_reached() -> None:
8890 """
8991
9092
93+ def test_bad_image (client : VWS ) -> None :
94+ """
95+ A ``BadImage`` exception is raised when a non-image is given.
96+ """
97+ not_an_image = io .BytesIO (b'Not an image' )
98+ with pytest .raises (BadImage ) as exc :
99+ client .add_target (name = 'x' , width = 1 , image = not_an_image )
100+
101+ assert exc .value .response .status_code == codes .UNPROCESSABLE_ENTITY
102+
103+
104+ def test_target_name_exist (
105+ client : VWS ,
106+ high_quality_image : io .BytesIO ,
107+ ) -> None :
108+ """
109+ A ``TargetNameExist`` exception is raised after adding two targets with
110+ the same name.
111+ """
112+ client .add_target (name = 'x' , width = 1 , image = high_quality_image )
113+ with pytest .raises (TargetNameExist ) as exc :
114+ client .add_target (name = 'x' , width = 1 , image = high_quality_image )
115+
116+ assert exc .value .response .status_code == codes .FORBIDDEN
117+
118+
91119def test_target_status_processing (
92120 client : VWS ,
93121 high_quality_image : io .BytesIO ,
You can’t perform that action at this time.
0 commit comments