New Resources - Endpoint and Webhook#215
Conversation
Codecov Report
@@ Coverage Diff @@
## main #215 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 37 39 +2
Lines 927 961 +34
=========================================
+ Hits 927 961 +34
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
alexviquez
left a comment
There was a problem hiding this comment.
Agrega un tes de cuando ya existe el endpoint, no te permita volver a crearlo si no solo actualizarlo
cuenca/resources/endpoints.py
Outdated
| @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)) |
There was a problem hiding this comment.
reusa el que ya tenemos, se llama 'Deactivable' y esta emplementado en fast-agave
cuenca-python/cuenca/resources/base.py
Line 83 in f22c4ba
There was a problem hiding this comment.
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 | |||
tests/resources/test_endpoints.py
Outdated
| 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 |
There was a problem hiding this comment.
puedes agregar validación de que cambio el url a url.io
There was a problem hiding this comment.
Está en la línea 34
| @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 |
There was a problem hiding this comment.
puedes hacer un webhook all con más de un webhook en test porfa
cuenca/resources/endpoints.py
Outdated
| """ | ||
| Deactivates an Endpoint | ||
| """ |
alexviquez
left a comment
There was a problem hiding this comment.
Lo de deactivable, y cuidar la info del cassete
|
|
||
|
|
||
| @pytest.mark.vcr | ||
| def test_webhook_all(): | ||
| assert list(Webhook.all()) |
There was a problem hiding this comment.
de un user nadamas, no todos, los cassetrs son gigantes y aparte tiene info de usuarios de stage con teléfonos
cuenca/resources/endpoints.py
Outdated
| """ | ||
| 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)) |
There was a problem hiding this comment.
no comprendo porque no puedes usar Deactivable, para eso se diseño con la idea de no repetir código
There was a problem hiding this comment.
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
This is the first approach of
EndpointandWebhookresources.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: