vws-python-mock 2026.8.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mock_vws/__init__.py +9 -0
- mock_vws/_base64_decoding.py +35 -0
- mock_vws/_constants.py +84 -0
- mock_vws/_database_matchers.py +107 -0
- mock_vws/_flask_server/Dockerfile +32 -0
- mock_vws/_flask_server/__init__.py +1 -0
- mock_vws/_flask_server/healthcheck.py +31 -0
- mock_vws/_flask_server/target_manager.py +447 -0
- mock_vws/_flask_server/vwq.py +173 -0
- mock_vws/_flask_server/vws.py +954 -0
- mock_vws/_mock_common.py +75 -0
- mock_vws/_model_target_web_api.py +486 -0
- mock_vws/_query_tools.py +136 -0
- mock_vws/_query_validators/__init__.py +128 -0
- mock_vws/_query_validators/accept_header_validators.py +31 -0
- mock_vws/_query_validators/auth_validators.py +143 -0
- mock_vws/_query_validators/content_length_validators.py +90 -0
- mock_vws/_query_validators/content_type_validators.py +65 -0
- mock_vws/_query_validators/date_validators.py +110 -0
- mock_vws/_query_validators/exceptions.py +769 -0
- mock_vws/_query_validators/fields_validators.py +47 -0
- mock_vws/_query_validators/image_validators.py +197 -0
- mock_vws/_query_validators/include_target_data_validators.py +51 -0
- mock_vws/_query_validators/num_results_validators.py +64 -0
- mock_vws/_query_validators/project_state_validators.py +49 -0
- mock_vws/_requests_mock_server/__init__.py +1 -0
- mock_vws/_requests_mock_server/decorators.py +275 -0
- mock_vws/_requests_mock_server/mock_web_query_api.py +139 -0
- mock_vws/_requests_mock_server/mock_web_services_api.py +954 -0
- mock_vws/_respx_mock_server/__init__.py +1 -0
- mock_vws/_respx_mock_server/decorators.py +186 -0
- mock_vws/_services_validators/__init__.py +186 -0
- mock_vws/_services_validators/active_flag_validators.py +43 -0
- mock_vws/_services_validators/auth_validators.py +124 -0
- mock_vws/_services_validators/content_length_validators.py +102 -0
- mock_vws/_services_validators/content_type_validators.py +42 -0
- mock_vws/_services_validators/date_validators.py +78 -0
- mock_vws/_services_validators/exceptions.py +858 -0
- mock_vws/_services_validators/image_validators.py +220 -0
- mock_vws/_services_validators/json_validators.py +69 -0
- mock_vws/_services_validators/key_validators.py +171 -0
- mock_vws/_services_validators/metadata_validators.py +106 -0
- mock_vws/_services_validators/name_validators.py +235 -0
- mock_vws/_services_validators/project_state_validators.py +76 -0
- mock_vws/_services_validators/request_quota_validators.py +42 -0
- mock_vws/_services_validators/target_quota_validators.py +41 -0
- mock_vws/_services_validators/target_validators.py +69 -0
- mock_vws/_services_validators/width_validators.py +38 -0
- mock_vws/database.py +257 -0
- mock_vws/database_type.py +13 -0
- mock_vws/image_matchers.py +124 -0
- mock_vws/model_target.py +79 -0
- mock_vws/py.typed +0 -0
- mock_vws/states.py +20 -0
- mock_vws/target.py +285 -0
- mock_vws/target_manager.py +178 -0
- mock_vws/target_raters.py +109 -0
- vws_python_mock-2026.8.4.dist-info/METADATA +177 -0
- vws_python_mock-2026.8.4.dist-info/RECORD +62 -0
- vws_python_mock-2026.8.4.dist-info/WHEEL +5 -0
- vws_python_mock-2026.8.4.dist-info/licenses/LICENSE +21 -0
- vws_python_mock-2026.8.4.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"""A fake implementation of the Vuforia Web Query API.
|
|
2
|
+
|
|
3
|
+
See
|
|
4
|
+
https://developer.vuforia.com/library/web-api/vuforia-query-web-api
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import email.utils
|
|
8
|
+
from collections.abc import Callable, Iterable, Mapping
|
|
9
|
+
from http import HTTPMethod, HTTPStatus
|
|
10
|
+
from typing import ParamSpec, Protocol, runtime_checkable
|
|
11
|
+
|
|
12
|
+
from beartype import beartype
|
|
13
|
+
|
|
14
|
+
from mock_vws._mock_common import RequestData, Route
|
|
15
|
+
from mock_vws._query_tools import (
|
|
16
|
+
get_query_match_response_text,
|
|
17
|
+
)
|
|
18
|
+
from mock_vws._query_validators import run_query_validators
|
|
19
|
+
from mock_vws._query_validators.exceptions import (
|
|
20
|
+
ValidatorError,
|
|
21
|
+
)
|
|
22
|
+
from mock_vws.image_matchers import ImageMatcher
|
|
23
|
+
from mock_vws.target_manager import TargetManager
|
|
24
|
+
|
|
25
|
+
_ROUTES: set[Route] = set()
|
|
26
|
+
|
|
27
|
+
_ResponseType = tuple[int, Mapping[str, str], str]
|
|
28
|
+
_P = ParamSpec("_P")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@runtime_checkable
|
|
32
|
+
class _RouteMethod(Protocol[_P]):
|
|
33
|
+
"""Callable used for routing which also exposes ``__name__``."""
|
|
34
|
+
|
|
35
|
+
__name__: str
|
|
36
|
+
|
|
37
|
+
def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _ResponseType:
|
|
38
|
+
"""Return a mock response."""
|
|
39
|
+
... # pylint: disable=unnecessary-ellipsis
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@beartype
|
|
43
|
+
def route(
|
|
44
|
+
*,
|
|
45
|
+
path_pattern: str,
|
|
46
|
+
http_methods: Iterable[str],
|
|
47
|
+
) -> Callable[[_RouteMethod[_P]], _RouteMethod[_P]]:
|
|
48
|
+
"""Register a decorated method so that it can be recognized as a route.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
path_pattern: The end part of a URL pattern. E.g. `/targets` or
|
|
52
|
+
`/targets/.+`.
|
|
53
|
+
http_methods: HTTP methods that map to the route function.
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
A decorator which takes methods and makes them recognizable as routes.
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
def decorator(
|
|
60
|
+
method: _RouteMethod[_P],
|
|
61
|
+
) -> _RouteMethod[_P]:
|
|
62
|
+
"""Register a decorated method so that it can be recognized as a
|
|
63
|
+
route.
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
The given `method` with multiple changes, including added
|
|
67
|
+
validators.
|
|
68
|
+
"""
|
|
69
|
+
new_route = Route(
|
|
70
|
+
route_name=method.__name__,
|
|
71
|
+
path_pattern=path_pattern,
|
|
72
|
+
http_methods=frozenset(http_methods),
|
|
73
|
+
)
|
|
74
|
+
_ROUTES.add(new_route)
|
|
75
|
+
|
|
76
|
+
return method
|
|
77
|
+
|
|
78
|
+
return decorator
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@beartype
|
|
82
|
+
class MockVuforiaWebQueryAPI:
|
|
83
|
+
"""A fake implementation of the Vuforia Web Query API."""
|
|
84
|
+
|
|
85
|
+
def __init__(
|
|
86
|
+
self,
|
|
87
|
+
target_manager: TargetManager,
|
|
88
|
+
query_match_checker: ImageMatcher,
|
|
89
|
+
) -> None:
|
|
90
|
+
"""
|
|
91
|
+
Args:
|
|
92
|
+
target_manager: The target manager which holds all databases.
|
|
93
|
+
query_match_checker: A callable which takes two image values
|
|
94
|
+
and
|
|
95
|
+
returns whether they match.
|
|
96
|
+
|
|
97
|
+
Attributes:
|
|
98
|
+
routes: The `Route`s to be used in the mock.
|
|
99
|
+
"""
|
|
100
|
+
self.routes = _ROUTES
|
|
101
|
+
self._target_manager = target_manager
|
|
102
|
+
self._query_match_checker = query_match_checker
|
|
103
|
+
|
|
104
|
+
@route(path_pattern="/v1/query", http_methods={HTTPMethod.POST})
|
|
105
|
+
def query(self, request: RequestData) -> _ResponseType:
|
|
106
|
+
"""Perform an image recognition query."""
|
|
107
|
+
try:
|
|
108
|
+
run_query_validators(
|
|
109
|
+
request_path=request.path,
|
|
110
|
+
request_headers=request.headers,
|
|
111
|
+
request_body=request.body,
|
|
112
|
+
request_method=request.method,
|
|
113
|
+
databases=self._target_manager.cloud_databases,
|
|
114
|
+
)
|
|
115
|
+
except ValidatorError as exc:
|
|
116
|
+
return exc.status_code, exc.headers, exc.response_text
|
|
117
|
+
|
|
118
|
+
response_text = get_query_match_response_text(
|
|
119
|
+
request_headers=request.headers,
|
|
120
|
+
request_body=request.body,
|
|
121
|
+
request_method=request.method,
|
|
122
|
+
request_path=request.path,
|
|
123
|
+
databases=self._target_manager.cloud_databases,
|
|
124
|
+
query_match_checker=self._query_match_checker,
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
date = email.utils.formatdate(
|
|
128
|
+
timeval=None,
|
|
129
|
+
localtime=False,
|
|
130
|
+
usegmt=True,
|
|
131
|
+
)
|
|
132
|
+
headers = {
|
|
133
|
+
"Connection": "keep-alive",
|
|
134
|
+
"Content-Type": "application/json",
|
|
135
|
+
"Server": "nginx",
|
|
136
|
+
"Date": date,
|
|
137
|
+
"Content-Length": str(object=len(response_text)),
|
|
138
|
+
}
|
|
139
|
+
return HTTPStatus.OK, headers, response_text
|