Skip to content

Commit 940aaae

Browse files
Merge pull request #651 from adamtheturtle/test-duplicates-while-processing
Test duplicates while processing
2 parents 0ccec26 + 5475366 commit 940aaae

File tree

2 files changed

+79
-2
lines changed

2 files changed

+79
-2
lines changed

src/mock_vws/_mock_web_services_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,8 @@ def get_duplicates(
593593
other.target_id for other in other_targets
594594
if Image.open(other.image) == Image.open(target.image) and
595595
TargetStatuses.FAILED.value not in (target.status, other.status)
596-
and TargetStatuses.PROCESSING.value not in
597-
(target.status, other.status) and other.active_flag
596+
and TargetStatuses.PROCESSING.value != other.status
597+
and other.active_flag
598598
]
599599

600600
body = {

tests/mock_vws/test_get_duplicates.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,13 @@ def test_status(
194194

195195
assert response.json()['similar_targets'] == []
196196

197+
198+
@pytest.mark.usefixtures('verify_mock_vuforia')
199+
class TestActiveFlag:
200+
"""
201+
Tests for the effects of the active flag on duplicate matching.
202+
"""
203+
197204
def test_active_flag_duplicate(
198205
self,
199206
vuforia_database_keys: VuforiaDatabaseKeys,
@@ -302,3 +309,73 @@ def test_active_flag_original(
302309
)
303310

304311
assert response.json()['similar_targets'] == [similar_target_id]
312+
313+
314+
@pytest.mark.usefixtures('verify_mock_vuforia')
315+
class TestProcessing:
316+
"""
317+
Tests for targets in the processing stage.
318+
"""
319+
320+
def test_processing(
321+
self,
322+
vuforia_database_keys: VuforiaDatabaseKeys,
323+
high_quality_image: io.BytesIO,
324+
) -> None:
325+
"""
326+
If a target is in the processing state, it can have duplicates.
327+
Targets can have duplicates in the processing state.
328+
"""
329+
image_data = high_quality_image.read()
330+
image_data_encoded = base64.b64encode(image_data).decode('ascii')
331+
332+
data_1 = {
333+
'name': str(uuid.uuid4()),
334+
'width': 1,
335+
'image': image_data_encoded,
336+
}
337+
338+
data_2 = {
339+
'name': str(uuid.uuid4()),
340+
'width': 1,
341+
'image': image_data_encoded,
342+
}
343+
344+
resp_1 = add_target_to_vws(
345+
vuforia_database_keys=vuforia_database_keys,
346+
data=data_1,
347+
)
348+
349+
processed_target_id = resp_1.json()['target_id']
350+
351+
wait_for_target_processed(
352+
vuforia_database_keys=vuforia_database_keys,
353+
target_id=processed_target_id,
354+
)
355+
356+
resp_2 = add_target_to_vws(
357+
vuforia_database_keys=vuforia_database_keys,
358+
data=data_2,
359+
)
360+
361+
processing_target_id = resp_2.json()['target_id']
362+
363+
response = target_duplicates(
364+
vuforia_database_keys=vuforia_database_keys,
365+
target_id=processed_target_id,
366+
)
367+
368+
assert response.json()['similar_targets'] == []
369+
370+
response = target_duplicates(
371+
vuforia_database_keys=vuforia_database_keys,
372+
target_id=processing_target_id,
373+
)
374+
375+
status_response = get_vws_target(
376+
vuforia_database_keys=vuforia_database_keys,
377+
target_id=processing_target_id,
378+
)
379+
380+
assert status_response.json()['status'] == 'processing'
381+
assert response.json()['similar_targets'] == [processed_target_id]

0 commit comments

Comments
 (0)