Skip to content

Commit a0df2cb

Browse files
adamtheturtleclaude
andcommitted
Complete remaining todos: ResultCodes constants, spelling revert, retry
- Use ResultCodes.INVALID_ACCEPT_HEADER.value and ResultCodes.INVALID_INSTANCE_ID.value in test assertions instead of raw strings - Reword docstrings/docs to avoid acronyms that trigger the spell checker, and revert spelling_private_dict.txt to its pre-PR state - Replace one-off try/except retry in _delete_all_targets with a proper tenacity-based _delete_target_when_processed helper function Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 179450f commit a0df2cb

4 files changed

Lines changed: 34 additions & 17 deletions

File tree

docs/source/differences-to-vws.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,6 @@ The mock does not necessarily match Vuforia for all header cases.
111111
VuMark instance images
112112
----------------------
113113

114-
The mock returns a fixed minimal image in the requested format (PNG, SVG, or PDF).
114+
The mock returns a fixed minimal image in the requested format.
115115
The ``instance_id`` value is not encoded into the response image.
116116
Real Vuforia encodes the instance ID into the VuMark pattern.

spelling_private_dict.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ nat
6969
noqa
7070
outerboundary
7171
overridable
72-
pdf
7372
pdict
7473
plugins
7574
png
@@ -101,7 +100,6 @@ resjsonarr
101100
rfc
102101
rgb
103102
str
104-
svg
105103
timestamp
106104
todo
107105
travis

tests/mock_vws/fixtures/vuforia_backends.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import responses
1111
from beartype import beartype
1212
from requests_mock_flask import add_flask_app_to_mock
13+
from tenacity import retry
14+
from tenacity.retry import retry_if_exception_type
15+
from tenacity.wait import wait_fixed
1316
from vws import VWS
1417
from vws.exceptions.vws_exceptions import (
1518
TargetStatusNotSuccessError,
@@ -32,6 +35,25 @@
3235
LOGGER.setLevel(level=logging.DEBUG)
3336

3437

38+
@retry(
39+
retry=retry_if_exception_type(exception_types=TargetStatusProcessingError),
40+
wait=wait_fixed(wait=2),
41+
reraise=True,
42+
)
43+
def _delete_target_when_processed(*, vws_client: VWS, target_id: str) -> None:
44+
"""Wait for a target to finish processing, then delete it.
45+
46+
Retries if Vuforia briefly returns a processing state immediately
47+
after the prior wait completes (race condition after update_target).
48+
49+
Args:
50+
vws_client: The VWS client to use.
51+
target_id: The target to delete.
52+
"""
53+
vws_client.wait_for_target_processed(target_id=target_id)
54+
vws_client.delete_target(target_id=target_id)
55+
56+
3557
@RETRY_ON_TOO_MANY_REQUESTS
3658
def _delete_all_targets(*, database_keys: VuforiaDatabase) -> None:
3759
"""Delete all targets.
@@ -58,15 +80,7 @@ def _delete_all_targets(*, database_keys: VuforiaDatabase) -> None:
5880
# we change the target to inactive before deleting it.
5981
with contextlib.suppress(TargetStatusNotSuccessError):
6082
vws_client.update_target(target_id=target, active_flag=False)
61-
vws_client.wait_for_target_processed(target_id=target)
62-
# Vuforia may briefly return TargetStatusProcessing immediately
63-
# after wait_for_target_processed returns (race condition after
64-
# update_target triggers reprocessing), so retry once if needed.
65-
try:
66-
vws_client.delete_target(target_id=target)
67-
except TargetStatusProcessingError:
68-
vws_client.wait_for_target_processed(target_id=target)
69-
vws_client.delete_target(target_id=target)
83+
_delete_target_when_processed(vws_client=vws_client, target_id=target)
7084

7185

7286
@beartype

tests/mock_vws/test_vumark_generation_api.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import requests
99
from vws_auth_tools import authorization_header, rfc_1123_date
1010

11+
from mock_vws._constants import ResultCodes
1112
from tests.mock_vws.fixtures.credentials import VuMarkVuforiaDatabase
1213

1314
_VWS_HOST = "https://vws.vuforia.com"
@@ -84,9 +85,7 @@ def test_generate_instance_format(
8485
expected_signature: bytes,
8586
vumark_vuforia_database: VuMarkVuforiaDatabase,
8687
) -> None:
87-
"""A VuMark instance can be generated in PNG, SVG, or PDF
88-
format.
89-
"""
88+
"""A VuMark instance can be generated in the requested format."""
9089
response = _make_vumark_request(
9190
vumark_vuforia_database=vumark_vuforia_database,
9291
instance_id=uuid4().hex,
@@ -114,7 +113,10 @@ def test_invalid_accept_header(
114113

115114
assert response.status_code == HTTPStatus.BAD_REQUEST
116115
response_json = response.json()
117-
assert response_json["result_code"] == "InvalidAcceptHeader"
116+
assert (
117+
response_json["result_code"]
118+
== ResultCodes.INVALID_ACCEPT_HEADER.value
119+
)
118120

119121
@staticmethod
120122
def test_empty_instance_id(
@@ -129,4 +131,7 @@ def test_empty_instance_id(
129131

130132
assert response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY
131133
response_json = response.json()
132-
assert response_json["result_code"] == "InvalidInstanceId"
134+
assert (
135+
response_json["result_code"]
136+
== ResultCodes.INVALID_INSTANCE_ID.value
137+
)

0 commit comments

Comments
 (0)