Skip to content

Commit f653ef4

Browse files
authored
Fix beneficiaries on User.update (#297)
* fix beneficiaries * remove breakpoint * Using encoder instead of nested code * lint * change to data * encode directly instead of dumps * versions * version & rebase
1 parent 8005b61 commit f653ef4

File tree

5 files changed

+90
-9
lines changed

5 files changed

+90
-9
lines changed

cuenca/http/client.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import datetime as dt
21
import json
32
import os
43
from typing import Optional, Tuple
54
from urllib.parse import urljoin
65

76
import requests
87
from cuenca_validations.errors import ERROR_CODES
8+
from cuenca_validations.types import JSONEncoder
99
from cuenca_validations.typing import (
1010
ClientRequestParams,
1111
DictStrAny,
@@ -110,16 +110,11 @@ def request(
110110
self.jwt_token = Jwt.create(self)
111111
self.session.headers['X-Cuenca-Token'] = self.jwt_token.token
112112

113-
if data is not None:
114-
for key, value in data.items():
115-
if isinstance(value, dt.date):
116-
data[key] = value.isoformat()
117-
118113
resp = self.session.request(
119114
method=method,
120115
url='https://' + self.host + urljoin('/', endpoint),
121116
auth=self.auth,
122-
json=data,
117+
json=json.loads(JSONEncoder().encode(data)),
123118
params=params,
124119
**kwargs,
125120
)

cuenca/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = '0.13.7'
1+
__version__ = '0.13.8'
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.27.1
2-
cuenca-validations==0.10.22
2+
cuenca-validations==0.10.23
33
dataclasses>=0.7;python_version<"3.7"
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
interactions:
2+
- request:
3+
body: '{"phone_number": null, "email_address": null, "profession": null, "verification_id":
4+
null, "email_verification_id": null, "phone_verification_id": null, "address":
5+
null, "beneficiaries": [{"name": "Pedro P\u00e9rez", "birth_date": "2020-01-01T00:00:00",
6+
"phone_number": "+525555555555", "user_relationship": "brother", "percentage":
7+
50}, {"name": "Jos\u00e9 P\u00e9rez", "birth_date": "2020-01-02T00:00:00", "phone_number":
8+
"+525544444444", "user_relationship": "brother", "percentage": 50}], "govt_id":
9+
null, "proof_of_address": null, "proof_of_life": null, "status": null, "terms_of_service":
10+
null, "platform_terms_of_service": null}'
11+
headers:
12+
Accept:
13+
- '*/*'
14+
Accept-Encoding:
15+
- gzip, deflate
16+
Authorization:
17+
- DUMMY
18+
Connection:
19+
- keep-alive
20+
Content-Length:
21+
- '635'
22+
Content-Type:
23+
- application/json
24+
User-Agent:
25+
- cuenca-python/0.13.6
26+
X-Cuenca-Api-Version:
27+
- '2020-03-19'
28+
method: PATCH
29+
uri: https://sandbox.cuenca.com/users/USw182B9fVTxK3J1A2ElKV7g
30+
response:
31+
body:
32+
string: "{\"id\":\"USw182B9fVTxK3J1A2ElKV7g\",\"identity_uri\":\"/identities/IDYsENkazRRuuZ46KnlN0x1Q\",\"created_at\":\"2022-07-04T20:36:35.007000\",\"updated_at\":\"2022-07-05T18:32:38.470895\",\"platform_id\":\"PTk5UC6RWyQjmDR74oiHlFng\",\"level\":0,\"required_level\":4,\"phone_number\":\"+5299887766\",\"email_address\":\"danisan@mail.com\",\"profession\":null,\"clabe\":null,\"status\":\"active\",\"terms_of_service\":null,\"blacklist_validation_status\":\"not_verified\",\"address\":null,\"govt_id\":null,\"proof_of_address\":null,\"proof_of_life\":null,\"beneficiaries\":[{\"name\":\"Pedro
33+
P\xE9rez\",\"birth_date\":\"2020-01-01\",\"phone_number\":\"+525555555555\",\"user_relationship\":\"brother\",\"percentage\":50,\"created_at\":\"2022-07-05T18:32:38.470632\"},{\"name\":\"Jos\xE9
34+
P\xE9rez\",\"birth_date\":\"2020-01-02\",\"phone_number\":\"+525544444444\",\"user_relationship\":\"brother\",\"percentage\":50,\"created_at\":\"2022-07-05T18:32:38.470703\"}],\"names\":\"Daniel\",\"first_surname\":\"Sanchez\",\"second_surname\":\"Chavez\",\"curp\":\"LOHJ660606HDFPRS02\",\"rfc\":\"LOHJ660606HDF\"}"
35+
headers:
36+
Connection:
37+
- keep-alive
38+
Content-Length:
39+
- '978'
40+
Content-Type:
41+
- application/json
42+
Date:
43+
- Tue, 05 Jul 2022 18:32:38 GMT
44+
x-amz-apigw-id:
45+
- UzmG_FEmCYcF_mA=
46+
x-amzn-Remapped-Connection:
47+
- keep-alive
48+
x-amzn-Remapped-Content-Length:
49+
- '978'
50+
x-amzn-Remapped-Date:
51+
- Tue, 05 Jul 2022 18:32:38 GMT
52+
x-amzn-Remapped-Server:
53+
- nginx/1.22.0
54+
x-amzn-RequestId:
55+
- c6a60f58-418f-4157-b8dc-98a8b13096a5
56+
status:
57+
code: 200
58+
message: OK
59+
version: 1

tests/resources/test_users.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import datetime as dt
2+
13
import pytest
24
from cuenca_validations.types import VerificationType
35

@@ -84,3 +86,28 @@ def test_user_update_user_email_from_verification():
8486
)
8587
user = User.update(user_id, email_verification_id=ver.id)
8688
assert user.to_dict()['email_address'] == ver.recipient
89+
90+
91+
@pytest.mark.vcr
92+
def test_user_beneficiaries_update():
93+
user_id = 'USw182B9fVTxK3J1A2ElKV7g'
94+
request = dict(
95+
beneficiaries=[
96+
dict(
97+
name='Pedro Pérez',
98+
birth_date=dt.date(2020, 1, 1),
99+
phone_number='+525555555555',
100+
user_relationship='brother',
101+
percentage=50,
102+
),
103+
dict(
104+
name='José Pérez',
105+
birth_date=dt.date(2020, 1, 2),
106+
phone_number='+525544444444',
107+
user_relationship='brother',
108+
percentage=50,
109+
),
110+
]
111+
)
112+
user = User.update(user_id, **request)
113+
assert all(item in user.to_dict().keys() for item in request.keys())

0 commit comments

Comments
 (0)