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
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ recursive-include contract-tests/src *.py py.typed
recursive-include contract-tests/consumer *.py *.ini
include test-backends/pyproject.toml test-backends/README.rst test-backends/LICENSE
recursive-include test-backends/src *.py py.typed
include server/pyproject.toml server/README.rst server/LICENSE
recursive-include server/src *.py py.typed
14 changes: 14 additions & 0 deletions contract-tests/consumer/core_checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Check that the core wheel works without the Flask server extra."""

import importlib.util

from mock_vws import MockVWS

__all__ = ["pytest_sessionstart"]


def pytest_sessionstart() -> None:
"""Import and enter the core mock without a Flask installation."""
assert importlib.util.find_spec(name="flask") is None
with MockVWS():
pass
22 changes: 22 additions & 0 deletions contract-tests/consumer/test_installed_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def test_installed_suite(
for filename in (
"pytest.ini",
"dependency_checks.py",
"core_checks.py",
"contract_checks.py",
):
_ = shutil.copyfile(src=consumer / filename, dst=tmp_path / filename)
Expand All @@ -63,6 +64,22 @@ def test_installed_suite(
],
cwd=tmp_path,
)
core = next(dist.glob(pattern="vws_python_mock-*.whl"))
_run(args=[uv, "pip", "install", "--python", python, core], cwd=tmp_path)
_run(
args=[
python,
"-m",
"pytest",
"-p",
"core_checks",
"--pyargs",
"vws_mock_contract_tests.database_summary",
"--collect-only",
"-q",
],
cwd=tmp_path,
)
_run(
args=[
uv,
Expand All @@ -74,6 +91,11 @@ def test_installed_suite(
],
cwd=tmp_path,
)
health_tests = tmp_path / "test_server_health.py"
_ = shutil.copyfile(
src=repository / "tests/mock_vws/test_healthcheck.py", dst=health_tests
)
_run(args=[python, "-m", "pytest", health_tests, "-q"], cwd=tmp_path)
_run(
args=[
python,
Expand Down
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.
./contract-tests
./test-backends
./server
2 changes: 1 addition & 1 deletion prek.toml
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ hooks = [
{
id = "pylint",
name = "pylint",
entry = "uv run --group=dev -m pylint *.py src/ tests/ contract-tests/src/ contract-tests/consumer/ test-backends/src/ docs/ ci/ admin/",
entry = "uv run --group=dev -m pylint *.py src/ tests/ server/src/ contract-tests/src/ contract-tests/consumer/ test-backends/src/ docs/ ci/ admin/",
language = "python",
stages = ["manual"],
pass_filenames = false,
Expand Down
12 changes: 7 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ dynamic = [
]
dependencies = [
"beartype>=0.23.0",
"flask>=3.0.3",
"httpx>=0.27.0",
"httpx2>=2.12",
"mock-response-delay>=2026.9.12",
Expand All @@ -52,6 +51,7 @@ dependencies = [
"vws-auth-tools>=2024.7.12",
"werkzeug>=3.1.2",
]
optional-dependencies.server = [ "flask>=3.0.3", "vws-python-mock-server==0.0.0" ]
urls.Documentation = "https://vws-python.github.io/vws-python-mock/"
urls.Source = "https://github.com/VWS-Python/vws-python-mock"

Expand Down Expand Up @@ -134,6 +134,7 @@ dev = [
"vws-mock-contract-tests==0.0.0",
"vws-mock-test-backends==0.0.0",
"vws-python==2026.10.9",
"vws-python-mock-server==0.0.0",
"vws-test-fixtures==2026.10.8",
"vws-web-tools==2026.8.27",
"yamlfix==1.19.1",
Expand Down Expand Up @@ -168,11 +169,12 @@ fallback_version = "0.0.0"
sources.vws-mock-contract-tests = { workspace = true }
sources.vws-mock-test-backends = { workspace = true }
sources.vws-python-mock = { workspace = true }
workspace.members = [ "contract-tests", "test-backends" ]
sources.vws-python-mock-server = { workspace = true }
workspace.members = [ "contract-tests", "server", "test-backends" ]

[tool.ruff]
line-length = 79
src = [ "contract-tests/src", "src", "test-backends/src" ]
src = [ "contract-tests/src", "server/src", "src", "test-backends/src" ]
lint.select = [
"ALL",
]
Expand Down Expand Up @@ -513,14 +515,14 @@ markers = [
"requires_docker_build",
]
# Legacy import modules keep the existing CI partitions stable.
norecursedirs = [ "contract-tests", "test-backends" ]
norecursedirs = [ "contract-tests", "server", "test-backends" ]
# Options for pytest-retry.
retries = "10"
retry_delay = "10"
xfail_strict = true

[tool.coverage]
run.source = [ "ci/", "contract-tests/src/", "src/", "test-backends/src/", "tests/" ]
run.source = [ "ci/", "contract-tests/src/", "server/src/", "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 Down
21 changes: 21 additions & 0 deletions server/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Adam Dangoor

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
39 changes: 39 additions & 0 deletions server/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
VWS mock server
===============

This separately buildable project owns server code while it is prepared for extraction.
The health probe is migrated first.
The three Flask services follow in separate changes.
Shared models, validation and API behavior stay in ``vws-python-mock``.

Build and install
-----------------

Build the workspace wheels and install them together:

.. code-block:: console

$ uv build --all-packages --wheel --out-dir dist
$ uv pip install dist/*.whl

The initial server version is ``0.0.0``.
Build the server and core library from the same repository commit.
For a Git installation, use that revision and the ``server`` subdirectory for this project.
The core's ``server`` extra selects this package and Flask when they are available in the workspace or as built wheels.
The default core installation does not require Flask.

The server consumes public core models and ``mock_vws.server_api``.
Its runtime dependencies do not include the contract suite or test adapters.
Consumers load those development dependencies explicitly.

Health checks
-------------

The published images continue to probe the local service on port 5000:

.. code-block:: console

$ python -m vws_mock_server.healthcheck

The probe accepts the existing unauthorized, forbidden and missing-route responses as healthy.
It fails on connection errors, timeouts and other HTTP statuses.
31 changes: 31 additions & 0 deletions server/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[build-system]
build-backend = "setuptools.build_meta"
requires = [ "setuptools" ]

[project]
name = "vws-python-mock-server"
version = "0.0.0"
description = "Flask services for the Vuforia Web Services mock."
readme = "README.rst"
license = "MIT"
license-files = [ "LICENSE" ]
authors = [ { name = "Adam Dangoor", email = "adamdangoor@gmail.com" } ]
requires-python = ">=3.15"
classifiers = [
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.15",
]
dependencies = [
"beartype>=0.23.1",
"flask>=3.0.3",
"pydantic>=2.6",
"pydantic-settings>=2.6.1",
"requests>=2.32.3",
"vws-python-mock",
"werkzeug>=3.1.2",
]
urls.Source = "https://github.com/VWS-Python/vws-python-mock"

[tool.setuptools]
packages.find.where = [ "src" ]
package-data.vws_mock_server = [ "py.typed" ]
1 change: 1 addition & 0 deletions server/src/vws_mock_server/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Flask services and deployment helpers for the VWS mock."""
35 changes: 35 additions & 0 deletions server/src/vws_mock_server/healthcheck.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Health check for the Flask server."""

import http.client
import sys
from http import HTTPStatus

from beartype import beartype


@beartype
def flask_app_healthy(port: int) -> bool:
"""Check if the Flask app is healthy."""
conn = http.client.HTTPConnection(host="localhost", port=port, timeout=5)
try:
conn.request(method="GET", url="/some-random-endpoint")
response = conn.getresponse()
# ``OSError`` covers ``TimeoutError``, ``ConnectionRefusedError`` and
# ``socket.gaierror``.
# ``ConnectionRefusedError`` is the expected error while the container is
# starting up and nothing is yet listening on the port.
except OSError, http.client.HTTPException:
return False
finally:
conn.close()

return response.status in {
HTTPStatus.NOT_FOUND,
HTTPStatus.UNAUTHORIZED,
HTTPStatus.FORBIDDEN,
}


# Containers execute this process entry point; import-driven tests use its API.
if __name__ == "__main__": # pragma: no cover
sys.exit(int(not flask_app_healthy(port=5000)))
Empty file.
6 changes: 3 additions & 3 deletions src/mock_vws/_flask_server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ WORKDIR /app
# Install the locked dependencies before copying the source, so that
# source edits do not invalidate the dependency layer.
COPY --chown=10001:10001 pyproject.toml uv.lock /app/
RUN uv sync --frozen --no-cache --no-dev --no-install-workspace
RUN uv sync --frozen --no-cache --no-dev --extra server --no-install-workspace
COPY --chown=10001:10001 . /app
RUN uv sync --locked --no-cache --no-dev
RUN uv sync --locked --no-cache --no-dev --extra server
EXPOSE 5000
ENTRYPOINT ["python"]
HEALTHCHECK --interval=1s --timeout=10s --start-period=5s --retries=3 CMD ["python", "/app/src/mock_vws/_flask_server/healthcheck.py"]
HEALTHCHECK --interval=1s --timeout=10s --start-period=5s --retries=3 CMD ["python", "-m", "vws_mock_server.healthcheck"]

FROM base AS vws
ENV VWS_HOST=0.0.0.0
Expand Down
29 changes: 3 additions & 26 deletions src/mock_vws/_flask_server/healthcheck.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,10 @@
"""Health check for the Flask server."""
"""Compatibility import for the server package's health check."""

