Skip to content

Commit 37040b4

Browse files
committed
Separate 'ProjectInactive' and 'InactiveProject' exceptions
1 parent fb9fe46 commit 37040b4

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

src/vws/_result_codes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from requests import Response
88

99
from vws.exceptions.custom_exceptions import UnknownVWSErrorPossiblyBadName
10+
from vws.exceptions.cloud_reco_exceptions import InactiveProject
1011
from vws.exceptions.vws_exceptions import (
1112
AuthenticationFailure,
1213
BadImage,
@@ -60,7 +61,7 @@ def raise_for_result_code(
6061
'DateRangeError': DateRangeError,
6162
'Fail': Fail,
6263
'ImageTooLarge': ImageTooLarge,
63-
'InactiveProject': ProjectInactive,
64+
'InactiveProject': InactiveProject,
6465
'MetadataTooLarge': MetadataTooLarge,
6566
'ProjectHasNoAPIAccess': ProjectHasNoAPIAccess,
6667
'ProjectInactive': ProjectInactive,

src/vws/exceptions/cloud_reco_exceptions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,10 @@ class MaxNumResultsOutOfRange(CloudRecoException):
1818
Exception raised when the ``max_num_results`` given to the Cloud
1919
Recognition Web API query endpoint is out of range.
2020
"""
21+
22+
23+
class InactiveProject(CloudRecoException):
24+
"""
25+
Exception raised when Vuforia returns a response with a result code
26+
'InactiveProject'.
27+
"""

src/vws/exceptions/vws_exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class ProjectHasNoAPIAccess(VWSException): # pragma: no cover
108108
class ProjectInactive(VWSException):
109109
"""
110110
Exception raised when Vuforia returns a response with a result code
111-
'ProjectInactive' or 'InactiveProject'.
111+
'ProjectInactive'.
112112
"""
113113

114114

src/vws/query.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ def query(
7676
~vws.exceptions.cloud_reco_exceptions.MatchProcessing: The given
7777
image matches a target which was recently added, updated or
7878
deleted and Vuforia returns an error in this case.
79-
~vws.exceptions.vws_exceptions.ProjectInactive: The project is
80-
inactive.
79+
~vws.exceptions.cloud_reco_exceptions.InactiveProject: The project
80+
is inactive.
8181
~vws.exceptions.custom_exceptions.ConnectionErrorPossiblyImageTooLarge:
8282
The given image is too large.
8383
~vws.exceptions.vws_exceptions.RequestTimeTooSkewed: There is an

tests/test_exceptions.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from vws import VWS, CloudRecoService
1515
from vws.exceptions.base_exceptions import CloudRecoException, VWSException
1616
from vws.exceptions.cloud_reco_exceptions import (
17+
InactiveProject,
1718
MatchProcessing,
1819
MaxNumResultsOutOfRange,
1920
)
@@ -161,10 +162,7 @@ def test_target_name_exist(
161162
assert exc.value.target_name == 'x'
162163

163164

164-
def test_project_inactive(
165-
vws_client: VWS,
166-
high_quality_image: io.BytesIO,
167-
) -> None:
165+
def test_project_inactive(high_quality_image: io.BytesIO) -> None:
168166
"""
169167
A ``ProjectInactive`` exception is raised if adding a target to an
170168
inactive database.
@@ -193,7 +191,20 @@ def test_project_inactive(
193191

194192
assert exc.value.response.status_code == HTTPStatus.FORBIDDEN
195193

196-
with pytest.raises(ProjectInactive) as exc:
194+
def test_inactive_project(high_quality_image: io.BytesIO) -> None:
195+
"""
196+
An ``InactiveProject`` exception is raised when querying an inactive
197+
database.
198+
"""
199+
database = VuforiaDatabase(state=States.PROJECT_INACTIVE)
200+
with MockVWS() as mock:
201+
mock.add_database(database=database)
202+
cloud_reco_client = CloudRecoService(
203+
client_access_key=database.client_access_key,
204+
client_secret_key=database.client_secret_key,
205+
)
206+
207+
with pytest.raises(InactiveProject) as exc:
197208
cloud_reco_client.query(image=high_quality_image)
198209

199210
assert exc.value.response.status_code == HTTPStatus.FORBIDDEN

0 commit comments

Comments
 (0)