Skip to content

Commit fb9fe46

Browse files
committed
Clean up a few tests
1 parent 6f1a79a commit fb9fe46

File tree

3 files changed

+35
-29
lines changed

3 files changed

+35
-29
lines changed

src/vws/exceptions/vws_exceptions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
"""
2+
Exception raised when Vuforia returns a response with a result code matching
3+
one of those documented at
4+
https://library.vuforia.com/articles/Solution/How-To-Use-the-Vuforia-Web-Services-API#How-To-Interperete-VWS-API-Result-Codes.
5+
"""
6+
17
import json
28
from urllib.parse import urlparse
39

tests/test_exceptions.py

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44

55
import io
66
from http import HTTPStatus
7-
from typing import List, Type, Union
87

98
import pytest
10-
import requests
119
from freezegun import freeze_time
1210
from mock_vws import MockVWS
1311
from mock_vws.database import VuforiaDatabase
@@ -19,11 +17,7 @@
1917
MatchProcessing,
2018
MaxNumResultsOutOfRange,
2119
)
22-
from vws.exceptions.custom_exceptions import (
23-
ConnectionErrorPossiblyImageTooLarge,
24-
TargetProcessingTimeout,
25-
UnknownVWSErrorPossiblyBadName,
26-
)
20+
from vws.exceptions.custom_exceptions import UnknownVWSErrorPossiblyBadName
2721
from vws.exceptions.vws_exceptions import (
2822
AuthenticationFailure,
2923
BadImage,
@@ -389,29 +383,32 @@ def test_cloudrecoexception_inheritance() -> None:
389383
assert issubclass(subclass, CloudRecoException)
390384

391385

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:
393391
"""
394-
Make sure other exceptions are inherited from their expected super-classes.
392+
``VWSException``s and ``CloudRecoException```s each have a response
393+
property.
395394
"""
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,
399406
)
400-
assert issubclass(TargetProcessingTimeout, Exception)
401407

408+
with pytest.raises(CloudRecoException) as cloud_reco_exc:
409+
cloud_reco_client.query(image=high_quality_image)
402410

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+
)

tests/test_query.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import uuid
77

88
import pytest
9+
import requests
910
from mock_vws import MockVWS
1011
from mock_vws.database import VuforiaDatabase
1112

@@ -62,9 +63,11 @@ def test_too_large(
6263
A ``ConnectionErrorPossiblyImageTooLarge`` exception is raised if an
6364
image which is too large is given.
6465
"""
65-
with pytest.raises(ConnectionErrorPossiblyImageTooLarge):
66+
with pytest.raises(ConnectionErrorPossiblyImageTooLarge) as exc:
6667
cloud_reco_client.query(image=png_too_large)
6768

69+
assert isinstance(exc.value, requests.ConnectionError)
70+
6871

6972
class TestCustomBaseVWQURL:
7073
"""

0 commit comments

Comments
 (0)