Skip to content

Commit 33be5da

Browse files
committed
Remove unnecessary query parameters and tests for them
1 parent f16d2e7 commit 33be5da

File tree

10 files changed

+24
-539
lines changed

10 files changed

+24
-539
lines changed

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ dependencies = [
277277
"requests-mock",
278278
"tzdata; sys_platform == 'win32'",
279279
"vws-auth-tools",
280-
"werkzeug",
281280
]
282281

283282
[project.optional-dependencies]
@@ -319,7 +318,10 @@ dev = [
319318
"types-PyYAML==6.0.12.9",
320319
"types-Pillow==9.5.0.4",
321320
"types-requests==2.30.0.0",
322-
"urllib3==2.0.2",
321+
# We need urllib3 < 2.0.0 for pdm to work.
322+
# After we can bump urllib3, we can remove types-urllib.
323+
"types-urllib3==1.26.25.13",
324+
"urllib3<2.0.0",
323325
"vulture==2.7",
324326
"vws-python==2023.3.25",
325327
]

src/mock_vws/_flask_server/vwq.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515
from werkzeug.datastructures import Headers
1616

1717
from mock_vws._query_tools import (
18-
ActiveMatchingTargetsDeleteProcessing,
1918
get_query_match_response_text,
2019
)
2120
from mock_vws._query_validators import run_query_validators
2221
from mock_vws._query_validators.exceptions import (
23-
DeletedTargetMatched,
2422
ValidatorException,
2523
)
2624
from mock_vws.database import VuforiaDatabase
@@ -55,8 +53,6 @@ class VWQSettings(BaseSettings):
5553

5654
vwq_host: str = ""
5755
target_manager_base_url: str
58-
deletion_processing_seconds: float = 3.0
59-
deletion_recognition_seconds: float = 2.0
6056
query_image_matcher: _ImageMatcherChoice = _ImageMatcherChoice.AVERAGE_HASH
6157

6258

@@ -128,21 +124,14 @@ def query() -> Response:
128124
)
129125
date = email.utils.formatdate(None, localtime=False, usegmt=True)
130126

131-
try:
132-
response_text = get_query_match_response_text(
133-
request_headers=dict(request.headers),
134-
request_body=request_body,
135-
request_method=request.method,
136-
request_path=request.path,
137-
databases=databases,
138-
query_processes_deletion_seconds=settings.deletion_processing_seconds,
139-
query_recognizes_deletion_seconds=(
140-
settings.deletion_recognition_seconds
141-
),
142-
query_match_checker=query_match_checker,
143-
)
144-
except ActiveMatchingTargetsDeleteProcessing as exc:
145-
raise DeletedTargetMatched from exc
127+
response_text = get_query_match_response_text(
128+
request_headers=dict(request.headers),
129+
request_body=request_body,
130+
request_method=request.method,
131+
request_path=request.path,
132+
databases=databases,
133+
query_match_checker=query_match_checker,
134+
)
146135

