File tree Expand file tree Collapse file tree 3 files changed +31
-4
lines changed
src/mock_vws/_query_validators Expand file tree Collapse file tree 3 files changed +31
-4
lines changed Original file line number Diff line number Diff 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+
624651class MatchProcessing (ValidatorException ):
625652 """
626653 Exception raised a target is matched which is processing or recently
Original file line number Diff line number Diff line change 99import requests
1010from 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
1515def 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
8080def validate_image_dimensions (
Original file line number Diff line number Diff 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 """
You can’t perform that action at this time.
0 commit comments