Skip to content

✨ New Resources - File and FileBatch#226

Merged
alexviquez merged 21 commits intocuenca-mx:mainfrom
LuisBrime:patzcuaro
Mar 7, 2022
Merged

✨ New Resources - File and FileBatch#226
alexviquez merged 21 commits intocuenca-mx:mainfrom
LuisBrime:patzcuaro

Conversation

@LuisBrime
Copy link
Copy Markdown
Contributor

@LuisBrime LuisBrime commented Feb 9, 2022

First approach of File resource.

The goal is to use the resource like this:

from io import BytesIO

import cuenca
from cuenca_validations.types import KYCFileType

# Upload a file
with open('my_file_to_upload.png', 'rb') as file:
  encrypted_file = cuenca.File.upload(
      file=BytesIO(file.read()),   # Not sure this is the best way to pass the file
      user_id='US01',              # user_id can be passed to upload a file from another user (omni does this)
      file_type=KYCFileType.ine,   # Pass type of document
      extension='png',             # If not passed, it will be calculated with the bytes but it might not be accurate
  )

encrypted_file.file # Returns bytes of the decrypted file

# Query also is delimited by `user_id`
cuenca.File.all(type=KYCFileType.proof_of_address)
cuenca.File.first(type=KYCFileType.ine)

First approach of FileBatch resource.

The goal is to send patzcuaro multiple links with their KYCFileType. patzcuaro will download, encrypt and save the files, and return the s3 URLs where the files are being saved.

import cuenca
from cuenca_validatons.types import KYCFileType

files = []
files.append(dict(url='XXXX', type=KYCFileType.passport))
files.append(dict(url='XXXX', type=KYCFileType.proof_of_liveness))
files.append(dict(url='XXXX', type=KYCFileType.proof_of_address))

batch = cuenca.FileBatch.create(files=files, user_id='USXXXXXX')

for file in batch.uploaded_files:
  file.url      # https://stage.cuenca.com/files/XXXX
  file.type     # KYCFileType.X

@LuisBrime LuisBrime added the enhancement New feature or request label Feb 9, 2022
@LuisBrime LuisBrime requested a review from alexviquez February 9, 2022 20:37
@LuisBrime LuisBrime self-assigned this Feb 9, 2022
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 9, 2022

Codecov Report

Merging #226 (9c2a052) into main (f22c4ba) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main      #226   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           35        37    +2     
  Lines          873       927   +54     
=========================================
+ Hits           873       927   +54     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
cuenca/__init__.py 100.00% <ø> (ø)
cuenca/http/client.py 100.00% <100.00%> (ø)
cuenca/resources/__init__.py 100.00% <100.00%> (ø)
cuenca/resources/base.py 100.00% <100.00%> (ø)
cuenca/resources/file_batches.py 100.00% <100.00%> (ø)
cuenca/resources/files.py 100.00% <100.00%> (ø)
cuenca/version.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f22c4ba...9c2a052. Read the comment docs.

Copy link
Copy Markdown
Contributor

@alexviquez alexviquez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahí va, hay que ajustarlo



@dataclass
class File(Creatable, Downloadable, Queryable):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uploadable

Comment on lines +26 to +41
@classmethod
def create(
cls,
file: BytesIO,
*,
session: Session = global_session,
) -> 'File':
"""
Stores an encrypted version of the file,
only users with permissions can access it.

:param session:
:return: New encrypted file object
"""
req = FileRequest(file=file.read())
response = session.post(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hay que usar uploadable para acá

Comment on lines +56 to +61
@property
def pdf(self) -> bytes:
"""
Override property value for `Donwlodable`
"""
return self.file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pon mejor un raise de NotImplementedError

Copy link
Copy Markdown
Contributor

@alexviquez alexviquez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unos comments respecto al user_id, no es necesario que lo pases en el body del request, vive en toda la sesión gracias a los blueprints, revisa como funcionan acá:
https://github.com/cuenca-mx/agave

resp = session.request(
'post',
cls._resource,
data=dict(user_id=user_id),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No necesitas majera el user_id en el cuerpo del post request, el user_id lo tienes en toda la sesión

@LuisBrime LuisBrime changed the title New Resource - File ✨ New Resources - File and FileBatch Mar 2, 2022
@LuisBrime LuisBrime requested a review from alexviquez March 4, 2022 16:45
Copy link
Copy Markdown
Contributor

@alexviquez alexviquez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unos cambios, el meme del perrito esta genial jaja

Comment on lines +11 to +21
url='https://media.getmati.com/file?location=XXX1',
type=KYCFileType.ine,
is_back=True,
),
dict(
url='https://media.getmati.com/file?location=XXX2',
type=KYCFileType.proof_of_liveness,
),
dict(
url='https://media.getmati.com/file?location=XXX3',
type=KYCFileType.proof_of_address,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cambia el path, debe ser no genérico

Copy link
Copy Markdown
Contributor

@alexviquez alexviquez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unos comments

@@ -0,0 +1 @@
python-magic-bin==0.4.14
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quitar

@@ -1,3 +1,3 @@
__version__ = '0.7.14'
__version__ = '0.7.16.dev1'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ajustar versión

Makefile Outdated
Comment on lines +21 to +22
install-dev: install-test
pip install -qU -r requirements-dev.txt
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

esto se va también

python_requires='>=3.6',
install_requires=[
'requests>=2.24,<28',
'cuenca-validations>=0.9.18,<0.9.19',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cambiar esto

@alexviquez alexviquez merged commit f122b4c into cuenca-mx:main Mar 7, 2022
@LuisBrime LuisBrime deleted the patzcuaro branch March 8, 2022 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants