Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add Charge option to Dummy provider and test it

Pacu281eba786d579
diff --git a/saleor/payment/gateways/dummy/__init__.py b/saleor/payment/gateways/dummy/__init__.py
index 3db25eed91..fb2f60bd97 100644
--- a/saleor/payment/gateways/dummy/__init__.py
+++ b/saleor/payment/gateways/dummy/__init__.py
@@ -83,3 +83,12 @@ def refund(payment: Payment, amount: Decimal):
token=str(uuid.uuid4()),
is_success=success)
return txn, error
+
+
+def charge(
+ payment: Payment, payment_token: str, amount: Decimal,
+ **connection_params):
+ """Performs Authorize and Capture transactions in a single run."""
+ authorize(payment_token)
+ txn, error = capture(payment, amount)
+ return txn, error
diff --git a/tests/gateway/test_dummy.py b/tests/gateway/test_dummy.py
index 7956ad7ae0..c90078b050 100644
--- a/tests/gateway/test_dummy.py
+++ b/tests/gateway/test_dummy.py
@@ -1,11 +1,26 @@
from decimal import Decimal
-
+from unittest.mock import patch
import pytest
from saleor.payment import (
ChargeStatus, PaymentError, TransactionKind, get_payment_gateway)
from saleor.payment.gateways.dummy.forms import DummyPaymentForm
+
+@patch('saleor.payment.gateways.dummy.authorize')
+@patch('saleor.payment.gateways.dummy.capture')
+def test_charge(mock_capture, mock_authorize, payment_dummy):
+ token = 'fake-token'
+ amount = payment_dummy.total
+
+ expected_result = ['txn', 'error']
+ mock_capture.return_value = expected_result
+ result = payment_dummy.charge(
+ payment_token=token, amount=amount)
+ assert result == expected_result
+ mock_capture.assert_called_once_with(payment, amount)
+ mock_authorize.assert_called_once_with(token)
+
def test_authorize(payment_dummy):
txn = payment_dummy.authorize(payment_token='Fake')
assert txn.is_success