Skip to content

Commit 748b136

Browse files
committed
Update requirements and refactor User class
1 parent 21690e1 commit 748b136

7 files changed

Lines changed: 95 additions & 147 deletions

File tree

cuenca/resources/users.py

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
PhoneNumber,
1010
SATRegimeCode,
1111
TOSAgreement,
12-
TOSRequest,
1312
UserQuery,
1413
UserRequest,
1514
UserStatus,
1615
UserUpdateRequest,
1716
)
1817
from cuenca_validations.types.enums import Country, Gender, State
1918
from cuenca_validations.types.general import SerializableHttpUrl
20-
from cuenca_validations.types.identities import Curp
19+
from cuenca_validations.types.identities import AddressRequest, Curp
2120
from pydantic import ConfigDict, EmailStr, Field
2221

2322
from ..http import Session, session as global_session
@@ -107,70 +106,54 @@ def balance(self) -> int:
107106
def create(
108107
cls,
109108
curp: Curp,
110-
phone_number: Optional[PhoneNumber] = None,
111-
email_address: Optional[EmailStr] = None,
112109
profession: Optional[str] = None,
113-
address: Optional[Address] = None,
110+
address: Optional[AddressRequest] = None,
114111
email_verification_id: Optional[str] = None,
115112
phone_verification_id: Optional[str] = None,
116-
status: Optional[UserStatus] = None,
117-
required_level: Optional[int] = None,
118-
terms_of_service: Optional[TOSRequest] = None,
119113
*,
120114
session: Session = global_session,
121115
) -> 'User':
122116
req = UserRequest(
123117
curp=curp,
124-
phone_number=phone_number,
125-
email_address=email_address,
126118
profession=profession,
127119
address=address,
128120
email_verification_id=email_verification_id,
129121
phone_verification_id=phone_verification_id,
130-
required_level=required_level,
131-
status=status,
132-
terms_of_service=terms_of_service,
133122
)
134123
return cls._create(session=session, **req.model_dump())
135124

136125
@classmethod
137126
def update(
138127
cls,
139128
user_id: str,
140-
phone_number: Optional[PhoneNumber] = None,
141-
email_address: Optional[str] = None,
142129
profession: Optional[str] = None,
143-
address: Optional[Address] = None,
130+
address: Optional[AddressRequest] = None,
144131
beneficiaries: Optional[list[Beneficiary]] = None,
145132
govt_id: Optional[KYCFile] = None,
146133
proof_of_address: Optional[KYCFile] = None,
147134
proof_of_life: Optional[KYCFile] = None,
148-
terms_of_service: Optional[TOSRequest] = None,
149-
verification_id: Optional[str] = None,
150135
status: Optional[UserStatus] = None,
151136
email_verification_id: Optional[str] = None,
152137
phone_verification_id: Optional[str] = None,
153138
curp_document: Optional[SerializableHttpUrl] = None,
154139
fiscal_regime_code: Optional[SATRegimeCode] = None,
140+
pronouns: Optional[str] = None,
155141
*,
156142
session: Session = global_session,
157143
) -> 'User':
158144
request = UserUpdateRequest(
159-
phone_number=phone_number,
160-
email_address=email_address,
161145
profession=profession,
162146
address=address,
163147
beneficiaries=beneficiaries,
164148
govt_id=govt_id,
165149
proof_of_address=proof_of_address,
166150
proof_of_life=proof_of_life,
167-
terms_of_service=terms_of_service,
168-
verification_id=verification_id,
151+
status=status,
169152
email_verification_id=email_verification_id,
170153
phone_verification_id=phone_verification_id,
171154
curp_document=curp_document,
172155
fiscal_regime_code=fiscal_regime_code,
173-
status=status,
156+
pronouns=pronouns,
174157
)
175158
return cls._update(id=user_id, **request.model_dump(), session=session)
176159

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.13
2+
cuenca-validations==2.1.14.dev1
33
pydantic-extra-types==2.10.2

