Skip to content

Commit 68be37d

Browse files
Merge pull request #465 from adamtheturtle/better-matching
Better matching
2 parents f33c71b + 5be86d1 commit 68be37d

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

src/mock_vws/_mock_web_services_api.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
)
7373
from .target import Target
7474

75+
_TARGET_ID_PATTERN = '[A-Za-z0-9]+'
7576

7677
@wrapt.decorator
7778
def update_request_count(
@@ -327,7 +328,10 @@ def add_target(
327328
}
328329
return json_dump(body)
329330

330-
@route(path_pattern='/targets/.+', http_methods=[DELETE])
331+
@route(
332+
path_pattern=f'/targets/{_TARGET_ID_PATTERN}',
333+
http_methods=[DELETE],
334+
)
331335
def delete_target(
332336
self,
333337
request: _RequestObjectProxy, # pylint: disable=unused-argument
@@ -462,7 +466,7 @@ def target_list(
462466
}
463467
return json_dump(body)
464468

465-
@route(path_pattern='/targets/.+', http_methods=[GET])
469+
@route(path_pattern=f'/targets/{_TARGET_ID_PATTERN}', http_methods=[GET])
466470
def get_target(
467471
self,
468472
request: _RequestObjectProxy, # pylint: disable=unused-argument
@@ -492,7 +496,10 @@ def get_target(
492496
}
493497
return json_dump(body)
494498

495-
@route(path_pattern='/duplicates/.+', http_methods=[GET])
499+
@route(
500+
path_pattern=f'/duplicates/{_TARGET_ID_PATTERN}',
501+
http_methods=[GET],
502+
)
496503
def get_duplicates(
497504
self,
498505
request: _RequestObjectProxy,
@@ -530,7 +537,7 @@ def get_duplicates(
530537
return json_dump(body)
531538

532539
@route(
533-
path_pattern='/targets/.+',
540+
path_pattern=f'/targets/{_TARGET_ID_PATTERN}',
534541
http_methods=[PUT],
535542
optional_keys={
536543
'active_flag',
@@ -630,7 +637,7 @@ def update_target(
630637
}
631638
return json_dump(body)
632639

633-
@route(path_pattern='/summary/.+', http_methods=[GET])
640+
@route(path_pattern=f'/summary/{_TARGET_ID_PATTERN}', http_methods=[GET])
634641
def target_summary(
635642
self,
636643
request: _RequestObjectProxy,

tests/mock_vws/test_delete_target.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def test_inactive_project(
9898
"""
9999
If the project is inactive, a FORBIDDEN response is returned.
100100
"""
101-
target_id = 'does_not_exist'
101+
target_id = 'abc12345a'
102102
response = delete_target(
103103
vuforia_database=inactive_database,
104104
target_id=target_id,

tests/mock_vws/test_get_target.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ def test_get_vws_target(
9999
assert target_record['tracking_rating'] in range(-1, 6)
100100
assert target_record['reco_rating'] == ''
101101

102+
def test_get_vws_target_with_slash(
103+
self,
104+
vuforia_database: VuforiaDatabase,
105+
image_file_failed_state: io.BytesIO,
106+
) -> None:
107+
"""
108+
Details of a target are returned.
109+
"""
110+
# response = get_vws_target(
111+
# target_id='x/1',
112+
# vuforia_database=vuforia_database,
113+
# )
114+
# import pdb; pdb.set_trace()
115+
#
102116
def test_active_flag_not_set(
103117
self,
104118
vuforia_database: VuforiaDatabase,

tests/mock_vws/test_usage.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def test_default(
412412
)
413413

414414
expected = 0.2
415-
assert abs(expected - recognize_deletion_seconds) < 0.1
415+
assert abs(expected - recognize_deletion_seconds) < 0.15
416416

417417
def test_with_no_processing_time(
418418
self,
@@ -430,7 +430,7 @@ def test_with_no_processing_time(
430430
)
431431

432432
expected = 0.2
433-
assert abs(expected - recognize_deletion_seconds) < 0.1
433+
assert abs(expected - recognize_deletion_seconds) < 0.15
434434

435435
def test_custom(
436436
self,
@@ -453,7 +453,7 @@ def test_custom(
453453
)
454454

455455
expected = query_recognizes_deletion
456-
assert abs(expected - recognize_deletion_seconds) < 0.1
456+
assert abs(expected - recognize_deletion_seconds) < 0.15
457457

458458

459459
class TestCustomQueryProcessDeletionSeconds:

0 commit comments

Comments
 (0)