Skip to content

Commit 88aa7b3

Browse files
committed
Progress towards tests
1 parent 06ee8e6 commit 88aa7b3

File tree

2 files changed

+22
-48
lines changed

2 files changed

+22
-48
lines changed

tests/mock_vws/test_add_target.py

Lines changed: 18 additions & 46 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
delete_target,
18+
make_image_file,
1819
wait_for_target_processed,
1920
)
2021
from tests.mock_vws.utils.assertions import (
@@ -468,63 +469,34 @@ def test_corrupted(
468469

469470
assert_success(response=response)
470471

471-
def test_jpeg_too_large(
472+
def test_image_too_large(
472473
self,
473474
vuforia_database_keys: VuforiaDatabaseKeys,
474-
png_large: io.BytesIO,
475475
) -> None:
476476
"""
477-
foobar todo update docstring
478477
An `ImageTooLarge` result is returned if the image is above a certain
479478
threshold.
480-
481-
This threshold is documented as being 2 MB but it is actually
482-
slightly larger. See the `png_large` fixture for more details.
483479
"""
484-
original_data = png_large.getvalue()
485-
longer_data = original_data.replace(b'IEND', b'\x00' + b'IEND')
486-
too_large_file = io.BytesIO(longer_data)
487-
488-
image_data = too_large_file.read()
489-
image_data_encoded = base64.b64encode(image_data).decode('ascii')
490-
491-
data = {
492-
'name': 'example_name',
493-
'width': 1,
494-
'image': image_data_encoded,
495-
}
496-
497-
response = add_target_to_vws(
498-
vuforia_database_keys=vuforia_database_keys,
499-
data=data,
480+
max_bytes = 2 * 1024 * 1024
481+
width = height = 835
482+
png_not_too_large = make_image_file(
483+
file_format='PNG',
484+
color_space='RGB',
485+
width=width,
486+
height=height,
500487
)
501488

502-
assert_vws_failure(
503-
response=response,
504-
status_code=codes.UNPROCESSABLE_ENTITY,
505-
result_code=ResultCodes.IMAGE_TOO_LARGE,
506-
)
507-
508-
def test_png_too_large(
509-
self,
510-
vuforia_database_keys: VuforiaDatabaseKeys,
511-
png_large: io.BytesIO,
512-
) -> None:
513-
"""
514-
foobar todo update docstring
515-
An `ImageTooLarge` result is returned if the image is above a certain
516-
threshold.
517-
518-
This threshold is documented as being 2 MB but it is actually
519-
slightly larger. See the `png_large` fixture for more details.
520-
"""
521-
original_data = png_large.getvalue()
522-
longer_data = original_data.replace(b'IEND', b'\x00' + b'IEND')
523-
too_large_file = io.BytesIO(longer_data)
524-
525-
image_data = too_large_file.read()
489+
image_data = png_not_too_large.read()
526490
image_data_encoded = base64.b64encode(image_data).decode('ascii')
527491

492+
image_content_size = len(image_data)
493+
# We check that the image we created is just slightly smaller than the
494+
# maximum file size.
495+
#
496+
# This is just because of the implementation details of ``image_file``.
497+
assert image_content_size < max_bytes
498+
assert (image_content_size * 1.05) > max_bytes
499+
528500
data = {
529501
'name': 'example_name',
530502
'width': 1,

tests/mock_vws/test_query.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,8 @@ def test_png(
10951095
# We check that the image we created is just slightly smaller than the
10961096
# maximum file size.
10971097
#
1098-
# This is just because of the implementation details of ``image_file``.
1098+
# This is just because of the implementation details of
1099+
# ``make_image_file``.
10991100
assert image_content_size < max_bytes
11001101
assert (image_content_size * 1.05) > max_bytes
11011102

@@ -1121,7 +1122,8 @@ def test_png(
11211122
# We check that the image we created is just slightly larger than the
11221123
# maximum file size.
11231124
#
1124-
# This is just because of the implementation details of ``image_file``.
1125+
# This is just because of the implementation details of
1126+
# ``make_image_file``.
11251127
assert image_content_size > max_bytes
11261128
assert (image_content_size * 0.95) < max_bytes
11271129

0 commit comments

Comments
 (0)