API Reference¶
- class mock_vws.MockVWS(*, base_vws_url: str = 'https://vws.vuforia.com', base_vwq_url: str = 'https://cloudreco.vuforia.com', 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, 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>)¶
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.
base_vwq_url¶ – The base URL for the VWQ API.
base_vws_url¶ – The base URL for the VWS API.
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.
- 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.database.CloudDatabase(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[~mock_vws.target.ImageTarget] = <factory>, state: ~mock_vws.states.States = States.WORKING, database_type: ~mock_vws.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)¶
Credentials for VWS APIs.
- Parameters:
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.
- targets: set[ImageTarget]¶
- database_type: DatabaseType = 'cloud_reco'¶
- class mock_vws.database.VuMarkDatabase(database_name: str = <factory>, server_access_key: str = <factory>, server_secret_key: str = <factory>, vumark_targets: set[~mock_vws.target.VuMarkTarget] = <factory>, state: ~mock_vws.states.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.
- enum mock_vws.states.States(value)¶
Constants representing various web service states.
- Member Type:
Valid values are as follows:
- WORKING = <States.WORKING: 'working'>¶
- PROJECT_INACTIVE = <States.PROJECT_INACTIVE: 'project_inactive'>¶
- enum mock_vws.database_type.DatabaseType(value)¶
Constants representing various database types.
- Member Type:
Valid values are as follows:
- CLOUD_RECO = <DatabaseType.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: ~mock_vws.target_raters.TargetTrackingRater, current_month_recos: int = 0, delete_date: ~datetime.datetime | None = None, last_modified_date: ~datetime.datetime = <factory>, previous_month_recos: int = 0, reco_rating: str = '', target_id: str = <factory>, total_recos: int = 0, upload_date: ~datetime.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.datetime = <factory>, upload_date: ~datetime.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:
- 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:
- 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.