cuenca-validations 2.0.0.dev14__tar.gz → 2.0.1__tar.gz

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.
Files changed (32) hide show
  1. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/PKG-INFO +1 -1
  2. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/cuenca_validations/errors.py +0 -20
  3. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/cuenca_validations/types/__init__.py +2 -2
  4. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/cuenca_validations/types/card.py +10 -5
  5. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/cuenca_validations/types/identities.py +3 -2
  6. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/cuenca_validations/types/morals.py +2 -2
  7. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/cuenca_validations/types/queries.py +2 -2
  8. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/cuenca_validations/types/requests.py +12 -16
  9. cuenca_validations-2.0.1/cuenca_validations/version.py +1 -0
  10. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/cuenca_validations.egg-info/PKG-INFO +1 -1
  11. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/tests/test_card.py +5 -3
  12. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/tests/test_errors.py +0 -5
  13. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/tests/test_types.py +12 -30
  14. cuenca_validations-2.0.0.dev14/cuenca_validations/version.py +0 -1
  15. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/LICENSE +0 -0
  16. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/README.md +0 -0
  17. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/cuenca_validations/__init__.py +0 -0
  18. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/cuenca_validations/card_bins.py +0 -0
  19. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/cuenca_validations/py.typed +0 -0
  20. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/cuenca_validations/types/enums.py +0 -0
  21. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/cuenca_validations/types/files.py +0 -0
  22. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/cuenca_validations/types/general.py +0 -0
  23. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/cuenca_validations/typing.py +0 -0
  24. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/cuenca_validations/validators.py +0 -0
  25. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/cuenca_validations.egg-info/SOURCES.txt +0 -0
  26. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/cuenca_validations.egg-info/dependency_links.txt +0 -0
  27. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/cuenca_validations.egg-info/requires.txt +0 -0
  28. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/cuenca_validations.egg-info/top_level.txt +0 -0
  29. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/setup.cfg +0 -0
  30. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/setup.py +0 -0
  31. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/tests/__init__.py +0 -0
  32. {cuenca_validations-2.0.0.dev14 → cuenca_validations-2.0.1}/tests/test_statement.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: cuenca_validations
3
- Version: 2.0.0.dev14
3
+ Version: 2.0.1
4
4
  Summary: Cuenca common validations
5
5
  Home-page: https://github.com/cuenca-mx/cuenca-validations
6
6
  Author: Cuenca