tests/conftest.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def curp_validation_request() -> dict:
3636
names='José',
3737
first_surname='López',
3838
second_surname='Hernández',
39-
date_of_birth=dt.date(1966, 6, 6),
40-
state_of_birth=State.DF,
39+
date_of_birth=dt.date(1996, 6, 21),
40+
state_of_birth=State.GR,
4141
country_of_birth=Country.MX,
4242
gender=Gender.male,
4343
)
@@ -48,17 +48,15 @@ def curp_validation_request() -> dict:
4848
def user_request() -> dict:
4949
user_dict = dict(
5050
curp='LOHJ660606HDFPRS02',
51-
phone_number='+525511223344',
52-
email_address='jose@test.com',
5351
profession=Profession.empleado,
5452
address=dict(
5553
street='calle 1',
5654
ext_number='2',
5755
int_number='3',
58-
postal_code_id='PC2ygq9j2bS9-9tsuVawzErA',
56+
postal_code_id='PCLo4hi65YTKaAnph27E_2SQ',
5957
),
60-
phone_verification_id='VERdkuqOCjSA2PSS-VCj7HhQ',
61-
email_verification_id='VERppwdqsQSAQFFF-CDsWD8s',
58+
phone_verification_id='VEJlFhtVOgQMG5EpkThHL5Tg',
59+
email_verification_id='VE_r7hBIlaSfe2pEOvMtBEog',
6260
)
6361
return user_dict
6462

tests/resources/cassettes/test_session_create.yaml

