Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add tests for charge failure and gateway error for dummy gateway
Unknown256e97f0c581
diff --git a/tests/gateway/test_dummy.py b/tests/gateway/test_dummy.pyindex 27cd37b8bc..3501c568e5 100644--- a/tests/gateway/test_dummy.py+++ b/tests/gateway/test_dummy.py@@ -1,5 +1,4 @@from decimal import Decimal-from unittest.mock import patch, Mockimport pytestfrom saleor.payment import (@@ -7,7 +6,7 @@ from saleor.payment import (from saleor.payment.gateways.dummy.forms import DummyPaymentForm-def test_charge(payment_dummy):+def test_charge_success(payment_dummy):payment_dummy.charge(payment_token='fake-token', amount=payment_dummy.total)capture_txn, auth_txn = payment_dummy.transactions.all()@@ -27,7 +26,33 @@ def test_charge(payment_dummy):assert payment_dummy.is_active-def test_authorize(payment_dummy):+def test_charge_gateway_error(payment_dummy, monkeypatch):+ monkeypatch.setattr(+ 'saleor.payment.gateways.dummy.dummy_success', lambda: False)+ with pytest.raises(PaymentError):+ txn = payment_dummy.charge(payment_token='Fake', amount=payment_dummy.total)+ assert txn.kind == TransactionKind.CHARGE+ assert not txn.is_success+ assert txn.payment == payment_dummy+++ 'is_active, charge_status', [+ (False, ChargeStatus.NOT_CHARGED),+ (False, ChargeStatus.CHARGED),+ (False, ChargeStatus.FULLY_REFUNDED),+ (True, ChargeStatus.FULLY_REFUNDED),])+def test_charge_failed(is_active, charge_status, payment_dummy):+ payment = payment_dummy+ payment.is_active = is_active+ payment.charge_status = charge_status+ payment.save()+ with pytest.raises(PaymentError):+ txn = payment.charge(payment_token='Fake')+ assert txn is None+++def test_authorize_success(payment_dummy):txn = payment_dummy.authorize(payment_token='Fake')assert txn.is_successassert txn.kind == TransactionKind.AUTH@@ -36,6 +61,23 @@ def test_authorize(payment_dummy):assert payment_dummy.is_active+ 'is_active, charge_status', [+ (False, ChargeStatus.NOT_CHARGED),+ (False, ChargeStatus.CHARGED),+ (False, ChargeStatus.FULLY_REFUNDED),+ (True, ChargeStatus.CHARGED),+ (True, ChargeStatus.FULLY_REFUNDED),])+def test_authorize_failed(is_active, charge_status, payment_dummy):+ payment = payment_dummy+ payment.is_active = is_active+ payment.charge_status = charge_status+ payment.save()+ with pytest.raises(PaymentError):+ txn = payment.authorize(payment_token='Fake')+ assert txn is None++def test_authorize_gateway_error(payment_dummy, monkeypatch):monkeypatch.setattr('saleor.payment.gateways.dummy.dummy_success', lambda: False)