File tree Expand file tree Collapse file tree 3 files changed +42
-3
lines changed
Expand file tree Collapse file tree 3 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -48,3 +48,18 @@ def __init__(self, response: Response) -> None:
4848 """
4949 super ().__init__ ()
5050 self .response = response
51+
52+
53+ class TargetNameExist (Exception ):
54+ """
55+ Exception raised when Vuforia returns a response with a result code
56+ 'TargetNameExist'.
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
Original file line number Diff line number Diff line change 1717from vws ._authorization import authorization_header , rfc_1123_date
1818from vws .exceptions import (
1919 MetadataTooLarge ,
20+ TargetNameExist ,
2021 TargetStatusProcessing ,
2122 UnknownTarget ,
2223)
@@ -109,9 +110,10 @@ class _ResultCodes(Enum):
109110
110111
111112_EXCEPTIONS = {
112- _ResultCodes .UNKNOWN_TARGET : UnknownTarget ,
113- _ResultCodes .TARGET_STATUS_PROCESSING : TargetStatusProcessing ,
114113 _ResultCodes .METADATA_TOO_LARGE : MetadataTooLarge ,
114+ _ResultCodes .TARGET_NAME_EXIST : TargetNameExist ,
115+ _ResultCodes .TARGET_STATUS_PROCESSING : TargetStatusProcessing ,
116+ _ResultCodes .UNKNOWN_TARGET : UnknownTarget ,
115117}
116118
117119
Original file line number Diff line number Diff line change 99from requests import codes
1010
1111from vws import VWS
12- from vws .exceptions import MetadataTooLarge
12+ from vws .exceptions import MetadataTooLarge , TargetNameExist
1313
1414
1515class TestSuccess :
@@ -51,6 +51,28 @@ def test_add_two_targets(
5151 client .add_target (name = 'a' , width = 1 , image = high_quality_image )
5252
5353
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+
5476class TestCustomBaseURL :
5577 """
5678 Tests for adding images to databases under custom VWS URLs.
You can’t perform that action at this time.
0 commit comments