Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/source/differences-to-vws.rst
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,12 @@ Some malformed State-Based Model Target configuration documents remain mock-only
Reco counts reports
-------------------

Vuforia documents ``POST /imagetargets/databases/{database_id}/reports/recoCounts``, and this endpoint previously worked against real Vuforia, so the mock continues to implement it.
The endpoint now returns an HTML 404 response for every database available to this project's test account, including a newly created database whose ID and server keys were read directly from the Target Manager.
This project treats that as a permanent limitation of its real-Vuforia test account.
The report tests therefore run against the mock backends only, including the cross-cutting authorization, date, content-length and JSON tests.
The mock remains useful for testing clients of the documented endpoint, but its behavior can no longer be compared continuously with the real service and may differ for accounts which can still use the endpoint.

The mock does not count recognitions, so a generated reco counts report contains only the ``target_id,reco_count`` header row, ending with a carriage return and a line feed, until recognition counts are set on targets.
That is what real Vuforia returns for a database with no recognitions.

Expand Down
10 changes: 10 additions & 0 deletions tests/mock_vws/fixtures/vuforia_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,11 @@ class VuforiaBackend(Enum):
"Real Vuforia can leave malformed-body requests open indefinitely; the "
"mock backends still verify this contract."
)
_RECO_COUNTS_REAL_NODE_ID_PART = "[Real Vuforia-reco_counts_report"
_RECO_COUNTS_REAL_SKIP_REASON = (
"The reco counts report endpoint is unavailable to the real-Vuforia "
"test account; the mock backends still verify this contract."
)


@beartype
Expand Down Expand Up @@ -453,9 +458,14 @@ def pytest_collection_modifyitems(
invalid_json_real_marker = pytest.mark.skip(
reason=_INVALID_JSON_REAL_SKIP_REASON,
)
reco_counts_real_marker = pytest.mark.skip(
reason=_RECO_COUNTS_REAL_SKIP_REASON,
)
for item in items:
if item.nodeid.startswith(_INVALID_JSON_REAL_NODE_ID_PREFIXES):
item.add_marker(marker=invalid_json_real_marker)
if _RECO_COUNTS_REAL_NODE_ID_PART in item.nodeid:
item.add_marker(marker=reco_counts_real_marker)


@beartype
Expand Down
15 changes: 5 additions & 10 deletions tests/mock_vws/test_reco_counts_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def _request_reco_counts_report(
request_path=request_path,
)

response = requests.post(
return requests.post(
url=_VWS_HOST + request_path,
headers={
"Authorization": authorization_string,
Expand All @@ -119,11 +119,6 @@ def _request_reco_counts_report(
data=content,
timeout=30,
)
if response.status_code == HTTPStatus.NOT_FOUND and response.headers.get(
"Content-Type", ""
).startswith("text/html"): # pragma: no cover
pytest.skip(reason="The real reco counts endpoint is unavailable.")
return response


@beartype
Expand Down Expand Up @@ -211,7 +206,7 @@ def _wait_for_report(*, presigned_url: str) -> requests.Response:
raise _ReportNotReadyError


@pytest.mark.usefixtures("verify_mock_vuforia")
@pytest.mark.usefixtures("mock_only_vuforia")
class TestRecoCountsReport:
"""Tests for requesting a reco counts report."""

Expand Down Expand Up @@ -429,12 +424,12 @@ def test_database_name_in_path(
)


@pytest.mark.usefixtures("verify_mock_vuforia")
@pytest.mark.usefixtures("mock_only_vuforia")
class TestDownloadReport:
"""Tests for downloading a generated reco counts report.

A real report has been observed ready within a second of being
requested, so these run against real Vuforia as well as the mocks.
The endpoint is unavailable to the real-Vuforia test account, so these
run against the mocks only.
"""

@staticmethod
Expand Down
16 changes: 2 additions & 14 deletions tests/mock_vws/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import secrets
from collections.abc import Mapping
from dataclasses import dataclass
from http import HTTPStatus
from typing import Literal
from urllib.parse import urljoin

Expand Down Expand Up @@ -104,23 +103,12 @@ class Endpoint:
@beartype
def send(self) -> Response:
"""Send the request."""
url = urljoin(base=self.base_url, url=self.path_url)
response = _send_request(
return _send_request(
method=self.method,
url=url,
url=urljoin(base=self.base_url, url=self.path_url),
headers=self.headers,
data=self.data,
)
if (
url.startswith("https://vws.vuforia.com/imagetargets/databases/")
and url.endswith("/reports/recoCounts")
and response.status_code == HTTPStatus.NOT_FOUND
and response.headers.get("Content-Type", "").startswith(
"text/html",
)
): # pragma: no cover
pytest.skip(reason="The real reco counts endpoint is unavailable.")
return response

@property
def auth_header_content_type(self) -> str:
Expand Down