|
4 | 4 |
|
5 | 5 | import io |
6 | 6 | from http import HTTPStatus |
7 | | -from typing import List, Type, Union |
8 | 7 |
|
9 | 8 | import pytest |
10 | | -import requests |
11 | 9 | from freezegun import freeze_time |
12 | 10 | from mock_vws import MockVWS |
13 | 11 | from mock_vws.database import VuforiaDatabase |
|
19 | 17 | MatchProcessing, |
20 | 18 | MaxNumResultsOutOfRange, |
21 | 19 | ) |
22 | | -from vws.exceptions.custom_exceptions import ( |
23 | | - ConnectionErrorPossiblyImageTooLarge, |
24 | | - TargetProcessingTimeout, |
25 | | - UnknownVWSErrorPossiblyBadName, |
26 | | -) |
| 20 | +from vws.exceptions.custom_exceptions import UnknownVWSErrorPossiblyBadName |
27 | 21 | from vws.exceptions.vws_exceptions import ( |
28 | 22 | AuthenticationFailure, |
29 | 23 | BadImage, |
@@ -389,29 +383,32 @@ def test_cloudrecoexception_inheritance() -> None: |
389 | 383 | assert issubclass(subclass, CloudRecoException) |
390 | 384 |
|
391 | 385 |
|
392 | | -def test_others_inheritance() -> None: |
| 386 | +def test_base_exceptions_properties( |
| 387 | + vws_client: VWS, |
| 388 | + cloud_reco_client: CloudRecoService, |
| 389 | + high_quality_image: io.BytesIO, |
| 390 | +) -> None: |
393 | 391 | """ |
394 | | - Make sure other exceptions are inherited from their expected super-classes. |
| 392 | + ``VWSException``s and ``CloudRecoException```s each have a response |
| 393 | + property. |
395 | 394 | """ |
396 | | - assert issubclass( |
397 | | - ConnectionErrorPossiblyImageTooLarge, |
398 | | - requests.ConnectionError, |
| 395 | + with pytest.raises(VWSException) as exc: |
| 396 | + vws_client.get_target_record(target_id='a') |
| 397 | + |
| 398 | + assert exc.value.response.status_code == HTTPStatus.NOT_FOUND |
| 399 | + |
| 400 | + vws_client.add_target( |
| 401 | + name='x', |
| 402 | + width=1, |
| 403 | + image=high_quality_image, |
| 404 | + active_flag=True, |
| 405 | + application_metadata=None, |
399 | 406 | ) |
400 | | - assert issubclass(TargetProcessingTimeout, Exception) |
401 | 407 |
|
| 408 | + with pytest.raises(CloudRecoException) as cloud_reco_exc: |
| 409 | + cloud_reco_client.query(image=high_quality_image) |
402 | 410 |
|
403 | | -def test_base_exceptions_have_response_property_and_text_str() -> None: |
404 | | - """ |
405 | | - A VWSException or CloudRecoException should have a response property |
406 | | - and string representation with the text property of the response. |
407 | | - """ |
408 | | - base_classes: List[Union[Type[CloudRecoException], Type[VWSException]]] = [ |
409 | | - CloudRecoException, |
410 | | - VWSException, |
411 | | - ] |
412 | | - for base in base_classes: |
413 | | - response = requests.Response() |
414 | | - setattr(response, '._content', bytes(f'Test{base.__name__}', 'ascii')) |
415 | | - exception = base(response=response) |
416 | | - assert exception.response == response |
417 | | - assert str(exception) == response.text |
| 411 | + assert ( |
| 412 | + cloud_reco_exc.value.response.status_code |
| 413 | + == HTTPStatus.INTERNAL_SERVER_ERROR |
| 414 | + ) |
0 commit comments