Skip to content

Commit 92c232d

Browse files
Add test for RequestQuotaReached exception.
The mock does not yet simulate this result code, so the test uses a custom transport. Closes #822. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent f257c27 commit 92c232d

2 files changed

Lines changed: 52 additions & 4 deletions

File tree

src/vws/exceptions/vws_exceptions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ class AuthenticationFailureError(VWSError):
5151
"""
5252

5353

54-
# See https://github.com/VWS-Python/vws-python/issues/822.
5554
@beartype
56-
class RequestQuotaReachedError(VWSError): # pragma: no cover
55+
class RequestQuotaReachedError(VWSError):
5756
"""Exception raised when Vuforia returns a response with a result code
5857
'RequestQuotaReached'.
5958
"""

tests/test_vws_exceptions.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for VWS exceptions."""
22

33
import io
4+
import json
45
import uuid
56
from http import HTTPStatus
67

@@ -41,6 +42,44 @@
4142
from vws.vumark_accept import VuMarkAccept
4243

4344

45+
class _RequestQuotaReachedTransport:
46+
"""Transport that always returns ``RequestQuotaReached``.
47+
48+
``vws-python-mock`` does not yet simulate this result code (see
49+
https://github.com/VWS-Python/vws-python-mock/issues/53), so tests
50+
use a custom transport instead of ``MockVWS``.
51+
"""
52+
53+
def close(self) -> None:
54+
"""Close the transport."""
55+
56+
def __call__(
57+
self,
58+
*,
59+
method: str,
60+
url: str,
61+
headers: dict[str, str],
62+
data: bytes,
63+
request_timeout: float | tuple[float, float],
64+
) -> Response:
65+
"""Return a ``RequestQuotaReached`` response."""
66+
del method, headers, request_timeout
67+
body = {
68+
"transaction_id": uuid.uuid4().hex,
69+
"result_code": "RequestQuotaReached",
70+
}
71+
text = json.dumps(body)
72+
return Response(
73+
text=text,
74+
url=url,
75+
status_code=HTTPStatus.FORBIDDEN,
76+
headers={"Content-Type": "application/json"},
77+
request_body=data,
78+
tell_position=0,
79+
content=text.encode(),
80+
)
81+
82+
4483
def test_image_too_large(
4584
*,
4685
vws_client: VWS,
@@ -106,9 +145,19 @@ def test_add_bad_name(
106145

107146
def test_request_quota_reached() -> None:
108147
"""
109-
See https://github.com/VWS-Python/vws-python/issues/822 for writing
110-
this test.
148+
A ``RequestQuotaReached`` exception is raised when Vuforia reports
149+
that the request quota has been reached.
111150
"""
151+
vws_client = VWS(
152+
server_access_key=uuid.uuid4().hex,
153+
server_secret_key=uuid.uuid4().hex,
154+
transport=_RequestQuotaReachedTransport(),
155+
)
156+
157+
with pytest.raises(expected_exception=RequestQuotaReachedError) as exc:
158+
vws_client.list_targets()
159+
160+
assert exc.value.response.status_code == HTTPStatus.FORBIDDEN
112161

113162

114163
def test_fail(high_quality_image: io.BytesIO) -> None:

0 commit comments

Comments
 (0)