Skip to content

Commit e4f5cd4

Browse files
authored
Add PostalCodes resource (#421)
* Add PostalCodes resource to exports * Add tests * Refactor postal code tests to use parameterized testing and remove obsolete cassette files * Update cuenca-validations to version 2.1.8.dev7 and bump internal version to 2.1.5.dev1 * Update version to 2.1.5 for stable release * Update user profession and add verification IDs in tests * Update cuenca-validations to version 2.1.8 in requirements.txt
1 parent 1a2563d commit e4f5cd4

File tree

11 files changed

+175
-7
lines changed

11 files changed

+175
-7
lines changed

cuenca/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
'JwtToken',
4545
'TermsOfService',
4646
'UserTOSAgreement',
47+
'PostalCodes',
4748
]
4849

4950
from . import http
@@ -73,6 +74,7 @@
7374
LoginToken,
7475
Otp,
7576
Platform,
77+
PostalCodes,
7678
Questionnaires,
7779
Saving,
7880
ServiceProvider,

cuenca/resources/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
'JwtToken',
4141
'TermsOfService',
4242
'UserTOSAgreement',
43+
'PostalCodes',
4344
]
4445

4546
from .accounts import Account
@@ -67,6 +68,7 @@
6768
from .login_tokens import LoginToken
6869
from .otps import Otp
6970
from .platforms import Platform
71+
from .postal_codes import PostalCodes
7072
from .questionnaires import Questionnaires
7173
from .resources import RESOURCES
7274
from .savings import Saving
@@ -126,6 +128,7 @@
126128
WhatsappTransfer,
127129
Webhook,
128130
Platform,
131+
PostalCodes,
129132
JwtToken,
130133
TermsOfService,
131134
UserTOSAgreement,

cuenca/resources/postal_codes.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import datetime as dt
2+
from typing import ClassVar
3+
4+
from cuenca_validations.types import Country, PostalCodeQuery, State
5+
6+
from .base import Queryable, Retrievable
7+
8+
9+
class PostalCodes(Retrievable, Queryable):
10+
_resource: ClassVar = 'postal_codes'
11+
_query_params: ClassVar = PostalCodeQuery
12+
13+
id: str
14+
created_at: dt.datetime
15+
postal_code: str
16+
colonia: str
17+
city: str
18+
state: State
19+
state_name: str
20+
country: Country
21+
country_name: str

cuenca/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = '2.1.4'
1+
__version__ = '2.1.5'
22
CLIENT_VERSION = __version__
33
API_VERSION = '2020-03-19'

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
requests==2.32.3
2-
cuenca-validations==2.1.5
2+
cuenca-validations==2.1.8
33
pydantic-extra-types==2.10.2

tests/conftest.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import pytest
55
from cuenca_validations.types import Country, Gender, State
6+
from cuenca_validations.types.enums import Profession
67

78
import cuenca
89

