Skip to content

Commit c723e56

Browse files
committed
Passing update test [skip ci]
1 parent 976c30f commit c723e56

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

tests/mock_vws/test_update_target.py

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from tests.mock_vws.utils import (
1616
add_target_to_vws,
1717
get_vws_target,
18+
make_image_file,
1819
update_target,
1920
wait_for_target_processed,
2021
)
@@ -802,7 +803,8 @@ def test_image_too_large(
802803
target_id: str,
803804
) -> None:
804805
"""
805-
No error is returned when the given image is corrupted.
806+
An `ImageTooLarge` result is returned if the image is above a certain
807+
threshold.
806808
"""
807809
max_bytes = 2.3 * 1024 * 1024
808810
width = height = 886
@@ -812,21 +814,22 @@ def test_image_too_large(
812814
width=width,
813815
height=height,
814816
)
815-
width = width + 1
816-
height = height + 1
817-
png_too_large = make_image_file(
818-
file_format='PNG',
819-
color_space='RGB',
820-
width=width,
821-
height=height,
822-
)
823817

824818
wait_for_target_processed(
825819
vuforia_database_keys=vuforia_database_keys,
826820
target_id=target_id,
827821
)
828822

823+
image_data = png_not_too_large.read()
829824
image_data_encoded = base64.b64encode(image_data).decode('ascii')
825+
image_content_size = len(image_data)
826+
# We check that the image we created is just slightly smaller than the
827+
# maximum file size.
828+
#
829+
# This is just because of the implementation details of
830+
# ``max_image_file``.
831+
assert image_content_size < max_bytes
832+
assert (image_content_size * 1.05) > max_bytes
830833

831834
response = update_target(
832835
vuforia_database_keys=vuforia_database_keys,
@@ -845,6 +848,38 @@ def test_image_too_large(
845848
target_id=target_id,
846849
)
847850

851+
width = width + 1
852+
height = height + 1
853+
png_too_large = make_image_file(
854+
file_format='PNG',
855+
color_space='RGB',
856+
width=width,
857+
height=height,
858+
)
859+
860+
image_data = png_too_large.read()
861+
image_data_encoded = base64.b64encode(image_data).decode('ascii')
862+
image_content_size = len(image_data)
863+
# We check that the image we created is just slightly smaller than the
864+
# maximum file size.
865+
#
866+
# This is just because of the implementation details of
867+
# ``max_image_file``.
868+
assert image_content_size < max_bytes
869+
assert (image_content_size * 1.05) > max_bytes
870+
871+
response = update_target(
872+
vuforia_database_keys=vuforia_database_keys,
873+
data={'image': image_data_encoded},
874+
target_id=target_id,
875+
)
876+
877+
assert_vws_failure(
878+
response=response,
879+
status_code=codes.UNPROCESSABLE_ENTITY,
880+
result_code=ResultCodes.IMAGE_TOO_LARGE,
881+
)
882+
848883
def test_not_base64_encoded(
849884
self,
850885
vuforia_database_keys: VuforiaDatabaseKeys,

0 commit comments

Comments
 (0)