Skip to content

Commit c6d3c12

Browse files
committed
Progress towards test
1 parent 59069e7 commit c6d3c12

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

src/vws/exceptions.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,18 @@ def __init__(self, response: Response) -> None:
6363
"""
6464
super().__init__()
6565
self.response = response
66+
67+
68+
class ImageTooLarge(Exception):
69+
"""
70+
Exception raised when Vuforia returns a response with a result code
71+
'ImageTooLarge'.
72+
"""
73+
74+
def __init__(self, response: Response) -> None:
75+
"""
76+
Args:
77+
response: The response to a request to Vuforia.
78+
"""
79+
super().__init__()
80+
self.response = response

src/vws/vws.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from vws._authorization import authorization_header, rfc_1123_date
1818
from vws.exceptions import (
19+
ImageTooLarge,
1920
MetadataTooLarge,
2021
TargetNameExist,
2122
TargetStatusProcessing,
@@ -110,6 +111,7 @@ class _ResultCodes(Enum):
110111

111112

112113
_EXCEPTIONS = {
114+
_ResultCodes.IMAGE_TOO_LARGE: ImageTooLarge,
113115
_ResultCodes.METADATA_TOO_LARGE: MetadataTooLarge,
114116
_ResultCodes.TARGET_NAME_EXIST: TargetNameExist,
115117
_ResultCodes.TARGET_STATUS_PROCESSING: TargetStatusProcessing,

tests/test_exceptions/test_image_too_large.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
from pathlib import Path
88

99
import pytest
10+
from requests import codes
1011
from PIL import Image
1112

13+
from vws import VWS
14+
from vws.exceptions import ImageTooLarge
15+
1216

1317
def make_image_file(
1418
file_format: str,
@@ -43,7 +47,7 @@ def make_image_file(
4347
return image_buffer
4448

4549

46-
def test_foo():
50+
def test_foo(client: VWS):
4751
width = height = 890
4852

4953
png_too_large = make_image_file(
@@ -52,6 +56,8 @@ def test_foo():
5256
width=width,
5357
height=height,
5458
)
55-
#
56-
# with pytest.raises(ImageTooLarge):
57-
# client.add_target(name='x', width=1, image=png_too_large)
59+
60+
with pytest.raises(ImageTooLarge) as exc:
61+
client.add_target(name='x', width=1, image=png_too_large)
62+
63+
assert exc.value.response.status_code == codes.UNPROCESSABLE_ENTITY

0 commit comments

Comments
 (0)