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,78 @@
|
|
|
1
|
+
"""Validators of the date header to use in the mock services API."""
|
|
2
|
+
|
|
3
|
+
import datetime
|
|
4
|
+
import logging
|
|
5
|
+
from collections.abc import Mapping
|
|
6
|
+
from http import HTTPStatus
|
|
7
|
+
from zoneinfo import ZoneInfo
|
|
8
|
+
|
|
9
|
+
from beartype import beartype
|
|
10
|
+
|
|
11
|
+
from mock_vws._services_validators.exceptions import (
|
|
12
|
+
FailError,
|
|
13
|
+
RequestTimeTooSkewedError,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
_LOGGER = logging.getLogger(name=__name__)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@beartype
|
|
20
|
+
def validate_date_header_given(*, request_headers: Mapping[str, str]) -> None:
|
|
21
|
+
"""Validate the date header is given to a VWS endpoint.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
request_headers: The headers sent with the request.
|
|
25
|
+
|
|
26
|
+
Raises:
|
|
27
|
+
FailError: The date is not given.
|
|
28
|
+
"""
|
|
29
|
+
if "Date" in request_headers:
|
|
30
|
+
return
|
|
31
|
+
|
|
32
|
+
_LOGGER.warning(msg="The date header is not given.")
|
|
33
|
+
raise FailError(status_code=HTTPStatus.BAD_REQUEST)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@beartype
|
|
37
|
+
def validate_date_format(*, request_headers: Mapping[str, str]) -> None:
|
|
38
|
+
"""Validate the format of the date header given to a VWS endpoint.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
request_headers: The headers sent with the request.
|
|
42
|
+
|
|
43
|
+
Raises:
|
|
44
|
+
FailError: The date is in the wrong format.
|
|
45
|
+
"""
|
|
46
|
+
date_header = request_headers["Date"]
|
|
47
|
+
date_format = "%a, %d %b %Y %H:%M:%S GMT"
|
|
48
|
+
try:
|
|
49
|
+
datetime.datetime.strptime(date_header, date_format).astimezone()
|
|
50
|
+
except ValueError as exc:
|
|
51
|
+
_LOGGER.warning(msg="The date header is in the wrong format.")
|
|
52
|
+
raise FailError(status_code=HTTPStatus.BAD_REQUEST) from exc
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@beartype
|
|
56
|
+
def validate_date_in_range(*, request_headers: Mapping[str, str]) -> None:
|
|
57
|
+
"""Validate the date header given to a VWS endpoint is in range.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
request_headers: The headers sent with the request.
|
|
61
|
+
|
|
62
|
+
Raises:
|
|
63
|
+
RequestTimeTooSkewedError: The date is out of range.
|
|
64
|
+
"""
|
|
65
|
+
gmt = ZoneInfo(key="GMT")
|
|
66
|
+
date_from_header = datetime.datetime.strptime(
|
|
67
|
+
request_headers["Date"],
|
|
68
|
+
"%a, %d %b %Y %H:%M:%S GMT",
|
|
69
|
+
).replace(tzinfo=gmt)
|
|
70
|
+
|
|
71
|
+
now = datetime.datetime.now(tz=gmt)
|
|
72
|
+
time_difference = now - date_from_header
|
|
73
|
+
|
|
74
|
+
maximum_time_difference = datetime.timedelta(minutes=5)
|
|
75
|
+
|
|
76
|
+
if abs(time_difference) >= maximum_time_difference:
|
|
77
|
+
_LOGGER.warning(msg="The date header is out of range.")
|
|
78
|
+
raise RequestTimeTooSkewedError
|