GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • vws-python-mock

This view

  • Original page
  • New address

GeezerVison is showing vws-python.github.io — vws-python-mock

vws-python-mock¶

Mocking calls made to Vuforia¶

$ pip install vws-python-mock

This requires Python 3.15+.

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 containers to mock calls to Vuforia from any language¶

You can run a Mock VWS instance using Docker or Apple’s container CLI.

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

See Running a server in containers for how to do this.

Reference¶

  • Installation
  • Getting started
    • Mocking calls made to Vuforia
  • Running a server in containers
    • Running the mock
      • Creating containers with Docker
      • Creating containers with Apple container
    • Adding a database to the mock target manager
    • Deleting a database
    • Setting the recognition counts of a target
    • Configuration options
      • Required configuration
      • Optional configuration
      • Building images from source
  • API Reference
    • MockVWS
      • MockVWS.add_cloud_database()
      • MockVWS.add_vumark_database()
      • MockVWS.set_target_recognition_counts()
    • MissingSchemeError
    • CloudQueryFailureResponse
      • CloudQueryFailureResponse.status_code
      • CloudQueryFailureResponse.headers
      • CloudQueryFailureResponse.body
    • ModelTargetFailureResponse
      • ModelTargetFailureResponse.status_code
      • ModelTargetFailureResponse.headers
      • ModelTargetFailureResponse.body
      • ModelTargetFailureResponse.requests
    • ModelTargetRequest
      • ModelTargetRequest.CREATE
      • ModelTargetRequest.STATUS
      • ModelTargetRequest.DOWNLOAD
      • ModelTargetRequest.DELETE
    • VuMarkGenerationFailure
      • VuMarkGenerationFailure.QUOTA_EXCEEDED
      • VuMarkGenerationFailure.LICENSE_CHECK_FAILED
      • VuMarkGenerationFailure.AUTHORIZATION_FAILED
      • VuMarkGenerationFailure.status_code
    • ModelTargetGenerationFailure
      • ModelTargetGenerationFailure.message
    • ModelTargetGenerationWarning
      • ModelTargetGenerationWarning.message
      • ModelTargetGenerationWarning.details
    • mock_vws.model_target.JSONValue
    • CloudDatabase
      • CloudDatabase.database_id
      • CloudDatabase.database_name
      • CloudDatabase.server_access_key
      • CloudDatabase.server_secret_key
      • CloudDatabase.client_access_key
      • CloudDatabase.client_secret_key
      • CloudDatabase.targets
      • CloudDatabase.state
      • CloudDatabase.database_type
      • CloudDatabase.request_quota
      • CloudDatabase.reco_threshold
      • CloudDatabase.current_month_recos
      • CloudDatabase.previous_month_recos
      • CloudDatabase.total_recos
      • CloudDatabase.target_quota
      • CloudDatabase.requests_per_second_limit
      • CloudDatabase.request_rate_limits
    • VuMarkDatabase
      • VuMarkDatabase.database_name
      • VuMarkDatabase.server_access_key
      • VuMarkDatabase.server_secret_key
      • VuMarkDatabase.vumark_targets
      • VuMarkDatabase.state
      • VuMarkDatabase.get_vumark_target()
    • RequestRateLimit
      • RequestRateLimit.max_requests
      • RequestRateLimit.window_seconds
    • RequestRateLimits
      • RequestRateLimits.other
      • RequestRateLimits.get_target
      • RequestRateLimits.get_duplicates
      • RequestRateLimits.list_targets
    • RateLimitedEndpoint
      • RateLimitedEndpoint.GET_TARGET
      • RateLimitedEndpoint.GET_DUPLICATES
      • RateLimitedEndpoint.LIST_TARGETS
      • RateLimitedEndpoint.OTHER
    • DOCUMENTED_REQUEST_RATE_LIMITS
    • States
      • States.WORKING
      • States.PROJECT_SUSPENDED
      • States.PROJECT_INACTIVE
      • States.PROJECT_HAS_NO_API_ACCESS
    • DatabaseType
      • DatabaseType.CLOUD_RECO
    • ImageTarget
    • VuMarkTarget
    • Image matchers
      • ImageMatcher
      • ExactMatcher
      • StructuralSimilarityMatcher
    • Target raters
      • TargetTrackingRater
      • RandomTargetTrackingRater
      • HardcodedTargetTrackingRater
      • BrisqueTargetTrackingRater
    • Server integration
  • Differences between the mock and the real Vuforia Web Services
    • Image matching
    • Speed and summary accuracy
    • Image quality and ratings
    • Result ordering
    • Matching recently deleted targets
    • Accepted date formats for the Query API
    • Unknown fields in Query API requests
    • Targets stuck in processing
    • Database summary quotas
    • transfer-encoding headers
    • Content-Encoding headers
    • x-aws-region headers
    • NGINX Error cases
    • Result codes
    • Request quota exhaustion
    • Request rate limits
    • Configurable Cloud Query failures
    • Configurable Model Target failures
    • Other configurable result codes
    • Content-Length headers
    • VuMark instance images
    • Model Target datasets
    • Reco counts reports
    • Paths which the mock does not serve
    • Header cases
  • Unverified behavior
    • Categories
    • Request quota exhaustion
    • A suspended database
    • Additional result codes
    • GET /targets for very large databases
    • The order of reco counts report rows
    • Recognition counts in the target summary report
    • Processing images in the database summary
    • VuMark instance generation for a processing target
    • Model Target generation failures
    • Model Target generation warnings
    • The name of a failed Model Target dataset
    • Malformed State-Based configuration documents
    • The exhausted training allowance response
    • Signed Model Target dataset creation
    • OAuth2 client-credential management
  • Versioning, Support and API Stability
  • Contributing to vws-python-mock
    • Install contribution dependencies
    • Linting
    • Running Tests
    • Connecting to Vuforia
    • Skipping Some Tests
    • Shared database credentials
    • Shared backend setup
    • Installed contract tests
    • Container deployment tests
    • Verifying signed Model Target requests
    • Retrying transient real Model Target failures
    • Documentation
    • Continuous Integration
    • Learnings about VWS
    • Release Process
    • Release notes
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.