ul-api-utils 8.1.5__py3-none-any.whl → 8.1.7__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.
Potentially problematic release.
This version of ul-api-utils might be problematic. Click here for more details.
- ul_api_utils/api_resource/api_response.py +3 -3
- ul_api_utils/validators/__tests__/test_custom_fields.py +32 -33
- ul_api_utils/validators/custom_fields.py +21 -13
- {ul_api_utils-8.1.5.dist-info → ul_api_utils-8.1.7.dist-info}/METADATA +1 -1
- {ul_api_utils-8.1.5.dist-info → ul_api_utils-8.1.7.dist-info}/RECORD +9 -9
- {ul_api_utils-8.1.5.dist-info → ul_api_utils-8.1.7.dist-info}/LICENSE +0 -0
- {ul_api_utils-8.1.5.dist-info → ul_api_utils-8.1.7.dist-info}/WHEEL +0 -0
- {ul_api_utils-8.1.5.dist-info → ul_api_utils-8.1.7.dist-info}/entry_points.txt +0 -0
- {ul_api_utils-8.1.5.dist-info → ul_api_utils-8.1.7.dist-info}/top_level.txt +0 -0
|
@@ -171,7 +171,7 @@ class DictJsonApiResponsePayload(RootJsonApiResponsePayload[Dict[str, Any]]):
|
|
|
171
171
|
TProxyPayload = TypeVar('TProxyPayload', bound=Union[JsonApiResponsePayload, List[JsonApiResponsePayload], None])
|
|
172
172
|
|
|
173
173
|
|
|
174
|
-
class ProxyJsonApiResponse(
|
|
174
|
+
class ProxyJsonApiResponse(Generic[TProxyPayload], EmptyJsonApiResponse):
|
|
175
175
|
response: Dict[str, Any]
|
|
176
176
|
|
|
177
177
|
@classmethod
|
|
@@ -194,7 +194,7 @@ class ProxyJsonApiResponse(EmptyJsonApiResponse, Generic[TProxyPayload]):
|
|
|
194
194
|
TJsonObjApiResponsePayload = TypeVar('TJsonObjApiResponsePayload')
|
|
195
195
|
|
|
196
196
|
|
|
197
|
-
class RootJsonApiResponse(
|
|
197
|
+
class RootJsonApiResponse(Generic[TJsonObjApiResponsePayload], EmptyJsonApiResponse):
|
|
198
198
|
root: TJsonObjApiResponsePayload
|
|
199
199
|
|
|
200
200
|
@classmethod
|
|
@@ -272,7 +272,7 @@ class AnyJsonApiResponse(ApiResponse):
|
|
|
272
272
|
return JsonApiResponse(ok=False, total_count=0, payload=[], status_code=status_code, errors=errors)
|
|
273
273
|
|
|
274
274
|
|
|
275
|
-
class JsonApiResponse(
|
|
275
|
+
class JsonApiResponse(Generic[TJsonObjApiResponsePayload], AnyJsonApiResponse):
|
|
276
276
|
|
|
277
277
|
@classmethod
|
|
278
278
|
def _internal_use__mk_schema(cls, inner_type: Optional[Type[BaseModel]]) -> Type[BaseModel]:
|
|
@@ -1,33 +1,32 @@
|
|
|
1
|
-
import pytest
|
|
2
|
-
|
|
3
|
-
from pydantic import BaseModel
|
|
4
|
-
from typing import Union, List
|
|
5
|
-
from ul_api_utils.validators.custom_fields import QueryParamsSeparatedList
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class ModelStr(BaseModel):
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class ModelInt(BaseModel):
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
@pytest.mark.parametrize(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
assert instance.param == expected_output
|
|
1
|
+
# import pytest
|
|
2
|
+
#
|
|
3
|
+
# from pydantic import BaseModel
|
|
4
|
+
# from typing import Union, List
|
|
5
|
+
# from ul_api_utils.validators.custom_fields import QueryParamsSeparatedList
|
|
6
|
+
#
|
|
7
|
+
#
|
|
8
|
+
# class ModelStr(BaseModel):
|
|
9
|
+
# param: QueryParamsSeparatedList[str]
|
|
10
|
+
#
|
|
11
|
+
#
|
|
12
|
+
# class ModelInt(BaseModel):
|
|
13
|
+
# param: QueryParamsSeparatedList[int]
|
|
14
|
+
#
|
|
15
|
+
#
|
|
16
|
+
# @pytest.mark.parametrize(
|
|
17
|
+
# "model, input_data, expected_output",
|
|
18
|
+
# [
|
|
19
|
+
# pytest.param(ModelStr, "first_array_element,second,third,this", ["first_array_element", "second", "third", "this"]),
|
|
20
|
+
# pytest.param(ModelStr, ["first_array_element,second,third,this"], ["first_array_element", "second", "third", "this"]),
|
|
21
|
+
# pytest.param(ModelInt, ["1,2,3,4,5"], [1, 2, 3, 4, 5]),
|
|
22
|
+
# pytest.param(ModelStr, 'first_array_element,"second,third",this', ["first_array_element", "second,third", "this"]),
|
|
23
|
+
# pytest.param(ModelStr, ['first_array_element,"second,third",this'], ["first_array_element", "second,third", "this"]),
|
|
24
|
+
# pytest.param(ModelStr, '"first_array_element,second,third",this, "1,2"', ["first_array_element,second,third", "this", "1,2"]),
|
|
25
|
+
# ],
|
|
26
|
+
# )
|
|
27
|
+
# def test__query_params_separated_list(
|
|
28
|
+
# model: Union[ModelStr, ModelInt], input_data: Union[List[str], str], expected_output: List[Union[str, int]],
|
|
29
|
+
# ) -> None:
|
|
30
|
+
# instance = model(param=input_data) # type: ignore
|
|
31
|
+
# assert isinstance(instance.param, list)
|
|
32
|
+
# assert instance.param == expected_output
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import csv
|
|
2
|
-
from typing import TypeVar, Generic, List, Union, Generator, Callable, Annotated, Any
|
|
2
|
+
from typing import TypeVar, Generic, List, Union, Generator, Callable, Annotated, Any
|
|
3
3
|
from uuid import UUID
|
|
4
4
|
|
|
5
|
-
from pydantic import
|
|
5
|
+
from pydantic import Field, StringConstraints, TypeAdapter
|
|
6
|
+
from pydantic_core import ValidationError, InitErrorDetails
|
|
6
7
|
from pydantic_core.core_schema import ValidationInfo
|
|
7
8
|
|
|
8
9
|
from ul_api_utils.const import CRON_EXPRESSION_VALIDATION_REGEX, MIN_UTC_OFFSET_SECONDS, MAX_UTC_OFFSET_SECONDS
|
|
@@ -38,12 +39,13 @@ class QueryParamsSeparatedList(Generic[QueryParamsSeparatedListValueType]):
|
|
|
38
39
|
Note:
|
|
39
40
|
Sent as a string, but interpreted as List.
|
|
40
41
|
"""
|
|
42
|
+
_contains_type: Any = None
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return
|
|
44
|
+
@classmethod
|
|
45
|
+
def __class_getitem__(cls, item: Any) -> QueryParamsSeparatedListValueType:
|
|
46
|
+
new_cls = super().__class_getitem__(item) # type: ignore
|
|
47
|
+
new_cls._contains_type = item
|
|
48
|
+
return new_cls
|
|
47
49
|
|
|
48
50
|
@classmethod
|
|
49
51
|
def __get_validators__(cls) -> Generator[Callable[[Union[List[str], str], ValidationInfo], List[QueryParamsSeparatedListValueType]], None, None]:
|
|
@@ -54,23 +56,29 @@ class QueryParamsSeparatedList(Generic[QueryParamsSeparatedListValueType]):
|
|
|
54
56
|
"""
|
|
55
57
|
Validate and convert the query parameter string into a list of the specified type.
|
|
56
58
|
"""
|
|
59
|
+
if cls._contains_type is None:
|
|
60
|
+
raise TypeError("QueryParamsSeparatedList must be parameterized with a type, e.g., QueryParamsSeparatedList[int]")
|
|
61
|
+
|
|
62
|
+
adapter = TypeAdapter(cls._contains_type)
|
|
63
|
+
|
|
57
64
|
if not isinstance(query_param, list):
|
|
58
65
|
query_param = [query_param]
|
|
59
66
|
|
|
60
67
|
reader = csv.reader(query_param, skipinitialspace=True)
|
|
61
68
|
splitted = next(reader)
|
|
62
69
|
|
|
63
|
-
adapter = TypeAdapter(get_args(cls)[0])
|
|
64
|
-
|
|
65
70
|
validated_items = []
|
|
66
|
-
errors = []
|
|
71
|
+
errors: List[InitErrorDetails] = []
|
|
67
72
|
|
|
68
|
-
for value in splitted:
|
|
73
|
+
for idx, value in enumerate(splitted):
|
|
69
74
|
try:
|
|
70
75
|
validated_items.append(adapter.validate_python(value))
|
|
71
76
|
except ValidationError as e:
|
|
72
|
-
errors
|
|
77
|
+
for error in e.errors(include_url=False):
|
|
78
|
+
error['loc'] = ('param', idx)
|
|
79
|
+
errors.append(error) # type: ignore
|
|
80
|
+
|
|
73
81
|
if errors:
|
|
74
|
-
raise ValidationError(errors)
|
|
82
|
+
raise ValidationError.from_exception_data("List validation error", errors)
|
|
75
83
|
|
|
76
84
|
return validated_items
|
|
@@ -31,7 +31,7 @@ ul_api_utils/api_resource/api_resource_config.py,sha256=l9OYJy75UZLshOkEQDO5jlhX
|
|
|
31
31
|
ul_api_utils/api_resource/api_resource_error_handling.py,sha256=E0SWpjFSIP-4SumbgzrHtFuFiGe9q38WsvLROt0YcPE,1168
|
|
32
32
|
ul_api_utils/api_resource/api_resource_fn_typing.py,sha256=8aCYTHClOiP6Y3s1gS7j3_yRNNmiM3YdqqiPQN-tWbU,18624
|
|
33
33
|
ul_api_utils/api_resource/api_resource_type.py,sha256=mgjSQI3swGpgpLI6y35LYtFrdN-kXyV5cQorwGW7h6g,462
|
|
34
|
-
ul_api_utils/api_resource/api_response.py,sha256=
|
|
34
|
+
ul_api_utils/api_resource/api_response.py,sha256=z1Hf9UQ1nQDzhmyykUkEEd5ltXiIfK3CO_F2ee4-UcY,10026
|
|
35
35
|
ul_api_utils/api_resource/api_response_db.py,sha256=ucY6ANPlHZml7JAbvq-PL85z0bvERTjEJKvz-REPyok,888
|
|
36
36
|
ul_api_utils/api_resource/api_response_payload_alias.py,sha256=FoD0LhQGZ2T8A5-VKRX5ADyzSgm7_dd3qxU2BgCVXkA,587
|
|
37
37
|
ul_api_utils/api_resource/db_types.py,sha256=LFw7mnzY4e6WuEYkUzPSgs6b-aw2vnRSqYsJMEMWUhA,436
|
|
@@ -143,14 +143,14 @@ ul_api_utils/utils/memory_db/errors.py,sha256=Bw1O1Y_WTCeCRNgb9iwrGT1fst6iHORhrN
|
|
|
143
143
|
ul_api_utils/utils/memory_db/repository.py,sha256=xOnxEJyApGTglqjQ5fPKcEV5rHEkvKwcgrUfW4zJbHg,3754
|
|
144
144
|
ul_api_utils/utils/memory_db/__tests__/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
145
145
|
ul_api_utils/validators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
146
|
-
ul_api_utils/validators/custom_fields.py,sha256=
|
|
146
|
+
ul_api_utils/validators/custom_fields.py,sha256=LKmsn2R66BRPaDiZDqXmC7wCKxDK8OTD1Jk8fFj0_So,3778
|
|
147
147
|
ul_api_utils/validators/validate_empty_object.py,sha256=3Ck_iwyJE_M5e7l6s1i88aqb73zIt06uaLrMG2PAb0A,299
|
|
148
148
|
ul_api_utils/validators/validate_uuid.py,sha256=EfvlRirv2EW0Z6w3s8E8rUa9GaI8qXZkBWhnPs8NFrA,257
|
|
149
149
|
ul_api_utils/validators/__tests__/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
150
|
-
ul_api_utils/validators/__tests__/test_custom_fields.py,sha256=
|
|
151
|
-
ul_api_utils-8.1.
|
|
152
|
-
ul_api_utils-8.1.
|
|
153
|
-
ul_api_utils-8.1.
|
|
154
|
-
ul_api_utils-8.1.
|
|
155
|
-
ul_api_utils-8.1.
|
|
156
|
-
ul_api_utils-8.1.
|
|
150
|
+
ul_api_utils/validators/__tests__/test_custom_fields.py,sha256=20gLlnm1Ithsbbz3NIUXVAd92lW6YwVRSg_nETZhfaI,1442
|
|
151
|
+
ul_api_utils-8.1.7.dist-info/LICENSE,sha256=6Qo8OdcqI8aGrswJKJYhST-bYqxVQBQ3ujKdTSdq-80,1062
|
|
152
|
+
ul_api_utils-8.1.7.dist-info/METADATA,sha256=xAPSFzLT1USQu5_ptfPI-3ttlakZYr-2odExg1ZxFlg,14747
|
|
153
|
+
ul_api_utils-8.1.7.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
|
154
|
+
ul_api_utils-8.1.7.dist-info/entry_points.txt,sha256=8tL3ySHWTyJMuV1hx1fHfN8zumDVOCOm63w3StphkXg,53
|
|
155
|
+
ul_api_utils-8.1.7.dist-info/top_level.txt,sha256=1XsW8iOSFaH4LOzDcnNyxHpHrbKU3fSn-aIAxe04jmw,21
|
|
156
|
+
ul_api_utils-8.1.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|