Skip to content

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofix committed Dec 13, 2024
1 parent 9531141 commit 82754b9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
4 changes: 0 additions & 4 deletions django_payments_chile/FlowProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
from payments.core import BasicProvider, get_base_url
from payments.forms import PaymentForm as BasePaymentForm

# from pyflowcl import Payment as FlowPayment
# from pyflowcl import Refund as FlowRefund
# from pyflowcl.Clients import ApiClient


class FlowProvider(BasicProvider):
"""
Expand Down
2 changes: 2 additions & 0 deletions django_payments_chile/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

# from .KhipuProvider import KhipuProvider # noqa
# from .PaykuProvider import PaykuProvider # noqa

__all__ = ["FlowProvider"]
33 changes: 25 additions & 8 deletions tests/test_flowprovider.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from unittest import TestCase
from unittest.mock import Mock, patch

from payments import PaymentStatus, RedirectNeeded
import requests
from payments import PaymentError, PaymentStatus, RedirectNeeded

from django_payments_chile.FlowProvider import FlowProvider

Expand Down Expand Up @@ -44,11 +45,7 @@ def get_success_url(self):
return "http://mi-app.cl/exito"


class TestException(Exception):
pass


class TestFlowProviderV3(TestCase):
class TestFlowProviderLive(TestCase):
def test_provider_create_session_success(self):
payment = Payment()
provider = FlowProvider(api_key=API_KEY, api_secret=API_SECRET)
Expand All @@ -73,10 +70,10 @@ def test_provider_create_session_error(self):
with patch("django_payments_chile.FlowProvider.requests.post") as mock_post:
# Simulate an error response
mock_response = Mock()
mock_response.raise_for_status.side_effect = TestException("Error occurred")
mock_response.raise_for_status.side_effect = requests.exceptions.RequestException("Error occurred")
mock_post.return_value = mock_response

with self.assertRaises(TestException):
with self.assertRaises(PaymentError):
provider.get_form(payment)

self.assertEqual(payment.status, PaymentStatus.ERROR)
Expand All @@ -103,3 +100,23 @@ def test_provider_transaction_id_set(self):
provider.get_form(payment)

self.assertEqual(payment.transaction_id, "TOKEN_ID")


class TestFlowProviderSandbox(TestCase):
def test_provider_create_session_success(self):
payment = Payment()
provider = FlowProvider(api_key=API_KEY, api_secret=API_SECRET, api_endpoint="sandbox")
with patch("django_payments_chile.FlowProvider.requests.post") as mock_post:
# Configure mock response
mock_response = Mock()
mock_response.raise_for_status.return_value = None # Simulates no exception raised
mock_response.json.return_value = {"url": "https://flow.cl", "token": "TOKEN_ID", "flowOrder": "ORDER_ID"}
mock_post.return_value = mock_response

with self.assertRaises(RedirectNeeded):
provider.get_form(payment)

self.assertEqual(payment.status, PaymentStatus.WAITING)
self.assertEqual(payment.attrs.respuesta_flow["url"], "https://flow.cl")
self.assertEqual(payment.attrs.respuesta_flow["token"], "TOKEN_ID")
self.assertEqual(payment.attrs.respuesta_flow["flowOrder"], "ORDER_ID")

0 comments on commit 82754b9

Please sign in to comment.