|
5 | 5 | from __future__ import annotations |
6 | 6 |
|
7 | 7 | import base64 |
| 8 | +import io |
8 | 9 | import json |
9 | 10 | from http import HTTPMethod, HTTPStatus |
10 | 11 | from string import hexdigits |
|
18 | 19 | from requests.structures import CaseInsensitiveDict |
19 | 20 | from vws.exceptions.custom_exceptions import OopsAnErrorOccurredPossiblyBadName |
20 | 21 | from vws.exceptions.vws_exceptions import ( |
| 22 | + BadImage, |
21 | 23 | Fail, |
22 | 24 | ImageTooLarge, |
23 | 25 | MetadataTooLarge, |
|
34 | 36 | from tests.mock_vws.utils.too_many_requests import handle_server_errors |
35 | 37 |
|
36 | 38 | if TYPE_CHECKING: |
37 | | - import io |
38 | | - |
39 | 39 | from mock_vws.database import VuforiaDatabase |
40 | 40 | from vws import VWS |
41 | 41 | from vws.exceptions.response import Response |
@@ -687,29 +687,22 @@ def test_not_base64_encoded_not_processable( |
687 | 687 | ) |
688 | 688 |
|
689 | 689 | @staticmethod |
690 | | - def test_not_image( |
691 | | - vuforia_database: VuforiaDatabase, |
692 | | - ) -> None: |
| 690 | + def test_not_image(vws_client: VWS) -> None: |
693 | 691 | """ |
694 | 692 | If the given image is not an image file then a `BadImage` result is |
695 | 693 | returned. |
696 | 694 | """ |
697 | | - not_image_data = b"not_image_data" |
698 | | - image_data_encoded = base64.b64encode(s=not_image_data).decode("ascii") |
699 | | - |
700 | | - data = { |
701 | | - "name": "example_name", |
702 | | - "width": 1, |
703 | | - "image": image_data_encoded, |
704 | | - } |
705 | | - |
706 | | - response = _add_target_to_vws( |
707 | | - vuforia_database=vuforia_database, |
708 | | - data=data, |
709 | | - ) |
| 695 | + with pytest.raises(expected_exception=BadImage) as exc: |
| 696 | + vws_client.add_target( |
| 697 | + name="example_name", |
| 698 | + width=1, |
| 699 | + image=io.BytesIO(initial_bytes=b"not_image_data"), |
| 700 | + application_metadata=None, |
| 701 | + active_flag=True, |
| 702 | + ) |
710 | 703 |
|
711 | 704 | assert_vws_failure( |
712 | | - response=response, |
| 705 | + response=exc.value.response, |
713 | 706 | status_code=HTTPStatus.UNPROCESSABLE_ENTITY, |
714 | 707 | result_code=ResultCodes.BAD_IMAGE, |
715 | 708 | ) |
|
0 commit comments