import http.client
import sys
from http import HTTPStatus

from beartype import beartype
from vws_mock_server.healthcheck import flask_app_healthy


@beartype
def flask_app_healthy(port: int) -> bool:
"""Check if the Flask app is healthy."""
conn = http.client.HTTPConnection(host="localhost", port=port, timeout=5)
try:
conn.request(method="GET", url="/some-random-endpoint")
response = conn.getresponse()
# ``OSError`` covers ``TimeoutError``, ``ConnectionRefusedError`` and
# ``socket.gaierror``.
# ``ConnectionRefusedError`` is the expected error while the container is
# starting up and nothing is yet listening on the port.
except OSError, http.client.HTTPException:
return False
finally:
conn.close()

return response.status in {
HTTPStatus.NOT_FOUND,
HTTPStatus.UNAUTHORIZED,
HTTPStatus.FORBIDDEN,
}
__all__ = ["flask_app_healthy"]


# Containers execute this process entry point; import-driven tests use its API.
Expand Down
2 changes: 1 addition & 1 deletion test-backends/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies = [
"urllib3>=2.8",
"vws-mock-contract-tests==0",
"vws-python>=2026.10.9",
"vws-python-mock",
"vws-python-mock[server]",
]
urls.Source = "https://github.com/VWS-Python/vws-python-mock"

Expand Down
Loading
Loading