Skip to content

Commit 1bf2b74

Browse files
committed
One test passing
1 parent 51c001a commit 1bf2b74

File tree

4 files changed

+20
-26
lines changed

4 files changed

+20
-26
lines changed

dev-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ PyYAML==5.4.1
55
Pygments==2.8.1
66
Sphinx-Substitution-Extensions==2020.9.30.0
77
Sphinx==3.5.3
8-
VWS-Python-Mock==2020.10.3.0
8+
VWS-Python-Mock==2021.3.27.1
99
VWS-Test-Fixtures==2020.9.25.1
1010
autoflake==1.4
1111
check-manifest==0.46

src/vws/exceptions/custom_exceptions.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ class UnknownVWSErrorPossiblyBadName(Exception):
1616
"""
1717

1818

19-
class ConnectionErrorPossiblyImageTooLarge(requests.ConnectionError):
19+
class RequestEntityTooLarge(Exception):
2020
"""
21-
Exception raised when a ConnectionError is raised from a query. This has
22-
been seen to happen when the given image is too large.
21+
Exception raised when the given image is too large.
2322
"""
2423

2524

src/vws/query.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from __future__ import annotations
66

77
import datetime
8+
from http import HTTPStatus
89
import io
910
from urllib.parse import urljoin
1011

@@ -21,7 +22,7 @@
2122
RequestTimeTooSkewed,
2223
)
2324
from vws.exceptions.custom_exceptions import (
24-
ConnectionErrorPossiblyImageTooLarge,
25+
RequestEntityTooLarge,
2526
)
2627
from vws.include_target_data import CloudRecoIncludeTargetData
2728
from vws.reports import QueryResult, TargetData
@@ -82,13 +83,13 @@ def query(
8283
deleted and Vuforia returns an error in this case.
8384
~vws.exceptions.cloud_reco_exceptions.InactiveProject: The project
8485
is inactive.
85-
~vws.exceptions.custom_exceptions.ConnectionErrorPossiblyImageTooLarge:
86-
The given image is too large.
8786
~vws.exceptions.cloud_reco_exceptions.RequestTimeTooSkewed: There
8887
is an error with the time sent to Vuforia.
8988
~vws.exceptions.cloud_reco_exceptions.BadImage: There is a problem
9089
with the given image. For example, it must be a JPEG or PNG
9190
file in the grayscale or RGB color space.
91+
~vws.exceptions.custom_exceptions.RequestEntityTooLarge:
92+
The given image is too large.
9293
9394
Returns:
9495
An ordered list of target details of matching targets.
@@ -125,18 +126,15 @@ def query(
125126
'Content-Type': content_type_header,
126127
}
127128

128-
try:
129-
response = requests.request(
130-
method=method,
131-
url=urljoin(base=self._base_vwq_url, url=request_path),
132-
headers=headers,
133-
data=content,
134-
)
135-
except requests.exceptions.ConnectionError as exc:
136-
raise ConnectionErrorPossiblyImageTooLarge(
137-
request=exc.request,
138-
response=exc.response,
139-
) from exc
129+
response = requests.request(
130+
method=method,
131+
url=urljoin(base=self._base_vwq_url, url=request_path),
132+
headers=headers,
133+
data=content,
134+
)
135+
136+
if response.status_code == HTTPStatus.REQUEST_ENTITY_TOO_LARGE:
137+
raise RequestEntityTooLarge
140138

141139
if 'Integer out of range' in response.text:
142140
raise MaxNumResultsOutOfRange(response=response)

tests/test_cloud_reco_exceptions.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
MaxNumResultsOutOfRange,
2121
)
2222
from vws.exceptions.custom_exceptions import (
23-
ConnectionErrorPossiblyImageTooLarge,
23+
RequestEntityTooLarge,
2424
)
2525

2626

@@ -50,15 +50,12 @@ def test_image_too_large(
5050
png_too_large: io.BytesIO,
5151
) -> None:
5252
"""
53-
A ``ConnectionErrorPossiblyImageTooLarge`` exception is raised if an
54-
image which is too large is given.
53+
A ``RequestEntityTooLarge`` exception is raised if an image which is too
54+
large is given.
5555
"""
56-
with pytest.raises(ConnectionErrorPossiblyImageTooLarge) as exc:
56+
with pytest.raises(RequestEntityTooLarge) as exc:
5757
cloud_reco_client.query(image=png_too_large)
5858

59-
assert isinstance(exc.value, requests.ConnectionError)
60-
61-
6259
def test_cloudrecoexception_inheritance() -> None:
6360
"""
6461
CloudRecoService-specific exceptions inherit from CloudRecoException.

0 commit comments

Comments
 (0)