@@ -49,15 +50,15 @@ def user_request() -> dict:
4950
curp='LOHJ660606HDFPRS02',
5051
phone_number='+525511223344',
5152
email_address='jose@test.com',
52-
profession='employee',
53+
profession=Profession.empleado,
5354
address=dict(
5455
street='calle 1',
5556
ext_number='2',
5657
int_number='3',
57-
postal_code='09900',
58-
state=State.DF.value,
59-
country=Country.MX,
58+
postal_code_id='PC2ygq9j2bS9-9tsuVawzErA',
6059
),
60+
phone_verification_id='VERdkuqOCjSA2PSS-VCj7HhQ',
61+
email_verification_id='VERppwdqsQSAQFFF-CDsWD8s',
6162
)
6263
return user_dict
6364

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
User-Agent:
6+
- cuenca-python/2.1.5
7+
X-Cuenca-Api-Version:
8+
- '2020-03-19'
9+
method: GET
10+
uri: https://sandbox.cuenca.com/postal_codes?postal_code=00000
11+
response:
12+
body:
13+
string: '{"items":[],"next_page_uri":null}'
14+
headers:
15+
Connection:
16+
- keep-alive
17+
Content-Length:
18+
- '33'
19+
Content-Type:
20+
- application/json
21+
Date:
22+
- Thu, 03 Jul 2025 18:44:22 GMT
23+
X-Request-Time:
24+
- 'value: 0.044'
25+
x-amz-apigw-id:
26+
- NJVdIFzWCYcEQnA=
27+
x-amzn-Remapped-Connection:
28+
- keep-alive
29+
x-amzn-Remapped-Content-Length:
30+
- '33'
31+
x-amzn-Remapped-Date:
32+
- Thu, 03 Jul 2025 18:44:22 GMT
33+
x-amzn-Remapped-Server:
34+
- nginx/1.28.0
35+
x-amzn-RequestId:
36+
- 00d3f3a3-2fb5-4b74-8fbf-8ac6dc615ae7
37+
status:
38+
code: 200
39+
message: OK
40+
version: 1
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
User-Agent:
6+
- cuenca-python/2.1.5
7+
X-Cuenca-Api-Version:
8+
- '2020-03-19'
9+
method: GET
10+
uri: https://sandbox.cuenca.com/postal_codes?postal_code=40100
11+
response:
12+
body:
13+
string: "{\"items\":[{\"id\":\"PCHOECy9u6QQeXPR6HdR5Bgw\",\"created_at\":\"2025-06-25T18:44:14.409000\",\"postal_code\":\"40100\",\"colonia\":\"Metlapa\",\"city\":\"Iguala
14+
de la Independencia\",\"state\":\"GR\",\"state_name\":\"Guerrero\",\"country\":\"MX\",\"country_name\":\"M\xE9xico\"}],\"next_page_uri\":null}"
15+
headers:
16+
Connection:
17+
- keep-alive
18+
Content-Length:
19+
- '263'
20+
Content-Type:
21+
- application/json
22+
Date:
23+
- Thu, 03 Jul 2025 18:42:12 GMT
24+
X-Request-Time:
25+
- 'value: 0.046'
26+
x-amz-apigw-id:
27+
- NJVIwHRyCYcEeIw=
28+
x-amzn-Remapped-Connection:
29+
- keep-alive
30+
x-amzn-Remapped-Content-Length:
31+
- '263'
32+
x-amzn-Remapped-Date:
33+
- Thu, 03 Jul 2025 18:42:12 GMT
34+
x-amzn-Remapped-Server:
35+
- nginx/1.28.0
36+
x-amzn-RequestId:
37+
- 75a527b3-8a33-42ed-8633-23dd2b1ddeff
38+
status:
39+
code: 200
40+
message: OK
41+
version: 1
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
User-Agent:
6+
- cuenca-python/2.1.5
7+
X-Cuenca-Api-Version:
8+
- '2020-03-19'
9+
method: GET
10+
uri: https://sandbox.cuenca.com/postal_codes?postal_code=40106
11+
response:
12+
body:
13+
string: "{\"items\":[{\"id\":\"PCqpCtquNnTTWj4afusCWbXQ\",\"created_at\":\"2025-06-25T18:44:14.409000\",\"postal_code\":\"40106\",\"colonia\":\"El
14+
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
15+
de la Independencia\",\"state\":\"GR\",\"state_name\":\"Guerrero\",\"country\":\"MX\",\"country_name\":\"M\xE9xico\"}],\"next_page_uri\":null}"
16+
headers:
17+
Connection:
18+
- keep-alive
19+
Content-Length:
20+
- '495'
21+
Content-Type:
22+
- application/json
23+
Date:
24+
- Thu, 03 Jul 2025 18:44:22 GMT
25+
X-Request-Time:
26+
- 'value: 0.045'
27+
x-amz-apigw-id:
28+
- NJVdFHJXCYcEPzw=
29+
x-amzn-Remapped-Connection:
30+
- keep-alive
31+
x-amzn-Remapped-Content-Length:
32+
- '495'
33+
x-amzn-Remapped-Date:
34+
- Thu, 03 Jul 2025 18:44:22 GMT
35+
x-amzn-Remapped-Server:
36+
- nginx/1.28.0
37+
x-amzn-RequestId:
38+
- 3ff50d45-d63b-4244-9bba-9f7dc776d4bb
39+
status:
40+
code: 200
41+
message: OK
42+
version: 1
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pytest
2+
3+
from cuenca.resources import PostalCodes
4+
5+
6+
@pytest.mark.vcr
7+
@pytest.mark.parametrize(
8+
"postal_code,expected_count",
9+
[
10+
("40100", 1),
11+
("40106", 2),
12+
("00000", 0),
13+
],
14+
)
15+
def test_postal_codes_retrieve(postal_code: str, expected_count: int) -> None:
16+
postal_codes = list(PostalCodes.all(postal_code=postal_code))
17+
assert len(postal_codes) == expected_count

0 commit comments

Comments
 (0)