Skip to content

Commit d2156b6

Browse files
committed
Remove one more use of a custom helper
1 parent 6dce119 commit d2156b6

File tree

1 file changed

+26
-44
lines changed

1 file changed

+26
-44
lines changed

tests/mock_vws/test_add_target.py

Lines changed: 26 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from vws.exceptions.custom_exceptions import OopsAnErrorOccurredPossiblyBadName
2020
from vws.exceptions.vws_exceptions import (
2121
Fail,
22+
ImageTooLarge,
2223
MetadataTooLarge,
2324
ProjectInactive,
2425
)
@@ -549,32 +550,22 @@ def test_bad_image_format_or_color_space(
549550

550551
@staticmethod
551552
def test_corrupted(
552-
vuforia_database: VuforiaDatabase,
553553
corrupted_image_file: io.BytesIO,
554+
vws_client: VWS,
554555
) -> None:
555556
"""
556557
No error is returned when the given image is corrupted.
557558
"""
558-
image_data = corrupted_image_file.getvalue()
559-
image_data_encoded = base64.b64encode(s=image_data).decode("ascii")
560-
561-
data = {
562-
"name": "example_name",
563-
"width": 1,
564-
"image": image_data_encoded,
565-
}
566-
567-
response = _add_target_to_vws(
568-
vuforia_database=vuforia_database,
569-
data=data,
559+
vws_client.add_target(
560+
name="example_name",
561+
width=1,
562+
image=corrupted_image_file,
563+
application_metadata=None,
564+
active_flag=True,
570565
)
571566

572-
assert_success(response=response)
573-
574567
@staticmethod
575-
def test_image_file_size_too_large(
576-
vuforia_database: VuforiaDatabase,
577-
) -> None:
568+
def test_image_file_size_too_large(vws_client: VWS) -> None:
578569
"""
579570
An ``ImageTooLarge`` result is returned if the image file size is above
580571
a certain threshold.
@@ -588,8 +579,7 @@ def test_image_file_size_too_large(
588579
height=height,
589580
)
590581

591-
image_data = png_not_too_large.read()
592-
image_data_encoded = base64.b64encode(s=image_data).decode("ascii")
582+
image_data = png_not_too_large.getvalue()
593583
image_content_size = len(image_data)
594584
# We check that the image we created is just slightly smaller than the
595585
# maximum file size.
@@ -599,19 +589,14 @@ def test_image_file_size_too_large(
599589
assert image_content_size < max_bytes
600590
assert (image_content_size * 1.05) > max_bytes
601591

602-
data = {
603-
"name": "example_name",
604-
"width": 1,
605-
"image": image_data_encoded,
606-
}
607-
608-
response = _add_target_to_vws(
609-
vuforia_database=vuforia_database,
610-
data=data,
592+
vws_client.add_target(
593+
name="example_name",
594+
width=1,
595+
image=png_not_too_large,
596+
application_metadata=None,
597+
active_flag=True,
611598
)
612599

613-
assert_success(response=response)
614-
615600
width = width + 1
616601
height = height + 1
617602
png_too_large = make_image_file(
@@ -621,8 +606,7 @@ def test_image_file_size_too_large(
621606
height=height,
622607
)
623608

624-
image_data = png_too_large.read()
625-
image_data_encoded = base64.b64encode(s=image_data).decode("ascii")
609+
image_data = png_too_large.getvalue()
626610
image_content_size = len(image_data)
627611
# We check that the image we created is just slightly smaller than the
628612
# maximum file size.
@@ -632,19 +616,17 @@ def test_image_file_size_too_large(
632616
assert image_content_size < max_bytes
633617
assert (image_content_size * 1.05) > max_bytes
634618

635-
data = {
636-
"name": "example_name_2",
637-
"width": 1,
638-
"image": image_data_encoded,
639-
}
640-
641-
response = _add_target_to_vws(
642-
vuforia_database=vuforia_database,
643-
data=data,
644-
)
619+
with pytest.raises(expected_exception=ImageTooLarge) as exc:
620+
vws_client.add_target(
621+
name="example_name_2",
622+
width=1,
623+
image=png_too_large,
624+
application_metadata=None,
625+
active_flag=True,
626+
)
645627

646628
assert_vws_failure(
647-
response=response,
629+
response=exc.value.response,
648630
status_code=HTTPStatus.UNPROCESSABLE_ENTITY,
649631
result_code=ResultCodes.IMAGE_TOO_LARGE,
650632
)

0 commit comments

Comments
 (0)