Skip to content

Commit 0b43e88

Browse files
authored
Fix download files (#308)
* Fix download files * lint * unify requests User * constraint versions * add cardholder * version * Update requirements.txt
1 parent 8448740 commit 0b43e88

File tree

9 files changed

+261
-22
lines changed

9 files changed

+261
-22
lines changed

cuenca/resources/base.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,25 @@ class Downloadable(Resource):
9797
@classmethod
9898
def download(
9999
cls,
100-
instance,
101-
file_format: FileFormat,
100+
id: str,
101+
file_format: FileFormat = FileFormat.any,
102102
*,
103103
session: Session = global_session,
104104
) -> BytesIO:
105105
resp = session.request(
106106
'get',
107-
f'/{cls._resource}/{instance.id}',
107+
f'/{cls._resource}/{id}',
108108
headers=dict(Accept=file_format.value),
109109
)
110110
return BytesIO(resp)
111111

112112
@property
113113
def pdf(self) -> bytes:
114-
return self.download(self, file_format=FileFormat.pdf).read()
114+
return self.download(self.id, file_format=FileFormat.pdf).read()
115115

116116
@property
117117
def xml(self) -> bytes:
118-
return self.download(self, file_format=FileFormat.xml).read()
118+
return self.download(self.id, file_format=FileFormat.xml).read()
119119

120120

121121
class Uploadable(Resource):

cuenca/resources/cards.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Card(Retrievable, Queryable, Creatable, Updateable):
3131
issuer: CardIssuer
3232
funding_type: CardFundingType
3333
pin_attempts_failed: Optional[int] = None
34+
card_holder_user_id: Optional[int] = None
3435

3536
@property
3637
def last_4_digits(self):
@@ -54,21 +55,24 @@ def create(
5455
issuer: CardIssuer,
5556
funding_type: CardFundingType,
5657
user_id: str = 'me',
58+
card_holder_user_id: Optional[str] = None,
5759
*,
5860
session: Session = global_session,
5961
) -> 'Card':
6062
"""
6163
Assigns user_id and ledger_account_id to a existing virtual card
6264
63-
:param user_id: associated user id
65+
:param user_id: associated user id (Owner of card)
6466
:param funding_type: debit or credit
6567
:param issuer:
68+
:param card_holder_user_id: Holder user of card, not is the owner
6669
:return: New assigned card
6770
"""
6871
req = CardRequest(
6972
user_id=user_id,
7073
issuer=issuer,
7174
funding_type=funding_type,
75+
card_holder_user_id=card_holder_user_id,
7276
)
7377
return cast('Card', cls._create(session=session, **req.dict()))
7478

cuenca/resources/files.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
from io import BytesIO
22
from typing import ClassVar, Optional, cast
33

4-
from cuenca_validations.types import (
5-
FileFormat,
6-
FileQuery,
7-
FileUploadRequest,
8-
KYCFileType,
9-
)
4+
from cuenca_validations.types import FileQuery, FileUploadRequest, KYCFileType
105
from pydantic import HttpUrl
116

127
from ..http import Session, session as global_session
@@ -63,7 +58,7 @@ def file(self) -> bytes:
6358
Bytes of the decrypted file.
6459
Format of the file is found on `file_type` property.
6560
"""
66-
return self.download(self, file_format=FileFormat.any).read()
61+
return self.download(self.id).read()
6762

6863
@property
6964
def pdf(self) -> bytes:

cuenca/resources/users.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
from clabe import Clabe
55
from cuenca_validations.types import (
66
Address,
7-
AddressUpdateRequest,
87
Beneficiary,
98
KYCFile,
10-
KYCFileUpdateRequest,
119
PhoneNumber,
1210
TOSAgreement,
1311
TOSRequest,
@@ -132,11 +130,11 @@ def update(
132130
phone_number: Optional[PhoneNumber] = None,
133131
email_address: Optional[str] = None,
134132
profession: Optional[str] = None,
135-
address: Optional[AddressUpdateRequest] = None,
133+
address: Optional[Address] = None,
136134
beneficiaries: Optional[List[Beneficiary]] = None,
137-
govt_id: Optional[KYCFileUpdateRequest] = None,
138-
proof_of_address: Optional[KYCFileUpdateRequest] = None,
139-
proof_of_life: Optional[KYCFileUpdateRequest] = None,
135+
govt_id: Optional[KYCFile] = None,
136+
proof_of_address: Optional[KYCFile] = None,
137+
proof_of_life: Optional[KYCFile] = None,
140138
terms_of_service: Optional[TOSRequest] = None,
141139
verification_id: Optional[str] = None,
142140
status: Optional[UserStatus] = None,

cuenca/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = '0.14.1'
1+
__version__ = '0.14.2'
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.28
2+
cuenca-validations==0.11.1
33
dataclasses>=0.7;python_version<"3.7"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
install_requires=[
2626
'requests>=2.24,<28',
2727
'dataclasses>=0.7;python_version<"3.7"',
28-
'cuenca-validations>=0.10.18,<0.11.0',
28+
'cuenca-validations>= 0.11.0,<0.12.0',
2929
],
3030
classifiers=[
3131
'Programming Language :: Python :: 3',

tests/resources/cassettes/test_file_download_only_bytes.yaml

Lines changed: 235 additions & 0 deletions
Large diffs are not rendered by default.

tests/resources/test_files.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ def test_file_download():
2121
assert isinstance(file.file, bytes)
2222

2323

24+
@pytest.mark.vcr
25+
def test_file_download_only_bytes():
26+
# Only download Bytes
27+
downloaded_file = File.download('EFXXX')
28+
assert isinstance(downloaded_file.read(), bytes)
29+
30+
2431
@pytest.mark.vcr
2532
def test_file_error_on_xml_pdf():
2633
file: File = File.first(type=KYCFileType.ine)

0 commit comments

Comments
 (0)