|
3 | 3 | """ |
4 | 4 |
|
5 | 5 | import io |
| 6 | +import time |
6 | 7 | from http import HTTPStatus |
7 | 8 |
|
8 | 9 | import pytest |
9 | | -import requests |
10 | 10 | from mock_vws import MockVWS |
11 | 11 | from mock_vws.database import VuforiaDatabase |
12 | 12 | from mock_vws.states import States |
|
15 | 15 | from vws.exceptions.base_exceptions import CloudRecoException |
16 | 16 | from vws.exceptions.cloud_reco_exceptions import ( |
17 | 17 | AuthenticationFailure, |
| 18 | + BadImage, |
18 | 19 | InactiveProject, |
19 | | - MatchProcessing, |
20 | 20 | MaxNumResultsOutOfRange, |
| 21 | + RequestTimeTooSkewed, |
21 | 22 | ) |
22 | 23 | from vws.exceptions.custom_exceptions import ( |
23 | | - ConnectionErrorPossiblyImageTooLarge, |
| 24 | + ActiveMatchingTargetsDeleteProcessing, |
| 25 | + RequestEntityTooLarge, |
24 | 26 | ) |
25 | 27 |
|
26 | 28 |
|
@@ -50,68 +52,49 @@ def test_image_too_large( |
50 | 52 | png_too_large: io.BytesIO, |
51 | 53 | ) -> None: |
52 | 54 | """ |
53 | | - A ``ConnectionErrorPossiblyImageTooLarge`` exception is raised if an |
54 | | - image which is too large is given. |
| 55 | + A ``RequestEntityTooLarge`` exception is raised if an image which is too |
| 56 | + large is given. |
55 | 57 | """ |
56 | | - with pytest.raises(ConnectionErrorPossiblyImageTooLarge) as exc: |
| 58 | + with pytest.raises(RequestEntityTooLarge): |
57 | 59 | cloud_reco_client.query(image=png_too_large) |
58 | 60 |
|
59 | | - assert isinstance(exc.value, requests.ConnectionError) |
60 | | - |
61 | 61 |
|
62 | 62 | def test_cloudrecoexception_inheritance() -> None: |
63 | 63 | """ |
64 | 64 | CloudRecoService-specific exceptions inherit from CloudRecoException. |
65 | 65 | """ |
66 | 66 | subclasses = [ |
67 | | - MatchProcessing, |
68 | 67 | MaxNumResultsOutOfRange, |
| 68 | + InactiveProject, |
| 69 | + BadImage, |
| 70 | + AuthenticationFailure, |
| 71 | + RequestTimeTooSkewed, |
69 | 72 | ] |
70 | 73 | for subclass in subclasses: |
71 | 74 | assert issubclass(subclass, CloudRecoException) |
72 | 75 |
|
73 | 76 |
|
74 | | -def test_base_exception( |
75 | | - vws_client: VWS, |
76 | | - cloud_reco_client: CloudRecoService, |
77 | | - high_quality_image: io.BytesIO, |
78 | | -) -> None: |
79 | | - """ |
80 | | - ``CloudRecoException``s has a response property. |
81 | | - """ |
82 | | - vws_client.add_target( |
83 | | - name='x', |
84 | | - width=1, |
85 | | - image=high_quality_image, |
86 | | - active_flag=True, |
87 | | - application_metadata=None, |
88 | | - ) |
89 | | - |
90 | | - with pytest.raises(CloudRecoException) as exc: |
91 | | - cloud_reco_client.query(image=high_quality_image) |
92 | | - |
93 | | - assert exc.value.response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR |
94 | | - |
95 | | - |
96 | | -def test_match_processing( |
| 77 | +def test_active_matching_targets_delete_processing( |
97 | 78 | vws_client: VWS, |
98 | 79 | cloud_reco_client: CloudRecoService, |
99 | 80 | high_quality_image: io.BytesIO, |
100 | 81 | ) -> None: |
101 | 82 | """ |
102 | | - A ``MatchProcessing`` exception is raised when a target in processing is |
103 | | - matched. |
| 83 | + A ``ActiveMatchingTargetsDeleteProcessing`` exception is raised when a |
| 84 | + target which has recently been deleted is matched. |
104 | 85 | """ |
105 | | - vws_client.add_target( |
| 86 | + target_id = vws_client.add_target( |
106 | 87 | name='x', |
107 | 88 | width=1, |
108 | 89 | image=high_quality_image, |
109 | 90 | active_flag=True, |
110 | 91 | application_metadata=None, |
111 | 92 | ) |
112 | | - with pytest.raises(MatchProcessing) as exc: |
| 93 | + vws_client.wait_for_target_processed(target_id=target_id) |
| 94 | + vws_client.delete_target(target_id=target_id) |
| 95 | + time.sleep(0.2) |
| 96 | + with pytest.raises(ActiveMatchingTargetsDeleteProcessing): |
113 | 97 | cloud_reco_client.query(image=high_quality_image) |
114 | | - assert exc.value.response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR |
115 | 98 |
|
116 | 99 |
|
117 | 100 | def test_authentication_failure(high_quality_image: io.BytesIO) -> None: |
|
0 commit comments