Skip to content

Commit eb9bee1

Browse files
committed
Replace outdated MatchProcessing exception with new ActiveMatchingTargetsDeleteProcessing exception
1 parent c1bc296 commit eb9bee1

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

src/vws/exceptions/cloud_reco_exceptions.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
from vws.exceptions.base_exceptions import CloudRecoException
77

88

9-
class MatchProcessing(CloudRecoException):
10-
"""
11-
Exception raised when a query is made with an image which matches a target
12-
which is processing or has recently been deleted.
13-
"""
14-
15-
169
class MaxNumResultsOutOfRange(CloudRecoException):
1710
"""
1811
Exception raised when the ``max_num_results`` given to the Cloud

src/vws/exceptions/custom_exceptions.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
or simple errors given by the cloud recognition service.
55
"""
66

7-
import requests
8-
97

108
class UnknownVWSErrorPossiblyBadName(Exception):
119
"""
@@ -26,3 +24,10 @@ class TargetProcessingTimeout(Exception):
2624
"""
2725
Exception raised when waiting for a target to be processed times out.
2826
"""
27+
28+
29+
class ActiveMatchingTargetsDeleteProcessing(Exception):
30+
"""
31+
Exception raised when a query is made with an image which matches a target
32+
which has recently been deleted.
33+
"""

src/vws/query.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from __future__ import annotations
66

77
import datetime
8-
from http import HTTPStatus
98
import io
9+
from http import HTTPStatus
1010
from urllib.parse import urljoin
1111

1212
import requests
@@ -21,8 +21,8 @@
2121
RequestTimeTooSkewed,
2222
)
2323
from vws.exceptions.custom_exceptions import (
24-
RequestEntityTooLarge,
2524
ActiveMatchingTargetsDeleteProcessing,
25+
RequestEntityTooLarge,
2626
)
2727
from vws.include_target_data import CloudRecoIncludeTargetData
2828
from vws.reports import QueryResult, TargetData
@@ -78,22 +78,21 @@ def query(
7878
client access key pair is not correct.
7979
~vws.exceptions.cloud_reco_exceptions.MaxNumResultsOutOfRange:
8080
``max_num_results`` is not within the range (1, 50).
81-
~vws.exceptions.cloud_reco_exceptions.ActiveMatchingTargetsDeleteProcessing: The given
82-
image matches a target which was recently
83-
deleted.
8481
~vws.exceptions.cloud_reco_exceptions.InactiveProject: The project
8582
is inactive.
8683
~vws.exceptions.cloud_reco_exceptions.RequestTimeTooSkewed: There
8784
is an error with the time sent to Vuforia.
8885
~vws.exceptions.cloud_reco_exceptions.BadImage: There is a problem
8986
with the given image. For example, it must be a JPEG or PNG
9087
file in the grayscale or RGB color space.
91-
~vws.exceptions.custom_exceptions.RequestEntityTooLarge:
92-
The given image is too large.
88+
~vws.exceptions.custom_exceptions.RequestEntityTooLarge: The given
89+
image is too large.
90+
~vws.exceptions.custom_exceptions.ActiveMatchingTargetsDeleteProcessing:
91+
The given image matches a target which was recently deleted.
9392
9493
Returns:
9594
An ordered list of target details of matching targets.
96-
"""
95+
""" # noqa: E501
9796
image_content = image.getvalue()
9897
body = {
9998
'image': ('image.jpeg', image_content, 'image/jpeg'),
@@ -140,7 +139,7 @@ def query(
140139
raise MaxNumResultsOutOfRange(response=response)
141140

142141
if 'No content to map due to end-of-input' in response.text:
143-
raise ActiveMatchingTargetsDeleteProcessing(response=response)
142+
raise ActiveMatchingTargetsDeleteProcessing
144143

145144
result_code = response.json()['result_code']
146145
if result_code != 'Success':

tests/test_cloud_reco_exceptions.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from http import HTTPStatus
88

99
import pytest
10-
import requests
1110
from mock_vws import MockVWS
1211
from mock_vws.database import VuforiaDatabase
1312
from mock_vws.states import States
@@ -16,11 +15,13 @@
1615
from vws.exceptions.base_exceptions import CloudRecoException
1716
from vws.exceptions.cloud_reco_exceptions import (
1817
AuthenticationFailure,
18+
BadImage,
1919
InactiveProject,
20-
MatchProcessing,
2120
MaxNumResultsOutOfRange,
21+
RequestTimeTooSkewed,
2222
)
2323
from vws.exceptions.custom_exceptions import (
24+
ActiveMatchingTargetsDeleteProcessing,
2425
RequestEntityTooLarge,
2526
)
2627

@@ -54,29 +55,33 @@ def test_image_too_large(
5455
A ``RequestEntityTooLarge`` exception is raised if an image which is too
5556
large is given.
5657
"""
57-
with pytest.raises(RequestEntityTooLarge) as exc:
58+
with pytest.raises(RequestEntityTooLarge):
5859
cloud_reco_client.query(image=png_too_large)
5960

61+
6062
def test_cloudrecoexception_inheritance() -> None:
6163
"""
6264
CloudRecoService-specific exceptions inherit from CloudRecoException.
6365
"""
6466
subclasses = [
65-
MatchProcessing,
6667
MaxNumResultsOutOfRange,
68+
InactiveProject,
69+
BadImage,
70+
AuthenticationFailure,
71+
RequestTimeTooSkewed,
6772
]
6873
for subclass in subclasses:
6974
assert issubclass(subclass, CloudRecoException)
7075

7176

72-
def test_match_processing(
77+
def test_active_matching_targets_delete_processing(
7378
vws_client: VWS,
7479
cloud_reco_client: CloudRecoService,
7580
high_quality_image: io.BytesIO,
7681
) -> None:
7782
"""
78-
A ``MatchProcessing`` exception is raised when a target in processing is
79-
matched.
83+
A ``ActiveMatchingTargetsDeleteProcessing`` exception is raised when a
84+
target which has recently been deleted is matched.
8085
"""
8186
target_id = vws_client.add_target(
8287
name='x',
@@ -88,10 +93,8 @@ def test_match_processing(
8893
vws_client.wait_for_target_processed(target_id=target_id)
8994
vws_client.delete_target(target_id=target_id)
9095
time.sleep(0.2)
91-
with pytest.raises(MatchProcessing) as exc:
92-
response = cloud_reco_client.query(image=high_quality_image)
93-
94-
assert exc.value.response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR
96+
with pytest.raises(ActiveMatchingTargetsDeleteProcessing):
97+
cloud_reco_client.query(image=high_quality_image)
9598

9699

97100
def test_authentication_failure(high_quality_image: io.BytesIO) -> None:

0 commit comments

Comments
 (0)