Skip to content

New Resources - Endpoint and Webhook#215

Merged
alexviquez merged 13 commits intocuenca-mx:mainfrom
andreshndz:webhook
Mar 8, 2022
Merged

New Resources - Endpoint and Webhook#215
alexviquez merged 13 commits intocuenca-mx:mainfrom
andreshndz:webhook

Conversation

@andreshndz
Copy link
Copy Markdown
Contributor

@andreshndz andreshndz commented Jan 21, 2022

This is the first approach of Endpoint and Webhook resources.
There are classes that are not defined in this PR, but they will be defined in cuenca-validations.

Our goal is to use the resources as below:

import cuenca

# Endpoint
cuenca.Endpoint.create(url='https://yoururl.com')
cuenca.Endpoint.retrieve('id')
cuenca.Endpoint.all()  # This will retrieve all endpoints 
cuenca.Endpoint.update('id', is_active=False)
cuenca.Endpoint.deactivate('id')

# Webhook
cuenca.Webhook.retrieve('id')
cuenca.Webhook.all()  # This will retrieve all webhooks from his platform 

@andreshndz andreshndz added the enhancement New feature or request label Jan 21, 2022
@andreshndz andreshndz self-assigned this Jan 21, 2022
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 9, 2022

Codecov Report

Merging #215 (c250e0a) into main (f122b4c) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main      #215   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           37        39    +2     
  Lines          927       961   +34     
=========================================
+ Hits           927       961   +34     
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/resources/__init__.py 100.00% <100.00%> (ø)
cuenca/resources/base.py 100.00% <100.00%> (ø)
cuenca/resources/endpoints.py 100.00% <100.00%> (ø)
cuenca/resources/webhooks.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 f122b4c...c250e0a. Read the comment docs.

@andreshndz andreshndz marked this pull request as ready for review February 9, 2022 19:25
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.

Agrega un tes de cuando ya existe el endpoint, no te permita volver a crearlo si no solo actualizarlo

Comment on lines +71 to +80
@classmethod
def deactivate(
cls, endpoint_id: str, *, session: Session = global_session
) -> 'Endpoint':
"""
Deactivates an Endpoint
"""
url = f'{cls._resource}/{endpoint_id}'
resp = session.delete(url)
return cast('Endpoint', cls._from_dict(resp))
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.

reusa el que ya tenemos, se llama 'Deactivable' y esta emplementado en fast-agave

class Deactivable(Resource):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Tengo problemas para usarlo porque posee un campo deactivated_at que no es opcional

requirements.txt Outdated
@@ -1,3 +1,3 @@
requests==2.27.1
cuenca-validations==0.9.18
cuenca-validations==0.9.22.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.

version

Comment on lines +28 to +45
id_endpoint = 'EN02'
endpoint: Endpoint = Endpoint.update(
endpoint_id=id_endpoint, url='https://url.io', is_active=False
)
assert endpoint.id == id_endpoint
assert endpoint.events
assert endpoint.url == 'https://url.io'
assert not endpoint.is_active
assert not endpoint.deactivated_at
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.

puedes agregar validación de que cambio el url a url.io

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Está en la línea 34

Comment on lines +6 to +12
@pytest.mark.vcr
def test_webhook_retrieve():
id_webhook = 'WE01'
webhook: Webhook = Webhook.retrieve(id_webhook)
assert webhook.id == id_webhook
assert webhook.payload
assert webhook.event
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.

puedes hacer un webhook all con más de un webhook en test porfa

Comment on lines +75 to +77
"""
Deactivates an Endpoint
"""
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.

agrega más contexto

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.

Lo de deactivable, y cuidar la info del cassete

Comment on lines +13 to +17


@pytest.mark.vcr
def test_webhook_all():
assert list(Webhook.all())
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.

de un user nadamas, no todos, los cassetrs son gigantes y aparte tiene info de usuarios de stage con teléfonos

Comment on lines 76 to 84
"""
Deactivates an Endpoint
Deactivates an Endpoint. There is no way to activate this endpoint
again

:param endpoint_id: existing endpoint_id
:param session
:return: Deactivated endpoint object
"""
url = f'{cls._resource}/{endpoint_id}'
resp = session.delete(url)
resp = session.delete(f'{cls._resource}/{endpoint_id}')
return cast('Endpoint', cls._from_dict(resp))
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 comprendo porque no puedes usar Deactivable, para eso se diseño con la idea de no repetir código

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ya le investigué un poco más y es que Deactivable trae una propiedad llamada is_active, al igual que Endpoint tiene un atributo llamado is_active

Al correr los tests pasa este error:

FAILED tests/resources/test_endpoints.py::test_endpoint_retrieve - AttributeError: can't set attribute
FAILED tests/resources/test_endpoints.py::test_endpoint_create - AttributeError: can't set attribute
FAILED tests/resources/test_endpoints.py::test_endpoint_update - AttributeError: can't set attribute
FAILED tests/resources/test_endpoints.py::test_endpoint_deactivate - AttributeError: can't set attribute

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.

validations version

@rogelioLpz rogelioLpz self-requested a review March 8, 2022 00:21
@alexviquez alexviquez merged commit 336b14e into cuenca-mx:main Mar 8, 2022
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.

3 participants