Skip to content

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

GraphQL api test fixes

Michał Jelonek6fc748b5fea4
diff --git a/saleor/graphql/order/mutations/orders.py b/saleor/graphql/order/mutations/orders.py
index c429309254..b36c85c07b 100644
--- a/saleor/graphql/order/mutations/orders.py
+++ b/saleor/graphql/order/mutations/orders.py
@@ -7,7 +7,8 @@ from ....order import OrderEvents, models
from ....order.utils import cancel_order
from ....payment import ChargeStatus, CustomPaymentChoices, PaymentError
from ....payment.models import Payment
-from ....payment.utils import get_billing_data, gateway_void
+from ....payment.utils import (
+ gateway_capture, gateway_void, gateway_refund, get_billing_data)
from ....shipping.models import ShippingMethod as ShippingMethodModel
from ...account.types import AddressInput
from ...core.mutations import BaseMutation
@@ -321,7 +322,7 @@ class OrderCapture(BaseMutation):
# FIXME adjust to multiple payments in the future
payment = order.get_last_payment()
clean_order_capture(payment, amount, errors)
- try_payment_action(payment.capture, amount, errors)
+ try_payment_action(gateway_capture, payment, amount, errors)
if errors:
return OrderCapture(errors=errors)
diff --git a/tests/api/test_order.py b/tests/api/test_order.py
index 470a9ebdba..3ae7587e65 100644
--- a/tests/api/test_order.py
+++ b/tests/api/test_order.py
@@ -1091,18 +1091,10 @@ def test_order_refund(
def test_clean_order_void_payment():
payment = MagicMock(spec=Payment)
payment.is_active = False
- payment.gateway = 'dummy'
errors = clean_void_payment(payment, [])
assert errors[0].field == 'payment'
assert errors[0].message == 'Only pre-authorized payments can be voided'
- payment.is_active = True
- error_msg = 'error has happened.'
- payment.void = Mock(side_effect=ValueError(error_msg))
- errors = clean_void_payment(payment, [])
- assert errors[0].field == 'payment'
- assert errors[0].message == error_msg
-
def test_clean_order_refund_payment():
payment = MagicMock(spec=Payment)
diff --git a/tests/api/test_payment.py b/tests/api/test_payment.py
index 893739ea03..3401a7fa7f 100644
--- a/tests/api/test_payment.py
+++ b/tests/api/test_payment.py
@@ -283,9 +283,9 @@ def test_payment_charge_success(
assert not data['errors']
payment.refresh_from_db()
assert payment.charge_status == ChargeStatus.CHARGED
- assert payment.transactions.count() == 2
+ assert payment.transactions.count() == 1
txn = payment.transactions.last()
- assert txn.kind == TransactionKind.CAPTURE
+ assert txn.kind == TransactionKind.CHARGE
def test_payment_charge_gateway_error(
@@ -314,7 +314,7 @@ def test_payment_charge_gateway_error(
assert payment.charge_status == ChargeStatus.NOT_CHARGED
assert payment.transactions.count() == 1
txn = payment.transactions.last()
- assert txn.kind == TransactionKind.AUTH
+ assert txn.kind == TransactionKind.CHARGE
assert not txn.is_success
@@ -335,8 +335,8 @@ REFUND_QUERY = """
def test_payment_refund_success(
- staff_api_client, permission_manage_orders, payment_dummy):
- payment = payment_dummy
+ staff_api_client, permission_manage_orders, payment_txn_captured):
+ payment = payment_txn_captured
payment.charge_status = ChargeStatus.CHARGED
payment.captured_amount = payment.total
payment.save()
@@ -345,28 +345,28 @@ def test_payment_refund_success(
variables = {
'paymentId': payment_id,
- 'amount': str(payment_dummy.total)}
+ 'amount': str(payment.total)}
response = staff_api_client.post_graphql(
REFUND_QUERY, variables, permissions=[permission_manage_orders])
content = get_graphql_content(response)
data = content['data']['paymentRefund']
assert not data['errors']
- payment_dummy.refresh_from_db()
+ payment.refresh_from_db()
assert payment.charge_status == ChargeStatus.FULLY_REFUNDED
- assert payment.transactions.count() == 1
+ assert payment.transactions.count() == 2
txn = payment.transactions.last()
assert txn.kind == TransactionKind.REFUND
def test_payment_refund_error(
- staff_api_client, permission_manage_orders, payment_dummy,
+ staff_api_client, permission_manage_orders, payment_txn_captured,
monkeypatch):
- payment = payment_dummy
+ payment = payment_txn_captured
payment.charge_status = ChargeStatus.CHARGED
payment.captured_amount = payment.total
payment.save()
payment_id = graphene.Node.to_global_id(
- 'Payment', payment_dummy.pk)
+ 'Payment', payment.pk)
variables = {
'paymentId': payment_id,
'amount': str(payment.total)}
@@ -380,9 +380,9 @@ def test_payment_refund_error(
assert data['errors']
assert data['errors'][0]['field'] is None
assert data['errors'][0]['message']
- payment_dummy.refresh_from_db()
+ payment.refresh_from_db()
assert payment.charge_status == ChargeStatus.CHARGED
- assert payment.transactions.count() == 1
+ assert payment.transactions.count() == 2
txn = payment.transactions.last()
assert txn.kind == TransactionKind.REFUND
assert not txn.is_success