Skip to content

Commit 4d39041

Browse files
committed
Remove dodgy fixture
1 parent 9cf4d15 commit 4d39041

File tree

2 files changed

+114
-25
lines changed

2 files changed

+114
-25
lines changed

tests/mock_vws/fixtures/images.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,6 @@ def png_greyscale() -> io.BytesIO:
5050
)
5151

5252

53-
@pytest.fixture()
54-
def png_large(
55-
png_rgb: io.BytesIO, # pylint: disable=redefined-outer-name
56-
) -> io.BytesIO:
57-
"""
58-
Return a PNG file of the maximum allowed file size.
59-
60-
https://library.vuforia.com/articles/Training/Cloud-Recognition-Guide
61-
describes that the maximum allowed file size of an image is 2 MB.
62-
However, tests using this fixture demonstrate that the maximum allowed
63-
size is actually slightly greater than that.
64-
"""
65-
png_size = len(png_rgb.getbuffer())
66-
max_size = 2359293
67-
filler_length = max_size - png_size
68-
filler_data = b'\x00' * int(filler_length)
69-
original_data = png_rgb.getvalue()
70-
longer_data = original_data.replace(b'IEND', filler_data + b'IEND')
71-
png = io.BytesIO(longer_data)
72-
return png
73-
74-
7553
@pytest.fixture
7654
def jpeg_cmyk() -> io.BytesIO:
7755
"""
@@ -114,7 +92,7 @@ def tiff_rgb() -> io.BytesIO:
11492
)
11593

11694

117-
@pytest.fixture(params=['png_rgb', 'jpeg_rgb', 'png_greyscale', 'png_large'])
95+
@pytest.fixture(params=['png_rgb', 'jpeg_rgb', 'png_greyscale'])
11896
def image_file(request: SubRequest) -> io.BytesIO:
11997
"""
12098
Return an image file which is expected to work on Vuforia.

tests/mock_vws/test_add_target.py

Lines changed: 113 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def test_image_valid(
410410

411411
assert_success(response=response)
412412

413-
def test_bad_image(
413+
def test_bad_image_format_or_color_space(
414414
self,
415415
bad_image_file: io.BytesIO,
416416
vuforia_database_keys: VuforiaDatabaseKeys,
@@ -440,7 +440,7 @@ def test_bad_image(
440440
result_code=ResultCodes.BAD_IMAGE,
441441
)
442442

443-
def test_too_large(
443+
def test_corrupted(
444444
self,
445445
vuforia_database_keys: VuforiaDatabaseKeys,
446446
png_large: io.BytesIO,
@@ -476,6 +476,117 @@ def test_too_large(
476476
result_code=ResultCodes.IMAGE_TOO_LARGE,
477477
)
478478

479+
def test_jpeg_too_large(
480+
self,
481+
vuforia_database_keys: VuforiaDatabaseKeys,
482+
png_large: io.BytesIO,
483+
) -> None:
484+
"""
485+
foobar todo update docstring
486+
An `ImageTooLarge` result is returned if the image is above a certain
487+
threshold.
488+
489+
This threshold is documented as being 2 MB but it is actually
490+
slightly larger. See the `png_large` fixture for more details.
491+
"""
492+
original_data = png_large.getvalue()
493+
longer_data = original_data.replace(b'IEND', b'\x00' + b'IEND')
494+
too_large_file = io.BytesIO(longer_data)
495+
496+
image_data = too_large_file.read()
497+
image_data_encoded = base64.b64encode(image_data).decode('ascii')
498+
499+
data = {
500+
'name': 'example_name',
501+
'width': 1,
502+
'image': image_data_encoded,
503+
}
504+
505+
response = add_target_to_vws(
506+
vuforia_database_keys=vuforia_database_keys,
507+
data=data,
508+
)
509+
510+
assert_vws_failure(
511+
response=response,
512+
status_code=codes.UNPROCESSABLE_ENTITY,
513+
result_code=ResultCodes.IMAGE_TOO_LARGE,
514+
)
515+
516+
def test_png_too_large(
517+
self,
518+
vuforia_database_keys: VuforiaDatabaseKeys,
519+
png_large: io.BytesIO,
520+
) -> None:
521+
"""
522+
foobar todo update docstring
523+
An `ImageTooLarge` result is returned if the image is above a certain
524+
threshold.
525+
526+
This threshold is documented as being 2 MB but it is actually
527+
slightly larger. See the `png_large` fixture for more details.
528+
"""
529+
original_data = png_large.getvalue()
530+
longer_data = original_data.replace(b'IEND', b'\x00' + b'IEND')
531+
too_large_file = io.BytesIO(longer_data)
532+
533+
image_data = too_large_file.read()
534+
image_data_encoded = base64.b64encode(image_data).decode('ascii')
535+
536+
data = {
537+
'name': 'example_name',
538+
'width': 1,
539+
'image': image_data_encoded,
540+
}
541+
542+
response = add_target_to_vws(
543+
vuforia_database_keys=vuforia_database_keys,
544+
data=data,
545+
)
546+
547+
assert_vws_failure(
548+
response=response,
549+
status_code=codes.UNPROCESSABLE_ENTITY,
550+
result_code=ResultCodes.IMAGE_TOO_LARGE,
551+
)
552+
553+
def test_corrupted_and_too_large(
554+
self,
555+
vuforia_database_keys: VuforiaDatabaseKeys,
556+
png_large: io.BytesIO,
557+
) -> None:
558+
"""
559+
foobar todo update docstring
560+
An `ImageTooLarge` result is returned if the image is above a certain
561+
threshold.
562+
563+
This threshold is documented as being 2 MB but it is actually
564+
slightly larger. See the `png_large` fixture for more details.
565+
"""
566+
original_data = png_large.getvalue()
567+
longer_data = original_data.replace(b'IEND', b'\x00' + b'IEND')
568+
too_large_file = io.BytesIO(longer_data)
569+
570+
image_data = too_large_file.read()
571+
image_data_encoded = base64.b64encode(image_data).decode('ascii')
572+
573+
data = {
574+
'name': 'example_name',
575+
'width': 1,
576+
'image': image_data_encoded,
577+
}
578+
579+
response = add_target_to_vws(
580+
vuforia_database_keys=vuforia_database_keys,
581+
data=data,
582+
)
583+
584+
assert_vws_failure(
585+
response=response,
586+
status_code=codes.UNPROCESSABLE_ENTITY,
587+
result_code=ResultCodes.IMAGE_TOO_LARGE,
588+
)
589+
479590
def test_not_base64_encoded(
480591
self,
481592
vuforia_database_keys: VuforiaDatabaseKeys,

0 commit comments

Comments
 (0)