Skip to content

Commit dd150c9

Browse files
Merge pull request #636 from adamtheturtle/test-query-success-false
Add test for querying a target with success: failed
2 parents 9736c90 + 778d5e3 commit dd150c9

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/mock_vws/_mock_web_query_api.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,10 @@ def query(
602602
content_type = 'text/html; charset=ISO-8859-1'
603603
context.headers['Content-Type'] = content_type
604604
return Path(match_processing_resp_file).read_text()
605-
if target.active_flag and not target.delete_date:
605+
if (
606+
target.active_flag and not target.delete_date
607+
and target.status == TargetStatuses.SUCCESS.value
608+
):
606609
matches.add(target)
607610

608611
results: List[Dict[str, Any]] = []

tests/mock_vws/test_query.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,3 +1511,47 @@ def test_deleted_inactive(
15111511

15121512
assert_query_success(response=response)
15131513
assert response.json()['results'] == []
1514+
1515+
1516+
@pytest.mark.usefixtures('verify_mock_vuforia')
1517+
class TestTargetStatusFailed:
1518+
"""
1519+
Tests for targets with the status "failed".
1520+
"""
1521+
1522+
def test_status_failed(
1523+
self,
1524+
png_rgb: io.BytesIO,
1525+
vuforia_database_keys: VuforiaDatabaseKeys,
1526+
) -> None:
1527+
"""
1528+
Targets with the status "failed" are not found in query results.
1529+
"""
1530+
image_content = png_rgb.getvalue()
1531+
image_data_encoded = base64.b64encode(image_content).decode('ascii')
1532+
add_target_data = {
1533+
'name': 'example_name',
1534+
'width': 1,
1535+
'image': image_data_encoded,
1536+
}
1537+
response = add_target_to_vws(
1538+
vuforia_database_keys=vuforia_database_keys,
1539+
data=add_target_data,
1540+
)
1541+
1542+
target_id = response.json()['target_id']
1543+
1544+
wait_for_target_processed(
1545+
target_id=target_id,
1546+
vuforia_database_keys=vuforia_database_keys,
1547+
)
1548+
1549+
body = {'image': ('image.jpeg', image_content, 'image/jpeg')}
1550+
1551+
response = query(
1552+
vuforia_database_keys=vuforia_database_keys,
1553+
body=body,
1554+
)
1555+
1556+
assert_query_success(response=response)
1557+
assert response.json()['results'] == []

0 commit comments

Comments
 (0)