@@ -1,9 +1,6 @@
1
- from pydantic_core import PydanticCustomError
2
-
3
1
  __all__ = [
4
2
  'ApiError',
5
3
  'AuthMethodNotAllowedError',
6
- 'CardBinValidationError',
7
4
  'CuencaError',
8
5
  'ERROR_CODES',
9
6
  'InvalidOTPCodeError',
@@ -16,23 +13,6 @@ __all__ = [
16
13
  ]
17
14
 
18
15
 
19
- class CardBinValidationError(PydanticCustomError):
20
- code = 'payment_card_number.bin'
21
- msg_template = (
22
- 'The card number contains a BIN (first six digits) that does not have'
23
- 'a known association with a Mexican bank. To add the association,'
24
- 'please file an issue:'
25
- 'https://github.com/cuenca-mx/cuenca-validations/issues'
26
- )
27
-
28
- def __new__(cls):
29
- return super().__new__(
30
- cls,
31
- error_type=cls.code,
32
- message_template=cls.msg_template,
33
- )
34
-
35
-
36
16
  class CuencaError(Exception):
37
17
  """Exceptions related to ApiKeys, Login, Password, etc"""
38
18
 
@@ -22,7 +22,7 @@ __all__ = [
22
22
  'CardTransactionType',
23
23
  'CardType',
24
24
  'Country',
25
- 'CurpField',
25
+ 'Curp',
26
26
  'CurpValidationRequest',
27
27
  'CommissionType',
28
28
  'DepositNetwork',
@@ -159,7 +159,7 @@ from .general import (
159
159
  from .identities import (
160
160
  Address,
161
161
  Beneficiary,
162
- CurpField,
162
+ Curp,
163
163
  KYCFile,
164
164
  PhoneNumber,
165
165
  Rfc,
@@ -1,15 +1,14 @@
1
1
  from typing import Annotated
2
2
 
3
3
  from pydantic import Field, StringConstraints
4
- from pydantic_core import core_schema
4
+ from pydantic_core import PydanticCustomError, core_schema
5
5
  from pydantic_extra_types.payment import PaymentCardNumber
6
6
 
7
7
  from ..card_bins import CARD_BINS
8
- from ..errors import CardBinValidationError
9
8
 
10
9
  ExpMonth = Annotated[int, Field(strict=True, ge=1, le=12)]
11
- ExpYear = Annotated[int, Field(strict=True, ge=18, le=99)]
12
- Cvv2 = Annotated[
10
+ ExpYear = Annotated[int, Field(strict=True, ge=1, le=99)]
11
+ Cvv = Annotated[
13
12
  str,
14
13
  StringConstraints(
15
14
  strip_whitespace=True,
@@ -28,7 +27,13 @@ class StrictPaymentCardNumber(PaymentCardNumber):
28
27
  ) -> 'StrictPaymentCardNumber':
29
28
  card = super().validate(card_number, validation_info)
30
29
  if card.bin not in CARD_BINS:
31
- raise CardBinValidationError
30
+ raise PydanticCustomError(
31
+ 'payment_card_number.bin',
32
+ 'The card number contains a BIN (first six digits) that '
33
+ 'does not have a known association with a Mexican bank. '
34
+ 'To add the association, please file an issue: '
35
+ 'https://github.com/cuenca-mx/cuenca-validations/issues',
36
+ )
32
37
  return cls(card)
33
38
 
34
39
  @property
@@ -6,6 +6,7 @@ from pydantic import (
6
6
  ConfigDict,
7
7
  Field,
8
8
  IPvAnyAddress,
9
+ SecretStr,
9
10
  StringConstraints,
10
11
  model_validator,
11
12
  )
@@ -14,7 +15,7 @@ from pydantic_extra_types.phone_numbers import PhoneNumber
14
15
  from .enums import Country, KYCFileType, State, VerificationStatus
15
16
 
16
17
  Password = Annotated[
17
- str,
18
+ SecretStr,
18
19
  Field(
19
20
  min_length=6,
20
21
  max_length=128,
@@ -24,7 +25,7 @@ Password = Annotated[
24
25
  ),
25
26
  ]
26
27
 
27
- CurpField = Annotated[
28
+ Curp = Annotated[
28
29
  str,
29
30
  StringConstraints(
30
31
  min_length=18,
@@ -3,7 +3,7 @@ from typing import Optional
3
3
 
4
4
  from pydantic import BaseModel, EmailStr
5
5
 
6
- from cuenca_validations.types import Address, CurpField, PhoneNumber, Rfc
6
+ from cuenca_validations.types import Address, Curp, PhoneNumber, Rfc
7
7
 
8
8
 
9
9
  class BusinessDetails(BaseModel):
@@ -52,7 +52,7 @@ class PhysicalPerson(BaseModel):
52
52
  names: str
53
53
  first_surname: str
54
54
  second_surname: Optional[str] = None
55
- curp: Optional[CurpField] = None
55
+ curp: Optional[Curp] = None
56
56
  rfc: Optional[Rfc] = None
57
57
 
58
58
 
@@ -24,7 +24,7 @@ from .enums import (
24
24
  TransferNetwork,
25
25
  UserStatus,
26
26
  )
27
- from .identities import CurpField
27
+ from .identities import Curp
28
28
 
29
29
  MAX_PAGE_SIZE = 100
30
30
 
@@ -158,7 +158,7 @@ class UserQuery(QueryParams):
158
158
 
159
159
 
160
160
  class IdentityQuery(QueryParams):
161
- curp: Optional[CurpField] = None
161
+ curp: Optional[Curp] = None
162
162
  rfc: Optional[str] = None
163
163
  status: Optional[UserStatus] = None
164
164
 
@@ -50,7 +50,7 @@ from ..types.enums import (
50
50
  from ..typing import DictStrAny
51
51
  from ..validators import validate_age_requirement
52
52
  from .card import (
53
- Cvv2,
53
+ Cvv,
54
54
  ExpMonth,
55
55
  ExpYear,
56
56
  PaymentCardNumber,
@@ -60,7 +60,7 @@ from .general import StrictPositiveInt
60
60
  from .identities import (
61
61
  Address,
62
62
  Beneficiary,
63
- CurpField,
63
+ Curp,
64
64
  KYCFile,
65
65
  Password,
66
66
  PhoneNumber,
@@ -145,7 +145,7 @@ class CardActivationRequest(BaseModel):
145
145
  number: PaymentCardNumber
146
146
  exp_month: ExpMonth
147
147
  exp_year: ExpYear
148
- cvv2: Cvv2
148
+ cvv2: Cvv
149
149
 
150
150
 
151
151
  class ApiKeyUpdateRequest(BaseRequest):
@@ -180,9 +180,9 @@ class CardValidationRequest(BaseModel):
180
180
  number: PaymentCardNumber
181
181
  exp_month: Optional[ExpMonth] = None
182
182
  exp_year: Optional[ExpYear] = None
183
- cvv: Optional[Cvv2] = None
184
- cvv2: Optional[Cvv2] = None
185
- icvv: Optional[Cvv2] = None
183
+ cvv: Optional[Cvv] = None
184
+ cvv2: Optional[Cvv] = None
185
+ icvv: Optional[Cvv] = None
186
186
  pin_block: Optional[
187
187
  Annotated[str, StringConstraints(strip_whitespace=True)]
188
188
  ] = None
@@ -327,7 +327,7 @@ class CurpValidationRequest(BaseModel):
327
327
  None, description='In format ISO 3166 Alpha-2'
328
328
  )
329
329
  gender: Optional[Gender] = None
330
- manual_curp: Optional[CurpField] = Field(
330
+ manual_curp: Optional[Curp] = Field(
331
331
  None,
332
332
  description='Force to validate this curp instead of use '
333
333
  'the one we calculate',
@@ -402,7 +402,7 @@ class UserRequest(BaseModel):
402
402
  id: Optional[str] = Field(
403
403
  None, description='if you want to create with specific `id`'
404
404
  )
405
- curp: CurpField = Field(
405
+ curp: Curp = Field(
406
406
  description='Previously validated in `curp_validations`'
407
407
  )
408
408
  phone_number: Optional[PhoneNumber] = Field(
@@ -447,9 +447,7 @@ class UserRequest(BaseModel):
447
447
 
448
448
  @field_validator('curp')
449
449
  @classmethod
450
- def validate_birth_date(
451
- cls, curp: Optional[CurpField]
452
- ) -> Optional[CurpField]:
450
+ def validate_birth_date(cls, curp: Optional[Curp]) -> Optional[Curp]:
453
451
  if curp:
454
452
  current_date = dt.datetime.utcnow()
455
453
  curp_date = curp[4:10]
@@ -587,12 +585,12 @@ class VerificationAttemptRequest(BaseModel):
587
585
 
588
586
 
589
587
  class LimitedWalletRequest(BaseRequest):
590
- allowed_curp: CurpField
588
+ allowed_curp: Curp
591
589
  allowed_rfc: Optional[Rfc] = None
592
590
 
593
591
 
594
592
  class KYCVerificationUpdateRequest(BaseRequest):
595
- curp: CurpField
593
+ curp: Curp
596
594
 
597
595
 
598
596
  class PlatformRequest(BaseModel):
@@ -625,9 +623,7 @@ class BankAccountValidationRequest(BaseModel):
625
623
 
626
624
 
627
625
  class UserListsRequest(BaseModel):
628
- curp: Optional[CurpField] = Field(
629
- None, description='Curp to review on lists'
630
- )
626
+ curp: Optional[Curp] = Field(None, description='Curp to review on lists')
631
627
  account_number: Optional[Union[Clabe, PaymentCardNumber]] = Field(
632
628
  None, description='Account to review on lists'
633
629
  )
@@ -0,0 +1 @@
1
+ __version__ = '2.0.1'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: cuenca_validations
3
- Version: 2.0.0.dev14
3
+ Version: 2.0.1
4
4
  Summary: Cuenca common validations
5
5
  Home-page: https://github.com/cuenca-mx/cuenca-validations
6
6
  Author: Cuenca
@@ -2,7 +2,6 @@ import pytest
2
2
  from pydantic import BaseModel, ValidationError
3
3
  from pydantic_extra_types.payment import PaymentCardBrand
4
4
 
5
- from cuenca_validations.errors import CardBinValidationError
6
5
  from cuenca_validations.types import StrictPaymentCardNumber
7
6
 
8
7
  VALID_BBVA = '4772130000000003'
@@ -18,8 +17,11 @@ def test_invalid_bin_strict_payment():
18
17
  CardModel(card_number=INVALID_BIN)
19
18
  assert exc_info.value.errors()[0] == dict(
20
19
  loc=('card_number',),
21
- type=CardBinValidationError.code,
22
- msg=CardBinValidationError.msg_template,
20
+ type='payment_card_number.bin',
21
+ msg='The card number contains a BIN (first six digits) that does '
22
+ 'not have a known association with a Mexican bank. To add the '
23
+ 'association, please file an issue: '
24
+ 'https://github.com/cuenca-mx/cuenca-validations/issues',
23
25
  input=INVALID_BIN,
24
26
  )
25
27
 
@@ -3,7 +3,6 @@ import pytest
3
3
  from cuenca_validations.errors import (
4
4
  ApiError,
5
5
  AuthMethodNotAllowedError,
6
- CuencaError,
7
6
  InvalidOTPCodeError,
8
7
  MissingAuthorizationHeaderError,
9
8
  NoPasswordFoundError,
@@ -14,10 +13,6 @@ from cuenca_validations.errors import (
14
13
  )
15
14
 
16
15
 
17
- def test_cuenca_error_base():
18
- assert issubclass(CuencaError, Exception)
19
-
20
-
21
16
  @pytest.mark.parametrize(
22
17
  "error_class, expected_code, expected_status",
23
18
  [
@@ -5,14 +5,13 @@ from enum import Enum
5
5
 
6
6
  import pytest
7
7
  from freezegun import freeze_time
8
- from pydantic import BaseModel, ValidationError
8
+ from pydantic import BaseModel, SecretStr, ValidationError
9
9
 
10
10
  from cuenca_validations.types import (
11
11
  Address,
12
12
  CardQuery,
13
13
  JSONEncoder,
14
14
  QueryParams,
15
- Rfc,
16
15
  SantizedDict,
17
16
  SessionRequest,
18
17
  TransactionStatus,
@@ -50,12 +49,12 @@ now = dt.datetime.now()
50
49
  utcnow = now.astimezone(dt.timezone.utc)
51
50
 
52
51
 
53
- class TestEnum(Enum):
52
+ class EnumModel(Enum):
54
53
  zero = 0
55
54
 
56
55
 
57
56
  @dataclass
58
- class TestClass:
57
+ class DictModel:
59
58
  uno: str
60
59
 
61
60
  def to_dict(self):
@@ -116,10 +115,10 @@ def test_count(count, truth):
116
115
  @pytest.mark.parametrize(
117
116
  'value, result',
118
117
  [
119
- (TestEnum.zero, 0),
118
+ (EnumModel.zero, 0),
120
119
  (today, today.isoformat()),
121
120
  (now, utcnow.isoformat()),
122
- (TestClass(uno='uno'), dict(uno='uno', dos='dos')),
121
+ (DictModel(uno='uno'), dict(uno='uno', dos='dos')),
123
122
  (b'test', 'dGVzdA=='), # b64 encode
124
123
  ],
125
124
  )
@@ -158,7 +157,6 @@ class Accounts(BaseModel):
158
157
  )
159
158
  def test_only_digits(input_number, expected):
160
159
  acc = Accounts(number=input_number)
161
- print(acc.model_dump())
162
160
  assert acc.number == expected
163
161
 
164
162
 
@@ -201,7 +199,7 @@ def test_update_one_property_at_a_time_request():
201
199
  UserCredentialUpdateRequest(user_id='US123', password='123456')
202
200
 
203
201
  req = UserCredentialUpdateRequest(password='123456')
204
- assert not req.is_active and req.password == '123456'
202
+ assert not req.is_active and req.password.get_secret_value() == '123456'
205
203
 
206
204
  req = UserCredentialUpdateRequest(is_active=True)
207
205
  assert req.is_active and not req.password
@@ -210,7 +208,10 @@ def test_update_one_property_at_a_time_request():
210
208
  @pytest.mark.parametrize(
211
209
  'data,expected_dict',
212
210
  [
213
- (dict(password='123456'), dict(password='123456', is_active=None)),
211
+ (
212
+ dict(password='123456'),
213
+ dict(password=SecretStr('123456'), is_active=None),
214
+ ),
214
215
  (dict(is_active=True), dict(password=None, is_active=True)),
215
216
  (dict(), dict(password=None, is_active=None)),
216
217
  ],
@@ -558,35 +559,16 @@ def test_bank_account_validation_clabe_request():
558
559
  assert BankAccountValidationRequest(account_number='646180157098510917')
559
560
 
560
561
 
561
- class TestRfc(BaseModel):
562
- rfc: Rfc
563
-
564
-
565
- def test_rfc_field():
566
- with pytest.raises(ValueError):
567
- TestRfc(rfc='')
568
- TestRfc(rfc='invalid')
569
- TestRfc(rfc='ThisValueIsTooLongForRFC')
570
-
571
- assert TestRfc(rfc='TAXM840916123')
572
-
573
-
574
562
  def test_user_lists_request():
575
563
  UserListsRequest(names='Pedro', first_surname='Paramo')
576
564
  with pytest.raises(ValueError):
577
565
  UserListsRequest()
578
566
 
579
567
 
580
- class TestIntModel(BaseModel):
568
+ class IntModel(BaseModel):
581
569
  value: StrictPositiveInt
582
570
 
583
571
 
584
- @pytest.mark.parametrize("value", [100, 1, 21_474_836_47])
585
- def test_strict_positive_int_valid(value):
586
- model = TestIntModel(value=value)
587
- assert model.value == value
588
-
589
-
590
572
  @pytest.mark.parametrize(
591
573
  "value, expected_error, expected_message",
592
574
  [
@@ -603,4 +585,4 @@ def test_strict_positive_int_valid(value):
603
585
  )
604
586
  def test_strict_positive_int_invalid(value, expected_error, expected_message):
605
587
  with pytest.raises(expected_error, match=expected_message):
606
- TestIntModel(value=value)
588
+ IntModel(value=value)
@@ -1 +0,0 @@
1
- __version__ = '2.0.0.dev14'