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
24 changes: 24 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@ By default, an exception will be raised if any requests to unmocked addresses ar

.. _requests: https://pypi.org/project/requests/

Mocking calls made to Vuforia with Python ``httpx``
----------------------------------------------------

Using the mock redirects requests to Vuforia made with `httpx`_ to an in-memory implementation.

.. code-block:: python

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

import httpx

from mock_vws import MockVWSForHttpx
from mock_vws.database import CloudDatabase

with MockVWSForHttpx() 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)

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

.. _httpx: https://pypi.org/project/httpx/

Using Docker to mock calls to Vuforia from any language
-------------------------------------------------------

Expand Down
8 changes: 8 additions & 0 deletions docs/source/getting-started.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
Getting started
---------------

Mocking calls made to Vuforia with Python ``requests``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. include:: basic-example.rst

Mocking calls made to Vuforia with Python ``httpx``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. include:: httpx-example.rst
22 changes: 22 additions & 0 deletions docs/source/httpx-example.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Using the mock redirects requests to Vuforia made with `httpx`_ to an in-memory implementation.

.. code-block:: python

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

import httpx

from mock_vws import MockVWSForHttpx
from mock_vws.database import CloudDatabase

with MockVWSForHttpx() 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)

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

See :ref:`mock-api-reference` for details of what can be changed and how.

.. _httpx: https://pypi.org/project/httpx/
5 changes: 5 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ This requires Python |minimum-python-version|\+.

.. include:: basic-example.rst

Mocking calls made to Vuforia with Python ``httpx``
----------------------------------------------------

.. include:: httpx-example.rst

Using Docker to mock calls to Vuforia from any language
-------------------------------------------------------

Expand Down
4 changes: 4 additions & 0 deletions docs/source/mock-api-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ API Reference
:members:
:undoc-members:

.. autoclass:: mock_vws.MockVWSForHttpx
:members:
:undoc-members:

.. autoclass:: mock_vws.MissingSchemeError
:members:
:undoc-members:
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ dynamic = [
dependencies = [
"beartype>=0.22.9",
"flask>=3.0.3",
"httpx>=0.27.0",
"numpy>=1.26.4",
"pillow>=11.0.0",
"piq>=0.8.0",
"pydantic-settings>=2.6.1",
"requests>=2.32.3",
"responses>=0.25.3",
"respx>=0.21.0",
"torch>=2.5.1",
"torchmetrics>=1.5.1",
"torchvision>=0.20.1",
Expand Down
2 changes: 2 additions & 0 deletions spelling_private_dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ hmac
html
http
https
httpx
iff
io
issuecomment
Expand Down Expand Up @@ -98,6 +99,7 @@ reqjsonarr
resheader
resjson
resjsonarr
respx
rfc
rgb
str
Expand Down
2 changes: 2 additions & 0 deletions src/mock_vws/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
MissingSchemeError,
MockVWS,
)
from mock_vws._respx_mock_server.decorators import MockVWSForHttpx

__all__ = [
"MissingSchemeError",
"MockVWS",
"MockVWSForHttpx",
]
1 change: 1 addition & 0 deletions src/mock_vws/_respx_mock_server/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""A fake implementation of Vuforia Web Services for use with respx."""
Loading