Skip to content

Commit decbb6c

Browse files
committed
Passing tests on the mock
1 parent 7b7dda2 commit decbb6c

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

src/mock_vws/_query_validators/exceptions.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,33 @@ def __init__(self) -> None:
621621
}
622622

623623

624+
class RequestEntityTooLarge(ValidatorException):
625+
"""
626+
Exception raised when the given image file size is too large.
627+
"""
628+
629+
def __init__(self) -> None:
630+
"""
631+
Attributes:
632+
status_code: The status code to use in a response if this is
633+
raised.
634+
response_text: The response text to use in a response if this is
635+
raised.
636+
"""
637+
super().__init__()
638+
self.status_code = HTTPStatus.REQUEST_ENTITY_TOO_LARGE
639+
# TODO assert this!
640+
self.response_text = ''
641+
date = email.utils.formatdate(None, localtime=False, usegmt=True)
642+
self.headers = {
643+
'Connection': 'Close',
644+
'Date': date,
645+
'Server': 'nginx',
646+
'Content-Type': 'text/html',
647+
'Content-Length': str(len(self.response_text)),
648+
}
649+
650+
624651
class MatchProcessing(ValidatorException):
625652
"""
626653
Exception raised a target is matched which is processing or recently

src/mock_vws/_query_validators/image_validators.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import requests
1010
from PIL import Image
1111

12-
from mock_vws._query_validators.exceptions import BadImage, ImageNotGiven
12+
from mock_vws._query_validators.exceptions import BadImage, ImageNotGiven, RequestEntityTooLarge
1313

1414

1515
def validate_image_field_given(
@@ -54,7 +54,7 @@ def validate_image_file_size(
5454
request_body: The body of the request.
5555
5656
Raises:
57-
requests.exceptions.ConnectionError: The image file size is too large.
57+
RequestEntityTooLarge: The image file size is too large.
5858
"""
5959
body_file = io.BytesIO(request_body)
6060

@@ -74,7 +74,7 @@ def validate_image_file_size(
7474
# files.
7575
max_bytes = 2 * 1024 * 1024
7676
if len(image) > max_bytes:
77-
raise requests.exceptions.ConnectionError
77+
raise RequestEntityTooLarge
7878

7979

8080
def validate_image_dimensions(

tests/mock_vws/test_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,7 @@ def test_jpeg(
13071307
the maximum file size is "512 KiB for JPEG".
13081308
However, this test shows that the maximum size for JPEG is 2 MiB.
13091309
1310-
Above this limit, a ``ConnectionError`` is raised.
1310+
Above this limit, a ``REQUEST_ENTITY_TOO_LARGE`` response is returned.
13111311
We do not test exactly at this limit, but that may be beneficial in the
13121312
future.
13131313
"""

0 commit comments

Comments
 (0)