diff --git a/cuenca/__init__.py b/cuenca/__init__.py index 32551ede..40533eaf 100644 --- a/cuenca/__init__.py +++ b/cuenca/__init__.py @@ -44,6 +44,7 @@ 'JwtToken', 'TermsOfService', 'UserTOSAgreement', + 'PostalCodes', ] from . import http @@ -73,6 +74,7 @@ LoginToken, Otp, Platform, + PostalCodes, Questionnaires, Saving, ServiceProvider, diff --git a/cuenca/resources/__init__.py b/cuenca/resources/__init__.py index 9a0191ea..b61650c0 100644 --- a/cuenca/resources/__init__.py +++ b/cuenca/resources/__init__.py @@ -40,6 +40,7 @@ 'JwtToken', 'TermsOfService', 'UserTOSAgreement', + 'PostalCodes', ] from .accounts import Account @@ -67,6 +68,7 @@ from .login_tokens import LoginToken from .otps import Otp from .platforms import Platform +from .postal_codes import PostalCodes from .questionnaires import Questionnaires from .resources import RESOURCES from .savings import Saving @@ -126,6 +128,7 @@ WhatsappTransfer, Webhook, Platform, + PostalCodes, JwtToken, TermsOfService, UserTOSAgreement, diff --git a/cuenca/resources/postal_codes.py b/cuenca/resources/postal_codes.py new file mode 100644 index 00000000..398018d1 --- /dev/null +++ b/cuenca/resources/postal_codes.py @@ -0,0 +1,21 @@ +import datetime as dt +from typing import ClassVar + +from cuenca_validations.types import Country, PostalCodeQuery, State + +from .base import Queryable, Retrievable + + +class PostalCodes(Retrievable, Queryable): + _resource: ClassVar = 'postal_codes' + _query_params: ClassVar = PostalCodeQuery + + id: str + created_at: dt.datetime + postal_code: str + colonia: str + city: str + state: State + state_name: str + country: Country + country_name: str diff --git a/cuenca/version.py b/cuenca/version.py index 0888f04c..8c121fec 100644 --- a/cuenca/version.py +++ b/cuenca/version.py @@ -1,3 +1,3 @@ -__version__ = '2.1.4' +__version__ = '2.1.5' CLIENT_VERSION = __version__ API_VERSION = '2020-03-19' diff --git a/requirements.txt b/requirements.txt index 50818af8..b2c46c75 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ requests==2.32.3 -cuenca-validations==2.1.5 +cuenca-validations==2.1.8 pydantic-extra-types==2.10.2 diff --git a/tests/conftest.py b/tests/conftest.py index c659e32e..73269127 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,6 +3,7 @@ import pytest from cuenca_validations.types import Country, Gender, State +from cuenca_validations.types.enums import Profession import cuenca @@ -49,15 +50,15 @@ def user_request() -> dict: curp='LOHJ660606HDFPRS02', phone_number='+525511223344', email_address='jose@test.com', - profession='employee', + profession=Profession.empleado, address=dict( street='calle 1', ext_number='2', int_number='3', - postal_code='09900', - state=State.DF.value, - country=Country.MX, + postal_code_id='PC2ygq9j2bS9-9tsuVawzErA', ), + phone_verification_id='VERdkuqOCjSA2PSS-VCj7HhQ', + email_verification_id='VERppwdqsQSAQFFF-CDsWD8s', ) return user_dict diff --git a/tests/resources/cassettes/test_postal_codes_retrieve[00000-0].yaml b/tests/resources/cassettes/test_postal_codes_retrieve[00000-0].yaml new file mode 100644 index 00000000..e893ed4d --- /dev/null +++ b/tests/resources/cassettes/test_postal_codes_retrieve[00000-0].yaml @@ -0,0 +1,40 @@ +interactions: +- request: + body: null + headers: + User-Agent: + - cuenca-python/2.1.5 + X-Cuenca-Api-Version: + - '2020-03-19' + method: GET + uri: https://sandbox.cuenca.com/postal_codes?postal_code=00000 + response: + body: + string: '{"items":[],"next_page_uri":null}' + headers: + Connection: + - keep-alive + Content-Length: + - '33' + Content-Type: + - application/json + Date: + - Thu, 03 Jul 2025 18:44:22 GMT + X-Request-Time: + - 'value: 0.044' + x-amz-apigw-id: + - NJVdIFzWCYcEQnA= + x-amzn-Remapped-Connection: + - keep-alive + x-amzn-Remapped-Content-Length: + - '33' + x-amzn-Remapped-Date: + - Thu, 03 Jul 2025 18:44:22 GMT + x-amzn-Remapped-Server: + - nginx/1.28.0 + x-amzn-RequestId: + - 00d3f3a3-2fb5-4b74-8fbf-8ac6dc615ae7 + status: + code: 200 + message: OK +version: 1 diff --git a/tests/resources/cassettes/test_postal_codes_retrieve[40100-1].yaml b/tests/resources/cassettes/test_postal_codes_retrieve[40100-1].yaml new file mode 100644 index 00000000..2f1cc2b2 --- /dev/null +++ b/tests/resources/cassettes/test_postal_codes_retrieve[40100-1].yaml @@ -0,0 +1,41 @@ +interactions: +- request: + body: null + headers: + User-Agent: + - cuenca-python/2.1.5 + X-Cuenca-Api-Version: + - '2020-03-19' + method: GET + uri: https://sandbox.cuenca.com/postal_codes?postal_code=40100 + response: + body: + string: "{\"items\":[{\"id\":\"PCHOECy9u6QQeXPR6HdR5Bgw\",\"created_at\":\"2025-06-25T18:44:14.409000\",\"postal_code\":\"40100\",\"colonia\":\"Metlapa\",\"city\":\"Iguala + de la Independencia\",\"state\":\"GR\",\"state_name\":\"Guerrero\",\"country\":\"MX\",\"country_name\":\"M\xE9xico\"}],\"next_page_uri\":null}" + headers: + Connection: + - keep-alive + Content-Length: + - '263' + Content-Type: + - application/json + Date: + - Thu, 03 Jul 2025 18:42:12 GMT + X-Request-Time: + - 'value: 0.046' + x-amz-apigw-id: + - NJVIwHRyCYcEeIw= + x-amzn-Remapped-Connection: + - keep-alive + x-amzn-Remapped-Content-Length: + - '263' + x-amzn-Remapped-Date: + - Thu, 03 Jul 2025 18:42:12 GMT + x-amzn-Remapped-Server: + - nginx/1.28.0 + x-amzn-RequestId: + - 75a527b3-8a33-42ed-8633-23dd2b1ddeff + status: + code: 200 + message: OK +version: 1 diff --git a/tests/resources/cassettes/test_postal_codes_retrieve[40106-2].yaml b/tests/resources/cassettes/test_postal_codes_retrieve[40106-2].yaml new file mode 100644 index 00000000..b18d0b07 --- /dev/null +++ b/tests/resources/cassettes/test_postal_codes_retrieve[40106-2].yaml @@ -0,0 +1,42 @@ +interactions: +- request: + body: null + headers: + User-Agent: + - cuenca-python/2.1.5 + X-Cuenca-Api-Version: + - '2020-03-19' + method: GET + uri: https://sandbox.cuenca.com/postal_codes?postal_code=40106 + response: + body: + string: "{\"items\":[{\"id\":\"PCqpCtquNnTTWj4afusCWbXQ\",\"created_at\":\"2025-06-25T18:44:14.409000\",\"postal_code\":\"40106\",\"colonia\":\"El + Naranjo\",\"city\":\"Iguala de la Independencia\",\"state\":\"GR\",\"state_name\":\"Guerrero\",\"country\":\"MX\",\"country_name\":\"M\xE9xico\"},{\"id\":\"PCN2-h_t4ASn-yr46-5C352g\",\"created_at\":\"2025-06-25T18:44:14.409000\",\"postal_code\":\"40106\",\"colonia\":\"Ficus\",\"city\":\"Iguala + de la Independencia\",\"state\":\"GR\",\"state_name\":\"Guerrero\",\"country\":\"MX\",\"country_name\":\"M\xE9xico\"}],\"next_page_uri\":null}" + headers: + Connection: + - keep-alive + Content-Length: + - '495' + Content-Type: + - application/json + Date: + - Thu, 03 Jul 2025 18:44:22 GMT + X-Request-Time: + - 'value: 0.045' + x-amz-apigw-id: + - NJVdFHJXCYcEPzw= + x-amzn-Remapped-Connection: + - keep-alive + x-amzn-Remapped-Content-Length: + - '495' + x-amzn-Remapped-Date: + - Thu, 03 Jul 2025 18:44:22 GMT + x-amzn-Remapped-Server: + - nginx/1.28.0 + x-amzn-RequestId: + - 3ff50d45-d63b-4244-9bba-9f7dc776d4bb + status: + code: 200 + message: OK +version: 1 diff --git a/tests/resources/test_postal_codes.py b/tests/resources/test_postal_codes.py new file mode 100644 index 00000000..76f80712 --- /dev/null +++ b/tests/resources/test_postal_codes.py @@ -0,0 +1,17 @@ +import pytest + +from cuenca.resources import PostalCodes + + +@pytest.mark.vcr +@pytest.mark.parametrize( + "postal_code,expected_count", + [ + ("40100", 1), + ("40106", 2), + ("00000", 0), + ], +) +def test_postal_codes_retrieve(postal_code: str, expected_count: int) -> None: + postal_codes = list(PostalCodes.all(postal_code=postal_code)) + assert len(postal_codes) == expected_count diff --git a/tests/resources/test_users.py b/tests/resources/test_users.py index ef5453d1..c8746e1e 100644 --- a/tests/resources/test_users.py +++ b/tests/resources/test_users.py @@ -2,6 +2,7 @@ import pytest from cuenca_validations.types import VerificationType +from cuenca_validations.types.enums import Profession from cuenca import Verification from cuenca.resources import CurpValidation, User @@ -30,7 +31,7 @@ def test_user_query(): def test_user_update(): user_id = 'USCM-zlFcNQk6ue4gZ_mTGeQ' changes = dict( - profession='programmer', + profession=Profession.sistemas, phone_number='+525555555555', govt_id=dict( type='ine',