Skip to content
This repository was archived by the owner on Oct 30, 2026. It is now read-only.
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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ newsfragments
secrets.tar.gpg
spelling_private_dict.txt
tests
server/tests
vuforia_secrets.env.example
zizmor.yml

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ jobs:
- tests/mock_vws/requests_mock
- tests/mock_vws/respx_mock
- tests/mock_vws/httpx2_mock
- tests/mock_vws/flask_app
- tests/mock_vws/test_healthcheck.py
- tests/mock_vws/test_docker.py
- server/tests/vws_mock_server_tests/flask_app
- server/tests/vws_mock_server_tests/test_healthcheck.py
- server/tests/vws_mock_server_tests/test_docker.py
- README.rst
- docs/

Expand Down Expand Up @@ -170,7 +170,7 @@ jobs:
# We have seen issues with running out of disk space on test_docker
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
if: matrix.ci_pattern == 'tests/mock_vws/test_docker.py'
if: matrix.ci_pattern == 'server/tests/vws_mock_server_tests/test_docker.py'
with:
# All of these default to true (meaning they are removed).
docker-images: false
Expand Down
7 changes: 7 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@
],
patterns=["*.rst", "*.py"],
).pytest()


# Load shared fixtures for both core and server tests.
pytest_plugins = [
"vws_mock_contract_tests.fixtures.plugin",
"vws_mock_test_backends.vuforia_backends",
]
4 changes: 3 additions & 1 deletion contract-tests/consumer/test_installed_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ def test_installed_suite(
)
health_tests = tmp_path / "test_server_health.py"
_ = shutil.copyfile(
src=repository / "tests/mock_vws/test_healthcheck.py", dst=health_tests
src=repository
/ "server/tests/vws_mock_server_tests/test_healthcheck.py",
dst=health_tests,
)
_run(args=[python, "-m", "pytest", health_tests, "-q"], cwd=tmp_path)
_run(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Helpers for testing the usage of the mocks."""

import datetime as dt
import io

from beartype import beartype
from vws import VWS
from vws.reports import TargetStatuses

from vws_mock_contract_tests.fixtures.credentials import (
CloudDatabaseCredentials,
)


@beartype
def processing_time_seconds(
*,
vuforia_database: CloudDatabaseCredentials,
base_vws_url: str,
image: io.BytesIO,
) -> float:
"""Return the time taken to process a target in the database."""
vws_client = VWS(
base_vws_url=base_vws_url,
server_access_key=vuforia_database.server_access_key,
server_secret_key=vuforia_database.server_secret_key,
)
target_id = vws_client.add_target(
name="example",
width=1,
image=image,
active_flag=True,
application_metadata=None,
)
start_time = dt.datetime.now(tz=dt.UTC)

while (
vws_client.get_target_record(target_id=target_id).status
== TargetStatuses.PROCESSING
):
pass

processing_time = dt.datetime.now(tz=dt.UTC) - start_time
return processing_time.total_seconds()
2 changes: 1 addition & 1 deletion prek.toml
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ hooks = [
{
id = "pylint",
name = "pylint",
entry = "uv run --group=dev -m pylint *.py src/ tests/ server/src/ contract-tests/src/ contract-tests/consumer/ test-backends/src/ docs/ ci/ admin/",
entry = "uv run --group=dev -m pylint *.py src/ tests/ server/src/ server/tests/ contract-tests/src/ contract-tests/consumer/ test-backends/src/ docs/ ci/ admin/",
language = "python",
stages = ["manual"],
pass_filenames = false,
Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ lint.per-file-ignores."doccmd_*.py" = [
# Allow asserts in docs.
"S101",
]
lint.per-file-ignores."server/tests/**" = [ "S101", "S105", "S106" ]
lint.per-file-ignores."test-backends/src/**" = [ "S101", "S105", "S106" ]
lint.per-file-ignores."tests/**" = [
# Allow asserts in tests.
Expand Down Expand Up @@ -375,6 +376,7 @@ ignore = [
"prek.toml",
"secrets.tar.gpg",
"server/Dockerfile",
"server/tests/**",
"spelling_private_dict.txt",
"styles/snapper/*.yml",
"tests",
Expand Down Expand Up @@ -514,14 +516,14 @@ markers = [
"requires_docker_build",
]
# Legacy import modules keep the existing CI partitions stable.
norecursedirs = [ "contract-tests", "server", "test-backends" ]
norecursedirs = [ "contract-tests", "test-backends" ]
# Options for pytest-retry.
retries = "10"
retry_delay = "10"
xfail_strict = true

[tool.coverage]
run.source = [ "ci/", "contract-tests/src/", "server/src/", "src/", "test-backends/src/", "tests/" ]
run.source = [ "ci/", "contract-tests/src/", "server/src/", "server/tests/", "src/", "test-backends/src/", "tests/" ]
# Import-only compatibility modules contain no assertions or backend logic.
# Their authoritative implementations remain subject to full coverage.
run.omit = [
Expand All @@ -543,6 +545,7 @@ run.omit = [
"tests/mock_vws/utils/retries.py",
"tests/mock_vws/utils/too_many_requests.py",
"tests/mock_vws/utils/unrouted_requests.py",
"tests/mock_vws/utils/usage_test_helpers.py",
]
run.branch = true
run.parallel = true
Expand Down
15 changes: 15 additions & 0 deletions server/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,18 @@ The published images continue to probe the local service on port 5000:

The probe accepts the existing unauthorized, forbidden and missing-route responses as healthy.
It fails on connection errors, timeouts and other HTTP statuses.

Development tests
-----------------

The server project owns its Flask, health-check and container deployment tests.
Run them from the workspace root:

.. code-block:: console

$ uv run --group=dev pytest server/tests --skip-backend=real

The Docker tests build and start all three services and require a running Docker daemon.
For the Flask and health-check cases alone, add ``--skip-marker=requires_docker_build``.
The shared fixtures are loaded explicitly from the installed contract package.
Shared API assertions remain maintained in that package.
1 change: 1 addition & 0 deletions server/tests/vws_mock_server_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Tests owned by the server project."""
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from beartype import beartype
from requests_mock_flask import add_flask_app_to_mock

from mock_vws._flask_server.target_manager import (
from vws_mock_server.target_manager import (
TARGET_MANAGER,
TARGET_MANAGER_FLASK_APP,
)
from mock_vws._flask_server.vwq import CLOUDRECO_FLASK_APP
from mock_vws._flask_server.vws import VWS_FLASK_APP
from vws_mock_server.vwq import CLOUDRECO_FLASK_APP
from vws_mock_server.vws import VWS_FLASK_APP


@beartype
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
from pydantic import JsonValue, TypeAdapter
from werkzeug.serving import BaseWSGIServer, make_server

from mock_vws._flask_server.target_manager import (
from mock_vws.database import CloudDatabase
from vws_mock_server.target_manager import (
TARGET_MANAGER,
TARGET_MANAGER_FLASK_APP,
)
from mock_vws.database import CloudDatabase

_NUM_WRITER_THREADS = 4
_NUM_READER_THREADS = 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
from pydantic import JsonValue, TypeAdapter
from vws import VWS, CloudRecoService

from mock_vws._flask_server.target_manager import (
TARGET_MANAGER,
)
from mock_vws.database import CloudDatabase, VuMarkDatabase
from mock_vws.target import VuMarkTarget
from vws_mock_server.target_manager import (
TARGET_MANAGER,
)


def test_add_cloud_database_duplicate_keys(target_manager_url: str) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import requests
from pydantic import JsonValue, TypeAdapter

from mock_vws._flask_server import target_manager as flask_target_manager
from mock_vws.model_target import (
ModelTargetDataset,
ModelTargetDatasetType,
ModelTargetGenerationFailure,
ModelTargetGenerationWarning,
)
from vws_mock_server import target_manager as flask_target_manager

_MODEL_TARGET_DATASET_REQUEST: dict[str, JsonValue] = {
"name": "dataset-name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import requests

from mock_vws.database import CloudDatabase
from tests.mock_vws.utils.usage_test_helpers import (
from vws_mock_contract_tests.utils.usage_test_helpers import (
processing_time_seconds,
)

Expand Down
36 changes: 36 additions & 0 deletions server/tests/vws_mock_server_tests/flask_app/test_routing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Tests for routing through the Flask app.

Tests for requests which the Flask app does not route.

Signed requests are covered by
``tests/mock_vws/invalid_given_id``, which verifies the
responses against real Vuforia.
"""

from http import HTTPStatus

from mock_vws._flask_server import target_manager as legacy_target_manager
from mock_vws._flask_server import vwq as legacy_vwq
from mock_vws._flask_server import vws as legacy_vws
from vws_mock_server.target_manager import TARGET_MANAGER_FLASK_APP
from vws_mock_server.vwq import CLOUDRECO_FLASK_APP
from vws_mock_server.vws import VWS_FLASK_APP


def test_unauthenticated_unknown_path() -> None:
"""A request to a path which is not routed returns a 404 even
without credentials.

The Docker health check relies on this request returning a
response.
"""
# Compatibility imports must share the same applications and state.
assert legacy_vws.VWS_FLASK_APP is VWS_FLASK_APP
assert legacy_vwq.CLOUDRECO_FLASK_APP is CLOUDRECO_FLASK_APP
assert (
legacy_target_manager.TARGET_MANAGER_FLASK_APP
is TARGET_MANAGER_FLASK_APP
)
response = VWS_FLASK_APP.test_client().get("/some-random-endpoint")

assert response.status_code == HTTPStatus.NOT_FOUND
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def fixture_mock_deployment() -> Iterator[_MockDeployment]:
"""
repository_root = str(
object=find_root(
criterion=has_file(file="pyproject.toml"),
criterion=has_file(file="docker-bake.hcl"),
start=Path(__file__).resolve(),
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
from flask import Flask, Response
from werkzeug.serving import make_server

from mock_vws._flask_server.healthcheck import flask_app_healthy
from mock_vws._flask_server.healthcheck import (
flask_app_healthy as legacy_flask_app_healthy,
)
from vws_mock_server.healthcheck import flask_app_healthy

_HEALTH_CHECK_DEADLINE_SECONDS = 10

Expand Down Expand Up @@ -117,6 +120,7 @@ def test_healthy(*, status: HTTPStatus) -> None:
"""An app which handles a request for an unknown endpoint is
healthy.
"""
assert legacy_flask_app_healthy is flask_app_healthy
with _app_responding_with(status=status) as port:
assert flask_app_healthy(port=port)

Expand Down
8 changes: 0 additions & 8 deletions tests/conftest.py

This file was deleted.

24 changes: 0 additions & 24 deletions tests/mock_vws/flask_app/test_routing.py

This file was deleted.

45 changes: 5 additions & 40 deletions tests/mock_vws/utils/usage_test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,7 @@
"""Helpers for testing the usage of the mocks."""
"""Compatibility imports for shared mock usage helpers."""

import datetime as dt
import io
from vws_mock_contract_tests.utils.usage_test_helpers import (
processing_time_seconds,
)

from beartype import beartype
from vws import VWS
from vws.reports import TargetStatuses

from tests.mock_vws.fixtures.credentials import CloudDatabaseCredentials


@beartype
def processing_time_seconds(
*,
vuforia_database: CloudDatabaseCredentials,
base_vws_url: str,
image: io.BytesIO,
) -> float:
"""Return the time taken to process a target in the database."""
vws_client = VWS(
base_vws_url=base_vws_url,
server_access_key=vuforia_database.server_access_key,
server_secret_key=vuforia_database.server_secret_key,
)
target_id = vws_client.add_target(
name="example",
width=1,
image=image,
active_flag=True,
application_metadata=None,
)
start_time = dt.datetime.now(tz=dt.UTC)

while (
vws_client.get_target_record(target_id=target_id).status
== TargetStatuses.PROCESSING
):
pass

processing_time = dt.datetime.now(tz=dt.UTC) - start_time
return processing_time.total_seconds()
__all__ = ["processing_time_seconds"]
Loading