Skip to content

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

Fix tests for partially charged and partially refunded

Unknown563b82a7b289
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.py
index 3df24f0ec7..e592b713ae 100644
--- a/saleor/dashboard/order/forms.py
+++ b/saleor/dashboard/order/forms.py
@@ -320,9 +320,9 @@ class VoidPaymentForm(ManagePaymentForm):
'Only pre-authorized payments can be voided')
def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
self.payment = kwargs.pop('payment')
self.fields.pop('amount')
- super().__init__(*args, **kwargs)
def void(self):
try:
diff --git a/tests/api/test_order.py b/tests/api/test_order.py
index 876c47885c..bf7c882d49 100644
--- a/tests/api/test_order.py
+++ b/tests/api/test_order.py
@@ -966,7 +966,7 @@ def test_order_capture(
order.refresh_from_db()
assert data['paymentStatus'] == PaymentChargeStatusEnum.CHARGED.name
payment_status_display = dict(ChargeStatus.CHOICES).get(
- ChargeStatus.CHARGED)
+ ChargeStatus.FULLY_CHARGED)
assert data['paymentStatusDisplay'] == payment_status_display
assert data['isPaid']
assert data['totalCaptured']['amount'] == float(amount)
diff --git a/tests/api/test_payment.py b/tests/api/test_payment.py
index 5e6bb2bf5e..f9f5933884 100644
--- a/tests/api/test_payment.py
+++ b/tests/api/test_payment.py
@@ -146,7 +146,7 @@ def test_payment_capture_success(
data = content['data']['paymentCapture']
assert not data['errors']
payment_txn_preauth.refresh_from_db()
- assert payment.charge_status == ChargeStatus.CHARGED
+ assert payment.charge_status == ChargeStatus.FULLY_CHARGED
assert payment.transactions.count() == 2
txn = payment.transactions.last()
assert txn.kind == TransactionKind.CAPTURE
@@ -199,7 +199,7 @@ REFUND_QUERY = """
def test_payment_refund_success(
staff_api_client, permission_manage_orders, payment_txn_captured):
payment = payment_txn_captured
- payment.charge_status = ChargeStatus.CHARGED
+ payment.charge_status = ChargeStatus.FULLY_CHARGED
payment.captured_amount = payment.total
payment.save()
payment_id = graphene.Node.to_global_id(
@@ -224,7 +224,7 @@ def test_payment_refund_error(
staff_api_client, permission_manage_orders, payment_txn_captured,
monkeypatch):
payment = payment_txn_captured
- payment.charge_status = ChargeStatus.CHARGED
+ payment.charge_status = ChargeStatus.FULLY_CHARGED
payment.captured_amount = payment.total
payment.save()
payment_id = graphene.Node.to_global_id(
@@ -243,7 +243,7 @@ def test_payment_refund_error(
assert data['errors'][0]['field'] is None
assert data['errors'][0]['message']
payment.refresh_from_db()
- assert payment.charge_status == ChargeStatus.CHARGED
+ assert payment.charge_status == ChargeStatus.FULLY_CHARGED
assert payment.transactions.count() == 2
txn = payment.transactions.last()
assert txn.kind == TransactionKind.REFUND
diff --git a/tests/conftest.py b/tests/conftest.py
index cd42c8ba3a..41b546d84c 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -553,7 +553,7 @@ def payment_txn_captured(order_with_lines, payment_dummy):
order = order_with_lines
payment = payment_dummy
payment.order = order
- payment.charge_status = ChargeStatus.CHARGED
+ payment.charge_status = ChargeStatus.FULLY_CHARGED
payment.captured_amount = payment.total
payment.save()
diff --git a/tests/dashboard/test_order.py b/tests/dashboard/test_order.py
index b31df9d0a1..a1af56cb22 100644
--- a/tests/dashboard/test_order.py
+++ b/tests/dashboard/test_order.py
@@ -78,7 +78,7 @@ def test_view_capture_order_payment_preauth(
'amount': str(order.total.gross.amount)})
assert response.status_code == 302
payment = order.payments.last()
- assert payment.charge_status == ChargeStatus.CHARGED
+ assert payment.charge_status == ChargeStatus.FULLY_CHARGED
assert payment.captured_amount == order.total.gross.amount
assert payment.currency == order.total.gross.currency
@@ -97,7 +97,7 @@ def test_view_capture_order_invalid_payment_confirmed_status(
url, {'csrfmiddlewaretoken': 'hello', 'amount': '20.00'})
assert response.status_code == 400
payment = order.payments.last()
- assert payment.charge_status == ChargeStatus.CHARGED
+ assert payment.charge_status == ChargeStatus.FULLY_CHARGED
@pytest.mark.integration
@@ -230,7 +230,7 @@ def test_view_void_order_invalid_payment_confirmed_status(
'csrfmiddlewaretoken': 'hello'})
assert response.status_code == 400
order_payment = order.payments.last()
- assert order_payment.charge_status == ChargeStatus.CHARGED
+ assert order_payment.charge_status == ChargeStatus.FULLY_CHARGED
assert order_payment.captured_amount == order.total.gross.amount
assert order_payment.total == order.total.gross.amount
assert order_payment.currency == order.total.gross.currency
diff --git a/tests/gateway/test_dummy.py b/tests/gateway/test_dummy.py
index 878b3d4ee8..a45f45e6cf 100644
--- a/tests/gateway/test_dummy.py
+++ b/tests/gateway/test_dummy.py
@@ -19,7 +19,7 @@ def test_charge_success(payment_dummy):
assert capture_txn.amount == payment_dummy.total
payment_dummy.refresh_from_db()
- assert payment_dummy.charge_status == ChargeStatus.CHARGED
+ assert payment_dummy.charge_status == ChargeStatus.FULLY_CHARGED
assert payment_dummy.captured_amount == payment_dummy.total
assert payment_dummy.is_active
@@ -39,9 +39,13 @@ def test_charge_gateway_error(payment_dummy, monkeypatch):
@pytest.mark.parametrize(
'is_active, charge_status', [
(False, ChargeStatus.NOT_CHARGED),
- (False, ChargeStatus.CHARGED),
+ (False, ChargeStatus.PARTIALLY_CHARGED),
+ (False, ChargeStatus.FULLY_CHARGED),
+ (False, ChargeStatus.PARTIALLY_REFUNDED),
(False, ChargeStatus.FULLY_REFUNDED),
- (True, ChargeStatus.FULLY_REFUNDED),])
+ (True, ChargeStatus.FULLY_CHARGED),
+ (True, ChargeStatus.PARTIALLY_REFUNDED),
+ (True, ChargeStatus.FULLY_REFUNDED), ])
def test_charge_failed(is_active, charge_status, payment_dummy):
payment = payment_dummy
payment.is_active = is_active
@@ -64,10 +68,14 @@ def test_authorize_success(payment_dummy):
@pytest.mark.parametrize(
'is_active, charge_status', [
(False, ChargeStatus.NOT_CHARGED),
- (False, ChargeStatus.CHARGED),
+ (False, ChargeStatus.PARTIALLY_CHARGED),
+ (False, ChargeStatus.FULLY_CHARGED),
+ (False, ChargeStatus.PARTIALLY_REFUNDED),
(False, ChargeStatus.FULLY_REFUNDED),
- (True, ChargeStatus.CHARGED),
- (True, ChargeStatus.FULLY_REFUNDED),])
+ (True, ChargeStatus.PARTIALLY_CHARGED),
+ (True, ChargeStatus.FULLY_CHARGED),
+ (True, ChargeStatus.PARTIALLY_REFUNDED),
+ (True, ChargeStatus.FULLY_REFUNDED), ])
def test_authorize_failed(is_active, charge_status, payment_dummy):
payment = payment_dummy
payment.is_active = is_active
@@ -103,8 +111,13 @@ def test_void_success(payment_txn_preauth):
@pytest.mark.parametrize(
'is_active, charge_status', [
(False, ChargeStatus.NOT_CHARGED),
- (False, ChargeStatus.CHARGED),
- (True, ChargeStatus.CHARGED),
+ (False, ChargeStatus.PARTIALLY_CHARGED),
+ (False, ChargeStatus.FULLY_CHARGED),
+ (False, ChargeStatus.PARTIALLY_REFUNDED),
+ (False, ChargeStatus.FULLY_REFUNDED),
+ (True, ChargeStatus.PARTIALLY_CHARGED),
+ (True, ChargeStatus.FULLY_CHARGED),
+ (True, ChargeStatus.PARTIALLY_REFUNDED),
(True, ChargeStatus.FULLY_REFUNDED), ])
def test_void_failed(is_active, charge_status, payment_dummy):
payment = payment_dummy
@@ -126,22 +139,26 @@ def test_void_gateway_error(payment_txn_preauth, monkeypatch):
assert txn.payment == payment_txn_preauth
[email protected]('amount', [80, 70])
-def test_capture_success(amount, payment_txn_preauth):
+ 'amount', 'charge_status', [
+ (80, ChargeStatus.FULLY_CHARGED),
+ (70, ChargeStatus.PARTIALLY_CHARGED), ])
+def test_capture_success(amount, charge_status, payment_txn_preauth):
txn = gateway_capture(payment=payment_txn_preauth, amount=Decimal(amount))
assert txn.is_success
assert txn.payment == payment_txn_preauth
payment_txn_preauth.refresh_from_db()
- assert payment_txn_preauth.charge_status == ChargeStatus.CHARGED
+ assert payment_txn_preauth.charge_status == charge_status
assert payment_txn_preauth.is_active
@pytest.mark.parametrize(
'amount, captured_amount, charge_status, is_active', [
(80, 0, ChargeStatus.NOT_CHARGED, False),
- (80, 0, ChargeStatus.FULLY_REFUNDED, True),
- (80, 80, ChargeStatus.CHARGED, True),
- (120, 0, ChargeStatus.NOT_CHARGED, True), ])
+ (120, 0, ChargeStatus.NOT_CHARGED, True),
+ (80, 20, ChargeStatus.PARTIALLY_CHARGED, True),
+ (80, 80, ChargeStatus.FULLY_CHARGED, True),
+ (80, 0, ChargeStatus.FULLY_REFUNDED, True), ])
def test_capture_failed(
amount, captured_amount, charge_status, is_active,
payment_dummy):
@@ -169,12 +186,12 @@ def test_capture_gateway_error(payment_txn_preauth, monkeypatch):
'initial_captured_amount, refund_amount, final_captured_amount, final_charge_status, active_after',
[
(80, 80, 0, ChargeStatus.FULLY_REFUNDED, False),
- (80, 10, 70, ChargeStatus.CHARGED, True), ])
+ (80, 10, 70, ChargeStatus.PARTIALLY_REFUNDED, True), ])
def test_refund_success(
initial_captured_amount, refund_amount, final_captured_amount,
final_charge_status, active_after, payment_txn_captured):
payment = payment_txn_captured
- payment.charge_status = ChargeStatus.CHARGED
+ payment.charge_status = ChargeStatus.FULLY_CHARGED
payment.captured_amount = initial_captured_amount
payment.save()
txn = gateway_refund(payment=payment, amount=Decimal(refund_amount))
@@ -188,9 +205,11 @@ def test_refund_success(
@pytest.mark.parametrize(
'initial_captured_amount, refund_amount, initial_charge_status', [
- (80, 0, ChargeStatus.FULLY_REFUNDED),
(0, 10, ChargeStatus.NOT_CHARGED),
- (10, 20, ChargeStatus.CHARGED), ])
+ (10, 20, ChargeStatus.PARTIALLY_CHARGED),
+ (10, 20, ChargeStatus.FULLY_CHARGED),
+ (10, 20, ChargeStatus.PARTIALLY_REFUNDED),
+ (80, 0, ChargeStatus.FULLY_REFUNDED), ])
def test_refund_failed(
initial_captured_amount, refund_amount, initial_charge_status,
payment_dummy):
@@ -207,7 +226,7 @@ def test_refund_gateway_error(payment_txn_captured, monkeypatch):
monkeypatch.setattr(
'saleor.payment.gateways.dummy.dummy_success', lambda: False)
payment = payment_txn_captured
- payment.charge_status = ChargeStatus.CHARGED
+ payment.charge_status = ChargeStatus.FULLY_CHARGED
payment.captured_amount = Decimal('80.00')
payment.save()
with pytest.raises(PaymentError):
@@ -218,16 +237,17 @@ def test_refund_gateway_error(payment_txn_captured, monkeypatch):
assert txn.kind == TransactionKind.REFUND
assert not txn.is_success
assert txn.payment == payment
- assert payment.charge_status == ChargeStatus.CHARGED
+ assert payment.charge_status == ChargeStatus.FULLY_CHARGED
assert payment.captured_amount == Decimal('80.00')
@pytest.mark.parametrize(
'kind, charge_status',
(
- (TransactionKind.REFUND, ChargeStatus.FULLY_REFUNDED),
(TransactionKind.AUTH, ChargeStatus.NOT_CHARGED),
- (TransactionKind.CAPTURE, ChargeStatus.CHARGED)))
+ (TransactionKind.CAPTURE, ChargeStatus.PARTIALLY_CHARGED),
+ (TransactionKind.CAPTURE, ChargeStatus.FULLY_CHARGED),
+ (TransactionKind.REFUND, ChargeStatus.FULLY_REFUNDED), ))
def test_dummy_payment_form(kind, charge_status, settings, payment_dummy):
payment = payment_dummy
data = {'charge_status': charge_status}
diff --git a/tests/gateway/test_razorpay.py b/tests/gateway/test_razorpay.py
index 97b498f7f2..8fd43dda71 100644
--- a/tests/gateway/test_razorpay.py
+++ b/tests/gateway/test_razorpay.py
@@ -43,7 +43,7 @@ def razorpay_payment(payment_dummy):
@pytest.fixture()
def charged_payment(razorpay_payment):
razorpay_payment.captured_amount = razorpay_payment.total
- razorpay_payment.charge_status = ChargeStatus.CHARGED
+ razorpay_payment.charge_status = ChargeStatus.FULLY_CHARGED
razorpay_payment.save(update_fields=['captured_amount', 'charge_status'])
razorpay_payment.transactions.create(
diff --git a/tests/gateway/test_stripe.py b/tests/gateway/test_stripe.py
index 6040c51e20..2ba03c55f8 100644
--- a/tests/gateway/test_stripe.py
+++ b/tests/gateway/test_stripe.py
@@ -66,7 +66,7 @@ def stripe_authorized_payment(stripe_payment):
@pytest.fixture()
def stripe_captured_payment(stripe_payment):
stripe_payment.captured_amount = stripe_payment.total
- stripe_payment.charge_status = ChargeStatus.CHARGED
+ stripe_payment.charge_status = ChargeStatus.FULLY_CHARGED
stripe_payment.save(update_fields=['captured_amount', 'charge_status'])
return stripe_payment
@@ -75,7 +75,7 @@ def stripe_captured_payment(stripe_payment):
@pytest.fixture()
def stripe_charged_payment(stripe_payment):
stripe_payment.captured_amount = stripe_payment.total
- stripe_payment.charge_status = ChargeStatus.CHARGED
+ stripe_payment.charge_status = ChargeStatus.FULLY_CHARGED
stripe_payment.save(update_fields=['captured_amount', 'charge_status'])
stripe_payment.transactions.create(
diff --git a/tests/test_order.py b/tests/test_order.py
index a21ae379bc..08bf2a6910 100644
--- a/tests/test_order.py
+++ b/tests/test_order.py
@@ -368,7 +368,7 @@ def test_order_queryset_to_ship(settings):
]
for order in orders_to_ship:
order.payments.create(
- gateway=settings.DUMMY, charge_status=ChargeStatus.CHARGED,
+ gateway=settings.DUMMY, charge_status=ChargeStatus.FULLY_CHARGED,
total=order.total.gross.amount,
captured_amount=order.total.gross.amount,
currency=order.total.gross.currency)
@@ -464,7 +464,7 @@ def test_order_payment_flow(
'is_active': True,
'total': order.total.gross.amount,
'currency': order.total.gross.currency,
- 'charge_status': ChargeStatus.CHARGED}
+ 'charge_status': ChargeStatus.FULLY_CHARGED}
response = client.post(redirect_url, data)
assert response.status_code == 302
diff --git a/tests/test_payment.py b/tests/test_payment.py
index fa8be06045..10d6f55832 100644
--- a/tests/test_payment.py
+++ b/tests/test_payment.py
@@ -152,7 +152,7 @@ def test_create_payment(address, settings):
def test_mark_as_paid(admin_user, draft_order):
mark_order_as_paid(draft_order, admin_user)
payment = draft_order.payments.last()
- assert payment.charge_status == ChargeStatus.CHARGED
+ assert payment.charge_status == ChargeStatus.FULLY_CHARGED
assert payment.captured_amount == draft_order.total.gross.amount
assert draft_order.events.last().type == (
OrderEvents.ORDER_MARKED_AS_PAID.value)
@@ -275,7 +275,7 @@ def test_gateway_authorize_failed(
def test_gateway_authorize_errors(payment_dummy):
- payment_dummy.charge_status = ChargeStatus.CHARGED
+ payment_dummy.charge_status = ChargeStatus.FULLY_CHARGED
with pytest.raises(PaymentError) as exc:
gateway_authorize(payment_dummy, 'payment-token')
assert exc.value.message == (
@@ -304,7 +304,7 @@ def test_gateway_capture(
payment_information=payment_info, connection_params=gateway_params)
payment.refresh_from_db()
- assert payment.charge_status == ChargeStatus.CHARGED
+ assert payment.charge_status == ChargeStatus.FULLY_CHARGED
assert payment.captured_amount == payment.total
mock_handle_fully_paid_order.assert_called_once_with(payment.order)
@@ -329,7 +329,7 @@ def test_gateway_capture_partial_capture(
gateway_capture(payment, amount)
payment.refresh_from_db()
- assert payment.charge_status == ChargeStatus.CHARGED
+ assert payment.charge_status == ChargeStatus.PARTIALLY_CHARGED
assert payment.captured_amount == amount
assert payment.currency == settings.DEFAULT_CURRENCY
assert not mock_handle_fully_paid_order.called
@@ -401,7 +401,7 @@ def test_gateway_charge(
payment_information=payment_info, connection_params=gateway_params)
payment.refresh_from_db()
- assert payment.charge_status == ChargeStatus.CHARGED
+ assert payment.charge_status == ChargeStatus.FULLY_CHARGED
assert payment.captured_amount == payment.total
mock_handle_fully_paid_order.assert_called_once_with(payment.order)
@@ -427,7 +427,7 @@ def test_gateway_capture_partial_charge(
gateway_charge(payment, payment_token, amount)
payment.refresh_from_db()
- assert payment.charge_status == ChargeStatus.CHARGED
+ assert payment.charge_status == ChargeStatus.PARTIALLY_CHARGED
assert payment.captured_amount == amount
assert payment.currency == settings.DEFAULT_CURRENCY
assert not mock_handle_fully_paid_order.called
@@ -523,7 +523,7 @@ def test_gateway_void_failed(
def test_gateway_void_errors(payment_dummy):
- payment_dummy.charge_status = ChargeStatus.CHARGED
+ payment_dummy.charge_status = ChargeStatus.FULLY_CHARGED
with pytest.raises(PaymentError) as exc:
gateway_void(payment_dummy)
exc.value.message == 'Only pre-authorized transactions can be voided.'
@@ -573,7 +573,7 @@ def test_gateway_refund_partial_refund(
gateway_refund(payment, amount)
payment.refresh_from_db()
- assert payment.charge_status == ChargeStatus.CHARGED
+ assert payment.charge_status == ChargeStatus.PARTIALLY_REFUNDED
assert payment.captured_amount == payment.total - amount
@@ -714,7 +714,10 @@ def test_can_authorize(payment_dummy: Payment):
payment_dummy.is_active = True
assert payment_dummy.can_authorize()
- payment_dummy.charge_status = ChargeStatus.CHARGED
+ payment_dummy.charge_status = ChargeStatus.PARTIALLY_CHARGED
+ assert not payment_dummy.can_authorize()
+
+ payment_dummy.charge_status = ChargeStatus.FULLY_CHARGED
assert not payment_dummy.can_authorize()
@@ -727,7 +730,10 @@ def test_can_capture(payment_txn_preauth: Payment):
payment_txn_preauth.is_active = True
assert payment_txn_preauth.can_capture()
- payment_txn_preauth.charge_status = ChargeStatus.CHARGED
+ payment_txn_preauth.charge_status = ChargeStatus.PARTIALLY_CHARGED
+ assert not payment_txn_preauth.can_capture()
+
+ payment_txn_preauth.charge_status = ChargeStatus.FULLY_CHARGED
assert not payment_txn_preauth.can_capture()
payment_txn_preauth.captured_amount = 0
@@ -744,9 +750,12 @@ def test_can_charge(payment_dummy: Payment):
payment_dummy.is_active = True
assert payment_dummy.can_charge()
- payment_dummy.charge_status = ChargeStatus.CHARGED
+ payment_dummy.charge_status = ChargeStatus.PARTIALLY_CHARGED
assert payment_dummy.can_charge()
+ payment_dummy.charge_status = ChargeStatus.FULLY_CHARGED
+ assert not payment_dummy.can_charge()
+
payment_dummy.captured_amount = payment_dummy.total
assert not payment_dummy.can_charge()
@@ -760,7 +769,10 @@ def test_can_void(payment_txn_preauth: Payment):
payment_txn_preauth.is_active = True
assert payment_txn_preauth.can_void()
- payment_txn_preauth.charge_status = ChargeStatus.CHARGED
+ payment_txn_preauth.charge_status = ChargeStatus.PARTIALLY_CHARGED
+ assert not payment_txn_preauth.can_void()
+
+ payment_txn_preauth.charge_status = ChargeStatus.FULLY_CHARGED
assert not payment_txn_preauth.can_void()
payment_txn_preauth.charge_status = ChargeStatus.NOT_CHARGED
@@ -777,7 +789,10 @@ def test_can_refund(payment_dummy: Payment):
payment_dummy.is_active = True
assert not payment_dummy.can_refund()
- payment_dummy.charge_status = ChargeStatus.CHARGED
+ payment_dummy.charge_status = ChargeStatus.PARTIALLY_CHARGED
+ assert payment_dummy.can_refund()
+
+ payment_dummy.charge_status = ChargeStatus.FULLY_CHARGED
assert payment_dummy.can_refund()