147136
headers = {
148137
"Content-Type": "application/json",

src/mock_vws/_query_tools.py

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,12 @@
2424
from mock_vws.image_matchers import ImageMatcher
2525

2626

27-
class ActiveMatchingTargetsDeleteProcessing(Exception):
28-
"""
29-
There is at least one active target which matches and was recently deleted.
30-
"""
31-
32-
3327
def get_query_match_response_text(
3428
request_headers: dict[str, str],
3529
request_body: bytes,
3630
request_method: str,
3731
request_path: str,
3832
databases: set[VuforiaDatabase],
39-
query_processes_deletion_seconds: int | float,
40-
query_recognizes_deletion_seconds: int | float,
4133
query_match_checker: ImageMatcher,
4234
) -> str:
4335
"""
@@ -47,21 +39,11 @@ def get_query_match_response_text(
4739
request_body: The body of the request.
4840
request_method: The HTTP method of the request.
4941
databases: All Vuforia databases.
50-
query_recognizes_deletion_seconds: The number of seconds after a target
51-
has been deleted that the query endpoint will still recognize the
52-
target for.
53-
query_processes_deletion_seconds: The number of seconds after a target
54-
deletion is recognized that the query endpoint will return a 500
55-
response on a match.
5642
query_match_checker: A callable which takes two image values and
5743
returns whether they match.
5844
5945
Returns:
6046
The response text for a query endpoint request.
61-
62-
Raises:
63-
ActiveMatchingTargetsDeleteProcessing: There is at least one active
64-
target which matches and was recently deleted.
6547
"""
6648
body_file = io.BytesIO(request_body)
6749

@@ -88,15 +70,7 @@ def get_query_match_response_text(
8870
assert image_part is not None
8971
image_value = image_part.raw
9072
gmt = ZoneInfo("GMT")
91-
now = datetime.datetime.now(tz=gmt)
92-
93-
processing_timedelta = datetime.timedelta(
94-
seconds=query_processes_deletion_seconds,
95-
)
96-
97-
recognition_timedelta = datetime.timedelta(
98-
seconds=query_recognizes_deletion_seconds,
99-
)
73+
datetime.datetime.now(tz=gmt)
10074

10175
database = get_database_matching_client_keys(
10276
request_headers=request_headers,
@@ -125,28 +99,7 @@ def get_query_match_response_text(
12599
and target.status == TargetStatuses.SUCCESS.value
126100
]
127101

128-
deletion_not_recognized_matches = [
129-
target
130-
for target in matching_targets
131-
if target.active_flag
132-
and target.delete_date
133-
and (now - target.delete_date) < recognition_timedelta
134-
]
135-
136-
active_matching_targets_delete_processing = [
137-
target
138-
for target in matching_targets
139-
if target.active_flag
140-
and target.delete_date
141-
and (now - target.delete_date)
142-
< (recognition_timedelta + processing_timedelta)
143-
and target not in deletion_not_recognized_matches
144-
]
145-
146-
if active_matching_targets_delete_processing:
147-
raise ActiveMatchingTargetsDeleteProcessing
148-
149-
all_quality_matches = not_deleted_matches + deletion_not_recognized_matches
102+
all_quality_matches = not_deleted_matches
150103
minimum_rating = 0
151104
matches = [
152105
match

src/mock_vws/_requests_mock_server/decorators.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ def __init__(
4343
duplicate_match_checker: ImageMatcher = _AVERAGE_HASH_MATCHER,
4444
query_match_checker: ImageMatcher = _AVERAGE_HASH_MATCHER,
4545
processing_time_seconds: int | float = 2,
46-
query_recognizes_deletion_seconds: int | float = 2,
47-
query_processes_deletion_seconds: int | float = 3,
4846
target_tracking_rater: TargetTrackingRater = _BRISQUE_TRACKING_RATER,
4947
*,
5048
real_http: bool = False,
@@ -62,12 +60,6 @@ def __init__(
6260
In the real Vuforia Web Services, this is not deterministic.
6361
base_vwq_url: The base URL for the VWQ API.
6462
base_vws_url: The base URL for the VWS API.
65-
query_recognizes_deletion_seconds: The number
66-
of seconds after a target has been deleted that the query
67-
endpoint will still recognize the target for.
68-
query_processes_deletion_seconds: The number of
69-
seconds after a target deletion is recognized that the query
70-
endpoint will return a 500 response on a match.
7163
query_match_checker: A callable which takes two image values and
7264
returns whether they will match in a query request.
7365
duplicate_match_checker: A callable which takes two image values
@@ -104,12 +96,6 @@ def __init__(
10496

10597
self._mock_vwq_api = MockVuforiaWebQueryAPI(
10698
target_manager=self._target_manager,
107-
query_processes_deletion_seconds=(
108-
query_processes_deletion_seconds
109-
),
110-
query_recognizes_deletion_seconds=(
111-
query_recognizes_deletion_seconds
112-
),
11399
query_match_checker=query_match_checker,
114100
)
115101

src/mock_vws/_requests_mock_server/mock_web_query_api.py

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@
1414

1515
from mock_vws._mock_common import Route
1616
from mock_vws._query_tools import (
17-
ActiveMatchingTargetsDeleteProcessing,
1817
get_query_match_response_text,
1918
)
2019
from mock_vws._query_validators import run_query_validators
2120
from mock_vws._query_validators.exceptions import (
22-
DeletedTargetMatched,
2321
ValidatorException,
2422
)
2523

@@ -82,19 +80,11 @@ class MockVuforiaWebQueryAPI:
8280
def __init__(
8381
self,
8482
target_manager: TargetManager,
85-
query_recognizes_deletion_seconds: int | float,
86-
query_processes_deletion_seconds: int | float,
8783
query_match_checker: ImageMatcher,
8884
) -> None:
8985
"""
9086
Args:
9187
target_manager: The target manager which holds all databases.
92-
query_recognizes_deletion_seconds: The number of seconds after a
93-
target has been deleted that the query endpoint will still
94-
recognize the target for.
95-
query_processes_deletion_seconds: The number of seconds after a
96-
target deletion is recognized that the query endpoint will
97-
return a 500 response on a match.
9888
query_match_checker: A callable which takes two image values and
9989
returns whether they match.
10090
@@ -103,12 +93,6 @@ def __init__(
10393
"""
10494
self.routes: set[Route] = _ROUTES
10595
self._target_manager = target_manager
106-
self._query_processes_deletion_seconds = (
107-
query_processes_deletion_seconds
108-
)
109-
self._query_recognizes_deletion_seconds = (
110-
query_recognizes_deletion_seconds
111-
)
11296
self._query_match_checker = query_match_checker
11397

11498
@route(path_pattern="/v1/query", http_methods={POST})
@@ -133,26 +117,14 @@ def query(
133117
context.status_code = exc.status_code
134118
return exc.response_text
135119

136-
try:
137-
response_text = get_query_match_response_text(
138-
request_headers=request.headers,
139-
request_body=request.body,
140-
request_method=request.method,
141-
request_path=request.path,
142-
databases=self._target_manager.databases,
143-
query_processes_deletion_seconds=(
144-
self._query_processes_deletion_seconds
145-
),
146-
query_recognizes_deletion_seconds=(
147-
self._query_recognizes_deletion_seconds
148-
),
149-
query_match_checker=self._query_match_checker,
150-
)
151-
except ActiveMatchingTargetsDeleteProcessing:
152-
deleted_target_matched_exception = DeletedTargetMatched()
153-
context.headers = deleted_target_matched_exception.headers
154-
context.status_code = deleted_target_matched_exception.status_code
155-
return deleted_target_matched_exception.response_text
120+
response_text = get_query_match_response_text(
121+
request_headers=request.headers,
122+
request_body=request.body,
123+
request_method=request.method,
124+
request_path=request.path,
125+
databases=self._target_manager.databases,
126+
query_match_checker=self._query_match_checker,
127+
)
156128

157129
date = email.utils.formatdate(None, localtime=False, usegmt=True)
158130
context.headers = {

tests/mock_vws/jetty_error_deletion_not_complete.html

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)