Lines changed: 58 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,210 +1,187 @@
11
interactions:
22
- request:
3-
body: '{"names": "Jos\u00e9", "first_surname": "L\u00f3pez", "second_surname":
4-
"Hern\u00e1ndez", "date_of_birth": "1966-06-06", "state_of_birth": "DF", "country_of_birth":
5-
"MX", "gender": "male", "manual_curp": null}'
3+
body: '{"names": "José", "first_surname": "López", "second_surname": "Hernández",
4+
"date_of_birth": "1996-06-21", "state_of_birth": "GR", "country_of_birth": "MX",
5+
"gender": "male", "manual_curp": null}'
66
headers:
7-
Accept:
8-
- '*/*'
9-
Accept-Encoding:
10-
- gzip, deflate
117
Authorization:
128
- DUMMY
13-
Connection:
14-
- keep-alive
159
Content-Length:
16-
- '209'
10+
- '195'
1711
Content-Type:
1812
- application/json
1913
User-Agent:
20-
- cuenca-python/0.7.15.dev3
14+
- cuenca-python/2.1.8
2115
X-Cuenca-Api-Version:
2216
- '2020-03-19'
2317
method: POST
2418
uri: https://sandbox.cuenca.com/curp_validations
2519
response:
2620
body:
27-
string: "{\"id\":\"CV3ZZrphyVSPaGihGwWO8QJQ\",\"created_at\":\"2022-02-09T18:29:24.320854\",\"names\":\"Jos\xE9\",\"first_surname\":\"L\xF3pez\",\"second_surname\":\"Hern\xE1ndez\",\"date_of_birth\":\"1966-06-06\",\"country_of_birth\":\"MX\",\"state_of_birth\":\"DF\",\"gender\":\"male\",\"nationality\":\"MX\",\"manual_curp\":null,\"calculated_curp\":\"LOHJ660606HDFPRS02\",\"validated_curp\":\"LOHJ660606HDFPRS02\",\"renapo_curp_match\":true,\"renapo_full_match\":true}"
21+
string: '{"id":"CViW6DNWVHSEu5QBEYWxC1Wg","created_at":"2025-07-29T17:26:50.871212","names":"José","first_surname":"López","second_surname":"Hernández","date_of_birth":"1996-06-21","country_of_birth":"MX","state_of_birth":"GR","gender":"male","nationality":"MX","manual_curp":null,"calculated_curp":"LOHJ660606HDFPRS02","validated_curp":"LOHJ660606HDFPRS02","renapo_curp_match":true,"renapo_full_match":true,"cve_entidad_emisora":null,"cve_entidad_nacimiento":null,"fecha_nacimiento":null,"fecha_nacimiento_axu":null,"nacionalidad":null,"codigo_error":null,"descripcion_error":null,"documento_probatorio":null,"anio_registro":null,"numero_acta":null,"clave_entidad_federativa_registro":null,"clave_municipio_registro":null,"numero_registro_nacional_extranjeros":null,"folio_carta":null,"folio_certificado":null,"clave_unica_refugiado":null,"estatus":null,"nivel_confiabilidad":null,"curp_historicas":null}'
2822
headers:
2923
Connection:
3024
- keep-alive
3125
Content-Length:
32-
- '402'
26+
- '897'
3327
Content-Type:
3428
- application/json
3529
Date:
36-
- Wed, 09 Feb 2022 18:29:24 GMT
30+
- Tue, 29 Jul 2025 17:26:51 GMT
3731
X-Request-Time:
38-
- 'value: 0.179'
32+
- 'value: 0.273'
3933
x-amz-apigw-id:
40-
- NSYwrGdkCYcF5Og=
34+
- Oe2ePGF3iYcEecQ=
4135
x-amzn-Remapped-Connection:
4236
- keep-alive
4337
x-amzn-Remapped-Content-Length:
44-
- '402'
38+
- '897'
4539
x-amzn-Remapped-Date:
46-
- Wed, 09 Feb 2022 18:29:24 GMT
40+
- Tue, 29 Jul 2025 17:26:51 GMT
4741
x-amzn-Remapped-Server:
48-
- nginx/1.20.2
42+
- nginx/1.28.0
4943
x-amzn-RequestId:
50-
- 9b033a9b-3129-40a8-a366-66875c1b8e39
44+
- 82794d72-54b2-44a3-844f-bd20d3b07515
5145
status:
5246
code: 201
5347
message: Created
5448
- request:
55-
body: '{"curp": "LOHJ660606HDFPRS02", "phone_number": "+525511223344", "email_address":
56-
"jose@test.com", "profession": "employee", "address": {"street": "calle 1",
57-
"ext_number": "2", "postal_code": "09900", "state": "DF", "country": "MX", "city":
58-
null, "int_number": "3"}}'
49+
body: '{"curp": "LOHJ660606HDFPRS02", "profession": "Empleado(a/e)", "address":
50+
{"street": "calle 1", "ext_number": "2", "int_number": "3", "postal_code_id":
51+
"PCLo4hi65YTKaAnph27E_2SQ"}, "phone_verification_id": "VEJlFhtVOgQMG5EpkThHL5Tg",
52+
"email_verification_id": "VE_r7hBIlaSfe2pEOvMtBEog"}'
5953
headers:
60-
Accept:
61-
- '*/*'
62-
Accept-Encoding:
63-
- gzip, deflate
6454
Authorization:
6555
- DUMMY
66-
Connection:
67-
- keep-alive
6856
Content-Length:
69-
- '265'
57+
- '285'
7058
Content-Type:
7159
- application/json
7260
User-Agent:
73-
- cuenca-python/0.7.15.dev3
61+
- cuenca-python/2.1.8
7462
X-Cuenca-Api-Version:
7563
- '2020-03-19'
7664
method: POST
7765
uri: https://sandbox.cuenca.com/users
7866
response:
7967
body:
80-
string: "{\"id\":\"USz-lkjzCBTO2wFzR-FswiqA\",\"identity_uri\":\"/identities/IDKWLi_wUoTty6WXXg9xfKFQ\",\"created_at\":\"2022-02-09T18:29:24.685833\",\"updated_at\":\"2022-02-09T18:29:24.715958\",\"platform_id\":\"PTW68GgAc_QPmNCmgajmctLg\",\"level\":0,\"phone_number\":\"+525511223344\",\"email_address\":\"jose@test.com\",\"profession\":\"employee\",\"status\":\"active\",\"terms_of_service\":null,\"blacklist_validation_status\":\"not_verified\",\"address\":{\"street\":\"calle
81-
1\",\"ext_number\":\"2\",\"int_number\":\"3\",\"postal_code\":\"09900\",\"state\":\"DF\",\"city\":null,\"country\":\"MX\",\"created_at\":\"2022-02-09T18:29:24.685718\"},\"govt_id\":null,\"proof_of_address\":null,\"proof_of_life\":null,\"beneficiaries\":null,\"names\":\"Jos\xE9\",\"first_surname\":\"L\xF3pez\",\"second_surname\":\"Hern\xE1ndez\",\"curp\":\"LOHJ660606HDFPRS02\",\"required_level\":4}"
68+
string: '{"id":"USPR4JxMuwSG60u2h4gBpB6Q","created_at":"2025-07-29T17:26:51.788962","updated_at":"2025-07-29T17:26:53.214399","platform_id":"PTZbBlk__kQt-wfwzP5nwA9A","user_type":"physical","level":0,"required_level":3,"phone_number":"+525555555552","phone_number_is_active":true,"email_address":"test-cuenca-06@yopmail.com","email_address_is_active":true,"clabe":"723324548297159645","status":"active","address":{"street":"calle
69+
1","ext_number":"2","int_number":"3","postal_code":"40106","colonia":"El Naranjo","state":"GR","city":"Iguala
70+
de la Independencia","country":"MX","created_at":"2025-07-29T17:26:51.788790","full_name":null},"identity_uri":"/identities/IDfN3QVig1Qui8oZNrmA4hfw","profession":"Empleado(a/e)","user_tos_agreements_id":null,"blacklist_validation_status":"not_verified","govt_id":null,"proof_of_address":null,"proof_of_life":null,"beneficiaries":[],"curp_status":"succeeded","pronouns":null,"fiscal_regime_code":null,"cash_reference_number":null,"names":"José","first_surname":"López","second_surname":"Hernández","curp":"LOHJ660606HDFPRS02","rfc":"MOOG960621GJ1","gender":"male","date_of_birth":"1996-06-21","state_of_birth":"GR","nationality":"MX","country_of_birth":"MX"}'
8271
headers:
8372
Connection:
8473
- keep-alive
8574
Content-Length:
86-
- '745'
75+
- '1190'
8776
Content-Type:
8877
- application/json
8978
Date:
90-
- Wed, 09 Feb 2022 18:29:25 GMT
91-
X-Request-Time:
92-
- 'value: 0.747'
79+
- Tue, 29 Jul 2025 17:26:54 GMT
9380
x-amz-apigw-id:
94-
- NSYwvE85iYcF_CQ=
81+
- Oe2eVHRNCYcEeEw=
9582
x-amzn-Remapped-Connection:
9683
- keep-alive
9784
x-amzn-Remapped-Content-Length:
98-
- '745'
85+
- '1190'
9986
x-amzn-Remapped-Date:
100-
- Wed, 09 Feb 2022 18:29:25 GMT
87+
- Tue, 29 Jul 2025 17:26:54 GMT
10188
x-amzn-Remapped-Server:
102-
- nginx/1.20.2
89+
- nginx/1.28.0
10390
x-amzn-RequestId:
104-
- 4804d108-50e8-4dd9-a875-6af3137a8474
91+
- 1e474c27-934f-440a-8ba4-c06db1bbec55
10592
status:
10693
code: 201
10794
message: Created
10895
- request:
109-
body: '{"user_id": "USz-lkjzCBTO2wFzR-FswiqA", "type": "session.registration",
96+
body: '{"user_id": "USPR4JxMuwSG60u2h4gBpB6Q", "type": "session.registration",
11097
"success_url": "https://example.com/succeeded_registration", "failure_url":
11198
"https://example.com/failed_registration"}'
11299
headers:
113-
Accept:
114-
- '*/*'
115-
Accept-Encoding:
116-
- gzip, deflate
117100
Authorization:
118101
- DUMMY
119-
Connection:
120-
- keep-alive
121102
Content-Length:
122103
- '190'
123104
Content-Type:
124105
- application/json
125106
User-Agent:
126-
- cuenca-python/0.7.15.dev3
107+
- cuenca-python/2.1.8
127108
X-Cuenca-Api-Version:
128109
- '2020-03-19'
129110
method: POST
130111
uri: https://sandbox.cuenca.com/sessions
131112
response:
132113
body:
133-
string: '{"id":"SSNiy0wLFnRYG0jR12n8qJyA","created_at":"2022-02-09T18:29:25.694402","updated_at":"2022-02-09T18:29:25.694553","user_id":"USz-lkjzCBTO2wFzR-FswiqA","platform_id":"PTW68GgAc_QPmNCmgajmctLg","expires_at":"2022-02-09T18:39:25.694412","success_url":"https://example.com/succeeded_registration","failure_url":"https://example.com/failed_registration","type":"session.registration"}'
114+
string: '{"id":"SSjUSaWbM1S-26rGdhk2r1Aw","created_at":"2025-07-29T17:26:55.884366","user_id":"USPR4JxMuwSG60u2h4gBpB6Q","platform_id":"PTZbBlk__kQt-wfwzP5nwA9A","expires_at":"2025-07-29T17:36:55.884378","success_url":"https://example.com/succeeded_registration","failure_url":"https://example.com/failed_registration","type":"session.registration"}'
134115
headers:
135116
Connection:
136117
- keep-alive
137118
Content-Length:
138-
- '382'
119+
- '340'
139120
Content-Type:
140121
- application/json
141122
Date:
142-
- Wed, 09 Feb 2022 18:29:25 GMT
123+
- Tue, 29 Jul 2025 17:26:55 GMT
143124
X-Request-Time:
144-
- 'value: 0.170'
125+
- 'value: 1.506'
145126
x-amz-apigw-id:
146-
- NSYw5EVlCYcF2Sg=
127+
- Oe2e0EeiCYcEPfA=
147128
x-amzn-Remapped-Connection:
148129
- keep-alive
149130
x-amzn-Remapped-Content-Length:
150-
- '382'
131+
- '340'
151132
x-amzn-Remapped-Date:
152-
- Wed, 09 Feb 2022 18:29:25 GMT
133+
- Tue, 29 Jul 2025 17:26:55 GMT
153134
x-amzn-Remapped-Server:
154-
- nginx/1.20.2
135+
- nginx/1.28.0
155136
x-amzn-RequestId:
156-
- abe06415-7324-4d27-96c2-bf5833967597
137+
- d01c1d75-a1fb-4692-a856-b118f291bde3
157138
status:
158139
code: 201
159140
message: Created
160141
- request:
161-
body: '{"email_address": "manu@example.com"}'
142+
body: '{"profession": "Comercio", "email_verification_id": null, "phone_verification_id":
143+
null, "address": null, "beneficiaries": null, "govt_id": null, "proof_of_address":
144+
null, "proof_of_life": null, "curp_document_uri": null, "fiscal_regime_code":
145+
null, "pronouns": null}'
162146
headers:
163-
Accept:
164-
- '*/*'
165-
Accept-Encoding:
166-
- gzip, deflate
167147
Authorization:
168148
- DUMMY
169-
Connection:
170-
- keep-alive
171149
Content-Length:
172-
- '37'
150+
- '267'
173151
Content-Type:
174152
- application/json
175153
User-Agent:
176-
- cuenca-python/0.7.15.dev3
154+
- cuenca-python/2.1.8
177155
X-Cuenca-Api-Version:
178156
- '2020-03-19'
179157
method: PATCH
180-
uri: https://sandbox.cuenca.com/users/USz-lkjzCBTO2wFzR-FswiqA
158+
uri: https://sandbox.cuenca.com/users/USPR4JxMuwSG60u2h4gBpB6Q
181159
response:
182160
body:
183-
string: "{\"id\":\"USz-lkjzCBTO2wFzR-FswiqA\",\"identity_uri\":\"/identities/IDKWLi_wUoTty6WXXg9xfKFQ\",\"created_at\":\"2022-02-09T18:29:24.685000\",\"updated_at\":\"2022-02-09T18:29:25.958447\",\"platform_id\":\"PTW68GgAc_QPmNCmgajmctLg\",\"level\":0,\"phone_number\":\"+525511223344\",\"email_address\":\"manu@example.com\",\"profession\":\"employee\",\"status\":\"active\",\"terms_of_service\":null,\"blacklist_validation_status\":\"not_verified\",\"address\":{\"street\":\"calle
184-
1\",\"ext_number\":\"2\",\"int_number\":\"3\",\"postal_code\":\"09900\",\"state\":\"DF\",\"city\":null,\"country\":\"MX\",\"created_at\":\"2022-02-09T18:29:24.685000\"},\"govt_id\":null,\"proof_of_address\":null,\"proof_of_life\":null,\"beneficiaries\":null,\"names\":\"Jos\xE9\",\"first_surname\":\"L\xF3pez\",\"second_surname\":\"Hern\xE1ndez\",\"curp\":\"LOHJ660606HDFPRS02\",\"required_level\":4}"
161+
string: '{"id":"USPR4JxMuwSG60u2h4gBpB6Q","created_at":"2025-07-29T17:26:51.788000","updated_at":"2025-07-29T17:26:56.475244","platform_id":"PTZbBlk__kQt-wfwzP5nwA9A","user_type":"physical","level":0,"required_level":3,"phone_number":"+525555555552","phone_number_is_active":true,"email_address":"test-cuenca-06@yopmail.com","email_address_is_active":true,"clabe":"723324548297159645","status":"active","address":{"street":"calle
162+
1","ext_number":"2","int_number":"3","postal_code":"40106","colonia":"El Naranjo","state":"GR","city":"Iguala
163+
de la Independencia","country":"MX","created_at":"2025-07-29T17:26:51.788000","full_name":null},"identity_uri":"/identities/IDfN3QVig1Qui8oZNrmA4hfw","profession":"Comercio","user_tos_agreements_id":null,"blacklist_validation_status":"succeeded","govt_id":null,"proof_of_address":null,"proof_of_life":null,"beneficiaries":[],"curp_status":"succeeded","pronouns":null,"fiscal_regime_code":null,"cash_reference_number":null,"names":"José","first_surname":"López","second_surname":"Hernández","curp":"LOHJ660606HDFPRS02","rfc":"MOOG960621GJ1","gender":"male","date_of_birth":"1996-06-21","state_of_birth":"GR","nationality":"MX","country_of_birth":"MX"}'
185164
headers:
186165
Connection:
187166
- keep-alive
188167
Content-Length:
189-
- '748'
168+
- '1182'
190169
Content-Type:
191170
- application/json
192171
Date:
193-
- Wed, 09 Feb 2022 18:29:26 GMT
194-
X-Request-Time:
195-
- 'value: 0.200'
172+
- Tue, 29 Jul 2025 17:26:56 GMT
196173
x-amz-apigw-id:
197-
- NSYw8F5piYcFZbg=
174+
- Oe2fHHFgiYcEGEw=
198175
x-amzn-Remapped-Connection:
199176
- keep-alive
200177
x-amzn-Remapped-Content-Length:
201-
- '748'
178+
- '1182'
202179
x-amzn-Remapped-Date:
203-
- Wed, 09 Feb 2022 18:29:26 GMT
180+
- Tue, 29 Jul 2025 17:26:56 GMT
204181
x-amzn-Remapped-Server:
205-
- nginx/1.20.2
182+
- nginx/1.28.0
206183
x-amzn-RequestId:
207-
- d4b85fcc-f94e-45a6-af87-695fd395df0c
184+
- d6c4ad54-9764-4c5c-acf8-2a1f4f5a5f26
208185
status:
209186
code: 200
210187
message: OK

0 commit comments

Comments
 (0)