Skip to content

Commit 79d1854

Browse files
committed
Add tests for base exceptions
1 parent 168b1ae commit 79d1854

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

tests/test_exceptions.py

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

55
import io
66
from http import HTTPStatus
7+
from typing import List, Type, Union
78

89
import pytest
10+
import requests
911
from freezegun import freeze_time
1012
from mock_vws import MockVWS
1113
from mock_vws.database import VuforiaDatabase
@@ -15,17 +17,27 @@
1517
from vws.exceptions import (
1618
AuthenticationFailure,
1719
BadImage,
20+
CloudRecoException,
21+
ConnectionErrorPossiblyImageTooLarge,
22+
DateRangeError,
1823
Fail,
1924
ImageTooLarge,
2025
MatchProcessing,
26+
MaxNumResultsOutOfRange,
2127
MetadataTooLarge,
28+
ProjectHasNoAPIAccess,
2229
ProjectInactive,
30+
ProjectSuspended,
31+
RequestQuotaReached,
2332
RequestTimeTooSkewed,
2433
TargetNameExist,
34+
TargetProcessingTimeout,
35+
TargetQuotaReached,
2536
TargetStatusNotSuccess,
2637
TargetStatusProcessing,
2738
UnknownTarget,
2839
UnknownVWSErrorPossiblyBadName,
40+
VWSException,
2941
)
3042

3143

@@ -333,3 +345,71 @@ def test_match_processing(
333345
with pytest.raises(MatchProcessing) as exc:
334346
cloud_reco_client.query(image=high_quality_image)
335347
assert exc.value.response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR
348+
349+
350+
def test_vwsexception_inheritance() -> None:
351+
"""
352+
VWS-related exceptions should inherit from VWSException.
353+
"""
354+
subclasses = [
355+
AuthenticationFailure,
356+
BadImage,
357+
DateRangeError,
358+
Fail,
359+
ImageTooLarge,
360+
MetadataTooLarge,
361+
ProjectInactive,
362+
ProjectHasNoAPIAccess,
363+
ProjectSuspended,
364+
RequestQuotaReached,
365+
RequestTimeTooSkewed,
366+
TargetNameExist,
367+
TargetQuotaReached,
368+
TargetStatusNotSuccess,
369+
TargetStatusProcessing,
370+
UnknownTarget,
371+
UnknownVWSErrorPossiblyBadName,
372+
]
373+
for subclass in subclasses:
374+
assert issubclass(subclass, VWSException)
375+
376+
377+
def test_cloudrecoexception_inheritance() -> None:
378+
"""
379+
CloudRecoService-specific exceptions should inherit from
380+
CloudRecoException.
381+
"""
382+
subclasses = [
383+
MatchProcessing,
384+
MaxNumResultsOutOfRange,
385+
]
386+
for subclass in subclasses:
387+
assert issubclass(subclass, CloudRecoException)
388+
389+
390+
def test_others_inheritance() -> None:
391+
"""
392+
Make sure other exceptions are inherited from their expected super-classes.
393+
"""
394+
assert issubclass(
395+
ConnectionErrorPossiblyImageTooLarge,
396+
requests.ConnectionError,
397+
)
398+
assert issubclass(TargetProcessingTimeout, Exception)
399+
400+
401+
def test_base_exceptions_have_response_property_and_text_str() -> None:
402+
"""
403+
A VWSException or CloudRecoException should have a response property
404+
and string representation with the text property of the response.
405+
"""
406+
base_classes: List[Union[Type[CloudRecoException], Type[VWSException]]] = [
407+
CloudRecoException,
408+
VWSException,
409+
]
410+
for base in base_classes:
411+
response = requests.Response()
412+
setattr(response, '._content', bytes(f'Test{base.__name__}', 'ascii'))
413+
exception = base(response=response)
414+
assert exception.response == response
415+
assert str(exception) == response.text

0 commit comments

Comments
 (0)