cuenca-validations 2.0.5.dev4__py3-none-any.whl → 2.0.5.dev6__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.
- cuenca_validations/types/general.py +1 -0
- cuenca_validations/types/helpers.py +8 -3
- cuenca_validations/version.py +1 -1
- {cuenca_validations-2.0.5.dev4.dist-info → cuenca_validations-2.0.5.dev6.dist-info}/METADATA +1 -1
- {cuenca_validations-2.0.5.dev4.dist-info → cuenca_validations-2.0.5.dev6.dist-info}/RECORD +9 -9
- tests/test_types.py +38 -23
- {cuenca_validations-2.0.5.dev4.dist-info → cuenca_validations-2.0.5.dev6.dist-info}/LICENSE +0 -0
- {cuenca_validations-2.0.5.dev4.dist-info → cuenca_validations-2.0.5.dev6.dist-info}/WHEEL +0 -0
- {cuenca_validations-2.0.5.dev4.dist-info → cuenca_validations-2.0.5.dev6.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import uuid
|
|
2
2
|
from base64 import urlsafe_b64encode
|
|
3
|
-
from typing import Callable
|
|
3
|
+
from typing import Callable, Optional
|
|
4
|
+
|
|
5
|
+
from pydantic.fields import FieldInfo
|
|
4
6
|
|
|
5
7
|
from .general import LogConfig
|
|
6
8
|
|
|
@@ -12,6 +14,9 @@ def uuid_field(prefix: str = '') -> Callable[[], str]:
|
|
|
12
14
|
return base64_uuid_func
|
|
13
15
|
|
|
14
16
|
|
|
15
|
-
def get_log_config(field) -> LogConfig:
|
|
17
|
+
def get_log_config(field: FieldInfo) -> Optional[LogConfig]:
|
|
16
18
|
"""Helper function to find LogConfig in field metadata"""
|
|
17
|
-
|
|
19
|
+
try:
|
|
20
|
+
return next(m for m in field.metadata if isinstance(m, LogConfig))
|
|
21
|
+
except StopIteration:
|
|
22
|
+
return None
|
cuenca_validations/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = '2.0.5.
|
|
1
|
+
__version__ = '2.0.5.dev6'
|
|
@@ -4,13 +4,13 @@ cuenca_validations/errors.py,sha256=OtM8EgiKqYdz9Hn66AbBO96orL1or7efkyt0vh0Zxbs,
|
|
|
4
4
|
cuenca_validations/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
5
|
cuenca_validations/typing.py,sha256=1QCu81IbVZZpyInjyeAuO-nF36gpT5Gi4o6V9PozuOU,204
|
|
6
6
|
cuenca_validations/validators.py,sha256=wzwLnJ4wHggZvqp3mearbFkzvDERGeTNvJkuofQnuMc,1484
|
|
7
|
-
cuenca_validations/version.py,sha256=
|
|
7
|
+
cuenca_validations/version.py,sha256=7vju1xXby-uZTLStSB9WeN-8fQQFIeT93MoMNabJaqQ,27
|
|
8
8
|
cuenca_validations/types/__init__.py,sha256=8fiuz26oYQT2DriQ7sbD740yFJergVhB1OYoUGETB5A,4783
|
|
9
9
|
cuenca_validations/types/card.py,sha256=UGzz8NTFAverUmdUKAK1oGHnOnjSNTpIRUm93vKSSGY,1295
|
|
10
10
|
cuenca_validations/types/enums.py,sha256=1ACr7I1iknXfm49y0YeP2sY1ZdZfreFC5cV4_6OJCw8,18825
|
|
11
11
|
cuenca_validations/types/files.py,sha256=2CszbwF9ytXV9suFFwyDjYG4XxY8UhCjRw3HttVXXNw,269
|
|
12
|
-
cuenca_validations/types/general.py,sha256=
|
|
13
|
-
cuenca_validations/types/helpers.py,sha256=
|
|
12
|
+
cuenca_validations/types/general.py,sha256=c3j5Iv42yEpIGbylZ-64uoURgNiTmaZPiV5WOht0jTI,2249
|
|
13
|
+
cuenca_validations/types/helpers.py,sha256=6rHUhwoQ7jJZtGcW3LX-W5ZDl42PWE1RoBpGme7KCkk,610
|
|
14
14
|
cuenca_validations/types/identities.py,sha256=TivJcz0I_zolAWXZB3RTwt80OUAyW_wGdCL_6VJlxSM,4735
|
|
15
15
|
cuenca_validations/types/morals.py,sha256=m8kAedevmwfSPTA9GYe03l7pkgipynwYgKfejyVtnuI,1813
|
|
16
16
|
cuenca_validations/types/queries.py,sha256=KCRx0sPzWDtDDbZysmFGVgANgfqil17EITWaG7tGQ-A,4700
|
|
@@ -20,9 +20,9 @@ tests/test_card.py,sha256=QAfRz7e11gWICPnFJZ2tiYgUsFV3C9TwzJXrDnDNXFw,1202
|
|
|
20
20
|
tests/test_errors.py,sha256=ixiIgEuBuzfsL5p4uCFdF32XqFRtTPF6EVhGJ0keOrI,930
|
|
21
21
|
tests/test_helpers.py,sha256=ubzpi1UXCryLQdgsT_Zm2IX-XE_4L0dnHnhLwH06xK8,748
|
|
22
22
|
tests/test_statement.py,sha256=IOE0rRRBgBZSJv_FLaETEyn5NzzXKMNTqgjv99GX-68,1436
|
|
23
|
-
tests/test_types.py,sha256=
|
|
24
|
-
cuenca_validations-2.0.5.
|
|
25
|
-
cuenca_validations-2.0.5.
|
|
26
|
-
cuenca_validations-2.0.5.
|
|
27
|
-
cuenca_validations-2.0.5.
|
|
28
|
-
cuenca_validations-2.0.5.
|
|
23
|
+
tests/test_types.py,sha256=XpFDDO1N6kRARFLr8cXyY7jDRICAwrhNYkFst7cCKQE,17737
|
|
24
|
+
cuenca_validations-2.0.5.dev6.dist-info/LICENSE,sha256=wR76FmxBbfnQpwELkkE5iMF8sFIafEMgXLTE4N4WPTc,1063
|
|
25
|
+
cuenca_validations-2.0.5.dev6.dist-info/METADATA,sha256=m9_i-NdDzVvZVpYPeNnhpImNwnnUPTUlSRZJu4qO2uA,1577
|
|
26
|
+
cuenca_validations-2.0.5.dev6.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
27
|
+
cuenca_validations-2.0.5.dev6.dist-info/top_level.txt,sha256=4233xdOs2HtuT-GFRjcDcwK0IwdwvWdczOtk0fPB6Gw,25
|
|
28
|
+
cuenca_validations-2.0.5.dev6.dist-info/RECORD,,
|
tests/test_types.py
CHANGED
|
@@ -7,6 +7,7 @@ from typing import Annotated
|
|
|
7
7
|
import pytest
|
|
8
8
|
from freezegun import freeze_time
|
|
9
9
|
from pydantic import AfterValidator, BaseModel, SecretStr, ValidationError
|
|
10
|
+
from pydantic.fields import FieldInfo
|
|
10
11
|
|
|
11
12
|
from cuenca_validations.types import (
|
|
12
13
|
Address,
|
|
@@ -27,6 +28,7 @@ from cuenca_validations.types.enums import (
|
|
|
27
28
|
)
|
|
28
29
|
from cuenca_validations.types.general import LogConfig, StrictPositiveInt
|
|
29
30
|
from cuenca_validations.types.helpers import get_log_config
|
|
31
|
+
from cuenca_validations.types.identities import Password
|
|
30
32
|
from cuenca_validations.types.requests import (
|
|
31
33
|
ApiKeyUpdateRequest,
|
|
32
34
|
BankAccountValidationRequest,
|
|
@@ -590,48 +592,61 @@ def test_strict_positive_int_invalid(value, expected_error, expected_message):
|
|
|
590
592
|
IntModel(value=value)
|
|
591
593
|
|
|
592
594
|
|
|
593
|
-
def
|
|
595
|
+
def validate_repeated_digits(password: str) -> str:
|
|
594
596
|
"""
|
|
595
597
|
Example of a custom validator
|
|
596
|
-
Check if the
|
|
598
|
+
Check if the str contains repeated numbers
|
|
597
599
|
"""
|
|
598
600
|
import re
|
|
599
601
|
|
|
600
602
|
if re.search(r'(\d).*\1', password):
|
|
601
|
-
raise ValueError("
|
|
603
|
+
raise ValueError("str cannot contain repeated digits")
|
|
602
604
|
return password
|
|
603
605
|
|
|
604
606
|
|
|
605
|
-
class
|
|
606
|
-
password: Annotated[
|
|
607
|
-
|
|
607
|
+
class LogConfigModel(BaseModel):
|
|
608
|
+
password: Annotated[Password, LogConfig(masked=True)]
|
|
609
|
+
validated: Annotated[
|
|
610
|
+
str, AfterValidator(validate_repeated_digits), LogConfig(masked=True)
|
|
608
611
|
]
|
|
609
612
|
secret: Annotated[str, LogConfig(masked=True)]
|
|
610
613
|
partial_secret: Annotated[
|
|
611
614
|
str, LogConfig(masked=True, unmasked_chars_length=4)
|
|
612
615
|
]
|
|
616
|
+
unmasked: Annotated[str, LogConfig(masked=False)]
|
|
617
|
+
excluded: Annotated[str, LogConfig(excluded=True)]
|
|
613
618
|
|
|
614
619
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
620
|
+
@pytest.mark.parametrize(
|
|
621
|
+
"field_name,expected_masked,expected_unmasked_length,expected_excluded",
|
|
622
|
+
[
|
|
623
|
+
("password", True, 0, False),
|
|
624
|
+
("validated", True, 0, False),
|
|
625
|
+
("secret", True, 0, False),
|
|
626
|
+
("partial_secret", True, 4, False),
|
|
627
|
+
("unmasked", False, 0, False),
|
|
628
|
+
("excluded", False, 0, True),
|
|
629
|
+
],
|
|
630
|
+
)
|
|
631
|
+
def test_log_config(
|
|
632
|
+
field_name, expected_masked, expected_unmasked_length, expected_excluded
|
|
633
|
+
):
|
|
634
|
+
model = LogConfigModel(
|
|
635
|
+
password="Mypass123.",
|
|
636
|
+
validated="str123",
|
|
618
637
|
secret="super-secret",
|
|
619
638
|
partial_secret="1234567890",
|
|
639
|
+
unmasked="unmasked",
|
|
640
|
+
excluded="excluded",
|
|
620
641
|
)
|
|
621
642
|
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
assert
|
|
627
|
-
assert get_log_config(password_field).unmasked_chars_length == 0
|
|
628
|
-
|
|
629
|
-
assert get_log_config(secret_field).masked is True
|
|
630
|
-
assert get_log_config(secret_field).unmasked_chars_length == 0
|
|
643
|
+
field = model.model_fields[field_name]
|
|
644
|
+
config = get_log_config(field)
|
|
645
|
+
assert config.masked is expected_masked
|
|
646
|
+
assert config.unmasked_chars_length == expected_unmasked_length
|
|
647
|
+
assert config.excluded is expected_excluded
|
|
631
648
|
|
|
632
|
-
assert get_log_config(partial_field).masked is True
|
|
633
|
-
assert get_log_config(partial_field).unmasked_chars_length == 4
|
|
634
649
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
assert
|
|
650
|
+
def test_get_log_config_no_log_config():
|
|
651
|
+
field = FieldInfo(default=None)
|
|
652
|
+
assert get_log_config(field) is None
|
|
File without changes
|
|
File without changes
|
{cuenca_validations-2.0.5.dev4.dist-info → cuenca_validations-2.0.5.dev6.dist-info}/top_level.txt
RENAMED
|
File without changes
|