API Reference¶
- class mock_vws.MockVWS(*, base_vws_url: str = 'https://vws.vuforia.com', base_vwq_url: str = 'https://cloudreco.vuforia.com', cloud_query_failure_response: ~mock_vws.cloud_query.CloudQueryFailureResponse | None = None, duplicate_match_checker: ~mock_vws.image_matchers.ImageMatcher = <mock_vws.image_matchers.StructuralSimilarityMatcher object>, query_match_checker: ~mock_vws.image_matchers.ImageMatcher = <mock_vws.image_matchers.StructuralSimilarityMatcher object>, processing_time_seconds: float = 2.0, model_target_generation_failure: ~mock_vws.model_target.ModelTargetGenerationFailure | None = None, model_target_generation_warning: ~mock_vws.model_target.ModelTargetGenerationWarning | None = None, target_tracking_rater: ~mock_vws.target_raters.TargetTrackingRater = <mock_vws.target_raters.BrisqueTargetTrackingRater object>, real_http: bool = False, response_delay_seconds: float = 0.0, sleep_fn: ~collections.abc.Callable[[float], None] = <built-in function sleep>, vumark_generation_failure: ~mock_vws.vumark.VuMarkGenerationFailure | None = None)¶
Route requests to Vuforia’s Web Service APIs to fakes of those APIs.
Works with both
requestsandhttpx.Route requests to Vuforia’s Web Service APIs to fakes of those APIs.
Works with both
requestsandhttpx.- Parameters:
real_http¶ – Whether or not to forward requests to the real server if they are not handled by the mock. See https://requests-mock.readthedocs.io/en/latest/mocker.html#real-http-requests.
processing_time_seconds¶ – The number of seconds to process each image for. In the real Vuforia Web Services, this is not deterministic.
model_target_generation_failure¶ – A failure to return after every Model Target dataset finishes processing. By default, Model Target datasets finish successfully.
model_target_generation_warning¶ – A warning to return after every Model Target dataset finishes processing. By default, Model Target datasets finish without warnings. This cannot be combined with
model_target_generation_failure.base_vwq_url¶ – The base URL for the VWQ API.
base_vws_url¶ – The base URL for the VWS API.
cloud_query_failure_response¶ – A response to return for every Cloud Query request, bypassing normal request validation and image matching. By default, Cloud Query requests are handled normally.
vumark_generation_failure¶ – A failure to return for every VuMark generation request, bypassing normal request validation and instance generation. By default, VuMark generation requests are handled normally.
query_match_checker¶ – A callable which takes two image values and returns whether they will match in a query request.
duplicate_match_checker¶ – A callable which takes two image values and returns whether they are duplicates.
target_tracking_rater¶ – A callable for rating targets for tracking.
response_delay_seconds¶ – The number of seconds to delay each response by. This can be used to test timeout handling.
sleep_fn¶ – The function to use for sleeping during response delays. Defaults to
time.sleep. Inject a custom function to control virtual time in tests without monkey-patching.
- Raises:
MissingSchemeError – There is no scheme in a given URL.
ValueError – Both a Model Target generation failure and warning are configured.
- add_cloud_database(cloud_database: CloudDatabase) None¶
Add a cloud database.
- Parameters:
cloud_database¶ – The cloud database to add.
- Raises:
ValueError – One of the given cloud database keys matches a key for an existing cloud database.
- add_vumark_database(vumark_database: VuMarkDatabase) None¶
Add a VuMark database.
- Parameters:
vumark_database¶ – The VuMark database to add.
- Raises:
ValueError – One of the given database keys matches a key for an existing database.
- class mock_vws.MissingSchemeError(url: str)¶
Raised when a URL is missing a schema.
- Parameters:
url¶ – The URL which is missing a scheme.
- class mock_vws.CloudQueryFailureResponse(*, status_code, headers={}, body=b'')¶
A failure response returned by the Cloud Query API mock.
- Parameters:
- class mock_vws.VuMarkGenerationFailure(*values)¶
A configured failure returned by the VuMark Generation API mock.
- QUOTA_EXCEEDED = 'QuotaExceeded'¶
- LICENSE_CHECK_FAILED = 'LicenseCheckFailed'¶
- AUTHORIZATION_FAILED = 'AuthorizationFailed'¶
- property status_code: HTTPStatus¶
Return the HTTP status documented for this failure.
- class mock_vws.ModelTargetGenerationFailure(*, message: str = 'Model Target dataset generation failed')¶
A configured Model Target dataset generation failure.
- Parameters:
message¶ – The failure message included in the dataset status response.
- class mock_vws.ModelTargetGenerationWarning(*, message='Warning after creating dataset', details=...)¶
A configured Model Target dataset generation warning.
- Parameters:
- class mock_vws.database.CloudDatabase(*, database_id: str = <factory>, database_name: str = <factory>, server_access_key: str = <factory>, server_secret_key: str = <factory>, client_access_key: str = <factory>, client_secret_key: str = <factory>, targets: set[ImageTarget] = <factory>, state: States = States.WORKING, database_type: DatabaseType = DatabaseType.CLOUD_RECO, request_quota: int = 100000, reco_threshold: int = 1000, current_month_recos: int = 0, previous_month_recos: int = 0, total_recos: int = 0, target_quota: int = 1000, requests_per_second_limit: int | None = None, request_rate_limits: RequestRateLimits | None = None)¶
Credentials for VWS APIs.
- Parameters:
database_id¶ – The identifier of a VWS target manager database. Defaults to a random string. Endpoints which name a database in their path, such as the reco counts report endpoint, accept only the identifier of the database which the request’s server keys belong to.
database_name¶ – The name of a VWS target manager database name. Defaults to a random string.
server_access_key¶ – A VWS server access key. Defaults to a random string.
server_secret_key¶ – A VWS server secret key. Defaults to a random string.
client_access_key¶ – A VWS client access key. Defaults to a random string.
client_secret_key¶ – A VWS client secret key. Defaults to a random string.
state¶ – The state of the database.
request_quota¶ – The request quota. Set this to
0to make VWS endpoints returnRequestQuotaReached.target_quota¶ – The target quota. When the database contains this many targets, adding another returns
TargetQuotaReached.requests_per_second_limit¶ – The maximum number of VWS requests accepted in a rolling one-second window, across all VWS endpoints. Set this to
0to make VWS endpoints returnTooManyRequests. By default, the mock does not apply this limit.request_rate_limits¶ – Request rate limits which apply to individual groups of VWS endpoints, tracked separately from each other and from
requests_per_second_limit. Set this tomock_vws.request_rate_limits.DOCUMENTED_REQUEST_RATE_LIMITSto apply the limits which Vuforia documents. By default, the mock does not apply per-endpoint request limits.
- targets: set[ImageTarget]¶
- database_type: DatabaseType = 'cloud_reco'¶
- request_rate_limits: RequestRateLimits | None = None¶
- class mock_vws.database.VuMarkDatabase(*, database_name: str = <factory>, server_access_key: str = <factory>, server_secret_key: str = <factory>, vumark_targets: set[VuMarkTarget] = <factory>, state: States = States.WORKING)¶
Credentials for the VuMark generation API.
- Parameters:
- vumark_targets: set[VuMarkTarget]¶
- get_vumark_target(target_id: str) VuMarkTarget¶
Return a VuMark target from the database with the given ID.
- class mock_vws.request_rate_limits.RequestRateLimit(*, max_requests: int, window_seconds: float)¶
A maximum number of requests within a rolling time window.
- Parameters:
- class mock_vws.request_rate_limits.RequestRateLimits(*, other: RequestRateLimit | None = None, get_target: RequestRateLimit | None = None, get_duplicates: RequestRateLimit | None = None, list_targets: RequestRateLimit | None = None)¶
Request rate limits for each group of VWS endpoints.
Each limit is tracked separately, in the same way that the real Vuforia Web Services document separate limits per endpoint. Endpoints without their own limit share the
otherlimit. A limit ofNonemeans that no limit is applied.- Parameters:
- other: RequestRateLimit | None = None¶
- get_target: RequestRateLimit | None = None¶
- get_duplicates: RequestRateLimit | None = None¶
- list_targets: RequestRateLimit | None = None¶
- class mock_vws.request_rate_limits.RateLimitedEndpoint(*values)¶
A group of VWS endpoints which share a request rate limit.
- GET_TARGET = 1¶
- GET_DUPLICATES = 2¶
- LIST_TARGETS = 3¶
- OTHER = 4¶
- mock_vws.request_rate_limits.DOCUMENTED_REQUEST_RATE_LIMITS = RequestRateLimits(other=RequestRateLimit(max_requests=15, window_seconds=1.0), get_target=RequestRateLimit(max_requests=45, window_seconds=1.0), get_duplicates=RequestRateLimit(max_requests=10, window_seconds=1.0), list_targets=RequestRateLimit(max_requests=1, window_seconds=60.0))¶
The request rate limits documented by Vuforia.
These limits have not been verified against the real Vuforia Web Services, and so they are not applied by default.
- class mock_vws.states.States(*values)¶
Constants representing various web service states.
- WORKING = 'working'¶
- PROJECT_SUSPENDED = 'project_suspended'¶
- PROJECT_INACTIVE = 'project_inactive'¶
- PROJECT_HAS_NO_API_ACCESS = 'project_has_no_api_access'¶
- class mock_vws.database_type.DatabaseType(*values)¶
Constants representing various database types.
- CLOUD_RECO = 'cloud_reco'¶
- class mock_vws.target.ImageTarget(*, active_flag: bool, application_metadata: str | None, image_value: bytes, name: str, processing_time_seconds: float, width: float, target_tracking_rater: TargetTrackingRater, current_month_recos: int = 0, delete_date: datetime | None = None, last_modified_date: datetime = <factory>, previous_month_recos: int = 0, reco_rating: str = '', target_id: str = <factory>, total_recos: int = 0, upload_date: datetime = <factory>)¶
A Vuforia image target as managed in https://developer.vuforia.com/target-manager.
- class mock_vws.target.VuMarkTarget(*, name: str, processing_time_seconds: float = 0.0, target_id: str = <factory>, last_modified_date: datetime = <factory>, upload_date: datetime = <factory>)¶
A VuMark target as managed in https://developer.vuforia.com/target-manager.
Unlike ImageTarget, VuMark targets do not require an image — they use a VuMark template.
Image matchers¶
- protocol mock_vws.image_matchers.ImageMatcher¶
Protocol for a matcher for query and duplicate requests.
This protocol is runtime checkable.
Classes that implement this protocol must have the following methods / attributes:
- __call__(first_image_content: bytes, second_image_content: bytes) bool¶
Whether one image’s content matches another’s closely enough.
- __annotations_cache__ = {}¶
- class mock_vws.image_matchers.ExactMatcher¶
A matcher which returns whether two images are exactly equal.
- class mock_vws.image_matchers.StructuralSimilarityMatcher¶
A matcher which returns whether two images are similar using SSIM.
Target raters¶
- protocol mock_vws.target_raters.TargetTrackingRater¶
Protocol for a rater of target quality.
This protocol is runtime checkable.
Classes that implement this protocol must have the following methods / attributes:
- __call__(image_content: bytes) int¶
The target tracking rating.
- Parameters:
image_content¶ – A target’s image’s content.
- __annotations_cache__ = {}¶
- class mock_vws.target_raters.RandomTargetTrackingRater¶
A rater which returns a random number.
- class mock_vws.target_raters.HardcodedTargetTrackingRater(rating: int)¶
A rater which returns a hardcoded number.
- Parameters:
rating¶ – The rating to return.
- class mock_vws.target_raters.BrisqueTargetTrackingRater¶
A rater which returns a rating based on a BRISQUE score.