Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix wrong type in payment mutation. Fix tests in api/test_payment
Maciej Korycinski1d875c3bb38c
diff --git a/saleor/graphql/payment/mutations.py b/saleor/graphql/payment/mutations.pyindex 35546a418b..fb705cd4ce 100644--- a/saleor/graphql/payment/mutations.py+++ b/saleor/graphql/payment/mutations.py@@ -78,8 +78,8 @@ class CheckoutPaymentCreate(BaseMutation, I18nMixin):raise ValidationError({"billing_address": "No billing address associated with this checkout."})- checkout_total = get_total_gross(discounts=info.context.discounts)- amount = data.get("amount", checkout_total)+ checkout_total = get_total_gross(checkout, discounts=info.context.discounts)+ amount = data.get("amount", checkout_total.gross.amount)if amount < checkout_total.gross.amount:raise ValidationError({diff --git a/tests/api/test_payment.py b/tests/api/test_payment.pyindex b4ea2525f7..078c2a4e5d 100644--- a/tests/api/test_payment.py+++ b/tests/api/test_payment.py@@ -1,6 +1,8 @@+from decimal import Decimalfrom unittest.mock import patchimport graphene+from prices import TaxedMoneyfrom saleor.core.utils import get_country_name_by_codefrom saleor.graphql.payment.enums import (@@ -94,12 +96,14 @@ def test_checkout_add_payment():checkout = checkout_with_itemcheckout_id = graphene.Node.to_global_id("Checkout", checkout.pk)+ total = checkout.get_total()+ total = TaxedMoney(net=total, gross=total)variables = {"checkoutId": checkout_id,"input": {"gateway": "DUMMY","token": "sample-token",- "amount": str(checkout.get_total().gross.amount),+ "amount": total.gross.amount,"billingAddress": graphql_address_data,},}@@ -113,9 +117,8 @@ def test_checkout_add_payment(assert payment.checkout == checkoutassert payment.is_activeassert payment.token == "sample-token"- total = checkout.get_total().gross- assert payment.total == total.amount- assert payment.currency == total.currency+ assert payment.total == total.gross.amount+ assert payment.currency == total.gross.currencyassert payment.charge_status == ChargeStatus.NOT_CHARGED@@ -124,12 +127,14 @@ def test_use_checkout_billing_address_as_payment_billing():checkout = checkout_with_itemcheckout_id = graphene.Node.to_global_id("Checkout", checkout.pk)+ total = checkout.get_total()+ total = TaxedMoney(net=total, gross=total)variables = {"checkoutId": checkout_id,"input": {"gateway": "DUMMY","token": "sample-token",- "amount": str(checkout.get_total().gross.amount),+ "amount": total.gross.amount,},}response = user_api_client.post_graphql(CREATE_QUERY, variables)@@ -145,8 +150,7 @@ def test_use_checkout_billing_address_as_payment_billing(checkout.billing_address = addresscheckout.save()response = user_api_client.post_graphql(CREATE_QUERY, variables)- content = get_graphql_content(response)- data = content["data"]["checkoutPaymentCreate"]+ get_graphql_content(response)checkout.refresh_from_db()assert checkout.payments.count() == 1@@ -377,11 +381,12 @@ def test_payments_query(data = content["data"]["payments"]["edges"][0]["node"]pay = payment_txn_capturedassert data["gateway"] == pay.gateway- assert data["capturedAmount"] == {- "amount": pay.captured_amount,- "currency": pay.currency,- }- assert data["total"] == {"amount": pay.total, "currency": pay.currency}+ amount = str(data["capturedAmount"]["amount"])+ assert Decimal(amount) == pay.captured_amount+ assert data["capturedAmount"]["currency"] == pay.currency+ total = str(data["total"]["amount"])+ assert Decimal(total) == pay.total+ assert data["total"]["currency"] == pay.currencyassert data["chargeStatus"] == PaymentChargeStatusEnum.FULLY_CHARGED.nameassert data["billingAddress"] == {"firstName": pay.billing_first_name,