vws-python-mock

Mocking calls made to Vuforia

$ pip install vws-python-mock

This requires Python 3.14+.

MockVWS intercepts requests to Vuforia made with requests, httpx or HTTPX2.

"""Make a request to the Vuforia Web Services API mock."""

import requests

from mock_vws import MockVWS
from mock_vws.database import CloudDatabase

with MockVWS() as mock:
    database = CloudDatabase()
    mock.add_cloud_database(cloud_database=database)
    # This will use the Vuforia mock.
    _ = requests.get(url="https://vws.vuforia.com/summary", timeout=30)

By default, an exception will be raised if any requests to unmocked addresses are made.

A MockVWS instance can also decorate a function:

"""Make a request to the Vuforia mock from a decorated function."""

import requests

from mock_vws import MockVWS
from mock_vws.database import CloudDatabase

mock = MockVWS()
mock.add_cloud_database(cloud_database=CloudDatabase())


@mock
def get_summary() -> None:
    """Make a request which uses the Vuforia mock."""
    _ = requests.get(url="https://vws.vuforia.com/summary", timeout=30)


get_summary()

Each call of a decorated function gets its own databases and targets, so decorated functions do not affect each other. A with block, by contrast, shares one set of databases and targets with every other use of the same instance.

See API Reference for details of what can be changed and how.

MockVWS also intercepts requests made with httpx.

"""Make a request to the Vuforia Web Services API mock using httpx."""

import httpx

from mock_vws import MockVWS
from mock_vws.database import CloudDatabase

with MockVWS() as mock:
    database = CloudDatabase()
    mock.add_cloud_database(cloud_database=database)
    # This will use the Vuforia mock.
    _ = httpx.get(url="https://vws.vuforia.com/summary", timeout=30)

MockVWS also intercepts requests made with HTTPX2, with no need for httpx2.alias_httpx().

"""Make a request to the Vuforia Web Services API mock using httpx2."""

import httpx2

from mock_vws import MockVWS
from mock_vws.database import CloudDatabase

with MockVWS() as mock:
    database = CloudDatabase()
    mock.add_cloud_database(cloud_database=database)
    # This will use the Vuforia mock.
    _ = httpx2.get(url="https://vws.vuforia.com/summary", timeout=30)

Asynchronous httpx and HTTPX2 clients are intercepted as well.

Using Docker to mock calls to Vuforia from any language

It is possible run a Mock VWS instance using Docker containers.

This allows you to run tests against a mock VWS instance regardless of the language or tooling you are using.

See Running a server with Docker for how to do this.

Reference