From 53a7ca9510f9fc028e64949d9b9e1b9d2e63ea5d Mon Sep 17 00:00:00 2001 From: Mario Hernandez Date: Mon, 20 Jan 2025 21:41:02 -0300 Subject: [PATCH] docs --- docs/django-payments.md | 18 +++------- docs/merchants.md | 10 ------ tests/test_apiclient.py | 75 +++++++++++++++-------------------------- 3 files changed, 32 insertions(+), 71 deletions(-) diff --git a/docs/django-payments.md b/docs/django-payments.md index 0c4b805..3f5654c 100644 --- a/docs/django-payments.md +++ b/docs/django-payments.md @@ -1,21 +1,11 @@ # Integración de Django-Payments con Flow -Django-Payments es un sistema universal de manejo de pagos para Django. Este documento detalla los pasos para integrar Flow con Django-Payments utilizando la librería `pyflowcl`. +Django-Payments es un sistema universal de manejo de pagos para Django. Este documento detalla los pasos para integrar Flow con Django-Payments utilizando la librería `django-payments-chile`. ## Instalación -Existen dos métodos principales para instalar `django-payments-flow`: - -### Usando Poetry - -```shell -poetry add django-payments-flow -``` - -### Usando pip - ```shell -pip install django-payments-flow +pip install django-payments-chile ``` ## Configuración Básica @@ -24,7 +14,7 @@ Configura el proveedor de Flow en tu archivo `settings.py`: ```python PAYMENT_VARIANTS = { - "flow": ("django_payments_flow.FlowProvider", { + "flow": ("django_payments_chile.FlowProvider", { "key": "ApiKey", "secret": "ApiSecret", "sandbox": True, # Usar True para pruebas, False para producción @@ -60,4 +50,4 @@ payment = Payment.objects.create( ## Configuración Avanzada -Para opciones de configuración más avanzadas, consulta la [documentación oficial de django-payments-flow](https://mariofix.github.io/django-payments-flow/uso/#variables-de-configuracion). +Para opciones de configuración más avanzadas, consulta la [documentación oficial de django-payments-chile](https://mariofix.github.io/django-payments-chile). diff --git a/docs/merchants.md b/docs/merchants.md index 691f89d..a51dcb0 100644 --- a/docs/merchants.md +++ b/docs/merchants.md @@ -4,16 +4,6 @@ Merchants es un sistema universal de manejo de pagos para Starlette/FastAPI. Est ## Instalación -Existen dos métodos principales para instalar `merchants`: - -### Usando Poetry - -```shell -poetry add merchants -``` - -### Usando pip - ```shell pip install merchants ``` diff --git a/tests/test_apiclient.py b/tests/test_apiclient.py index 3f5a953..0c1d1b4 100644 --- a/tests/test_apiclient.py +++ b/tests/test_apiclient.py @@ -1,16 +1,17 @@ -import pytest -from unittest.mock import patch, Mock import hashlib import hmac -from pyflowcl.Clients import ApiClient +from unittest.mock import Mock, patch + +import pytest import requests +from pyflowcl.Clients import ApiClient + + @pytest.fixture def api_client(): - return ApiClient( - api_key="test_key", - api_secret="test_secret" - ) + return ApiClient(api_key="test_key", api_secret="test_secret") + @pytest.fixture def mock_response(): @@ -18,51 +19,39 @@ def mock_response(): mock.json.return_value = {"status": "success"} return mock + def test_init_default_values(): client = ApiClient() assert client.api_url == "https://www.flow.cl/api" assert client.api_key is None assert client.api_secret is None + def test_init_custom_values(): - client = ApiClient( - api_url="https://custom.api.url", - api_key="custom_key", - api_secret="custom_secret" - ) + client = ApiClient(api_url="https://custom.api.url", api_key="custom_key", api_secret="custom_secret") assert client.api_url == "https://custom.api.url" assert client.api_key == "custom_key" assert client.api_secret == "custom_secret" + def test_make_signature(api_client): - params = { - "apiKey": "test_key", - "amount": 1000, - "subject": "Test Payment", - "empty": None - } + params = {"apiKey": "test_key", "amount": 1000, "subject": "Test Payment", "empty": None} # Calculate expected signature manually string = "apiKeytest_keyamount1000subjectTest Payment" - expected_signature = hmac.new( - "test_secret".encode(), - string.encode(), - hashlib.sha256 - ).hexdigest() + expected_signature = hmac.new(b"test_secret", string.encode(), hashlib.sha256).hexdigest() assert api_client.make_signature(params) == expected_signature + def test_make_signature_empty_params(api_client): params = {} - expected_signature = hmac.new( - "test_secret".encode(), - "".encode(), - hashlib.sha256 - ).hexdigest() + expected_signature = hmac.new(b"test_secret", b"", hashlib.sha256).hexdigest() assert api_client.make_signature(params) == expected_signature -@patch('requests.get') + +@patch("requests.get") def test_get_request(mock_get, api_client, mock_response): mock_get.return_value = mock_response url = "https://api.example.com/endpoint" @@ -70,14 +59,11 @@ def test_get_request(mock_get, api_client, mock_response): response = api_client.get(url, query_params) - mock_get.assert_called_once_with( - url, - params=query_params, - timeout=5 - ) + mock_get.assert_called_once_with(url, params=query_params, timeout=5) assert response == mock_response -@patch('requests.post') + +@patch("requests.post") def test_post_request(mock_post, api_client, mock_response): mock_post.return_value = mock_response url = "https://api.example.com/endpoint" @@ -85,32 +71,27 @@ def test_post_request(mock_post, api_client, mock_response): response = api_client.post(url, post_data) - mock_post.assert_called_once_with( - url, - data=post_data, - timeout=5 - ) + mock_post.assert_called_once_with(url, data=post_data, timeout=5) assert response == mock_response + def test_make_signature_with_special_chars(api_client): - params = { - "apiKey": "test_key", - "subject": "Test & Payment", - "description": "Payment for item #123" - } + params = {"apiKey": "test_key", "subject": "Test & Payment", "description": "Payment for item #123"} # The signature should handle special characters correctly signature = api_client.make_signature(params) assert len(signature) == 64 # SHA256 produces 64 character hex string -@patch('requests.get') + +@patch("requests.get") def test_get_request_timeout(mock_get, api_client): mock_get.side_effect = requests.Timeout() with pytest.raises(requests.Timeout): api_client.get("https://api.example.com/endpoint", {}) -@patch('requests.post') + +@patch("requests.post") def test_post_request_timeout(mock_post, api_client): mock_post.side_effect = requests.Timeout()