Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix gateway_get_client_token
Michał Jelonek231b6ed5edff
diff --git a/saleor/payment/utils.py b/saleor/payment/utils.pyindex b2b810cacb..c0aec7c14f 100644--- a/saleor/payment/utils.py+++ b/saleor/payment/utils.py@@ -145,7 +145,7 @@ def gateway_get_client_token(gateway_name: str):client-side tokenization of the chosen payment method."""gateway, gateway_params = get_payment_gateway(gateway_name)- return gateway.get_client_token(**gateway_params)+ return gateway.get_client_token(connection_params=gateway_params)def clean_charge(payment: Payment, amount: Decimal):diff --git a/tests/test_payment.py b/tests/test_payment.pyindex 515ea72dfe..b1c90b2444 100644--- a/tests/test_payment.py+++ b/tests/test_payment.py@@ -2,9 +2,8 @@ from decimal import Decimalfrom unittest.mock import Mock, patchimport pytest-from django.conf import settings+from django.conf import settings as dj_settingsfrom django.core.exceptions import ImproperlyConfigured-from django.forms.models import model_to_dictfrom django.template.loader import get_templatefrom saleor.order import OrderEvents, OrderEventsEmails@@ -181,13 +180,17 @@ def test_create_transaction_no_gateway_response(transaction_data):assert txn.gateway_response == {}-def test_gateway_get_client_token(settings):- gateway_name = list(settings.PAYMENT_GATEWAYS.keys())[0]- gateway = settings.PAYMENT_GATEWAYS[gateway_name]- module = gateway['module']- with patch('%s.get_client_token' % module) as transaction_token_mock:- gateway_get_client_token(gateway_name)- assert transaction_token_mock.called+@patch('saleor.payment.utils.get_payment_gateway')+def test_gateway_get_client_token(get_payment_gateway_mock, gateway_params):+ get_client_token_mock = Mock(return_value='client-token')+ get_payment_gateway_mock.return_value = (+ Mock(get_client_token=get_client_token_mock), gateway_params)++ token = gateway_get_client_token('some-gateway')++ assert token == 'client-token'+ get_client_token_mock.assert_called_once_with(+ connection_params=gateway_params)def test_gateway_get_client_token_not_allowed_gateway(settings):@@ -610,7 +613,7 @@ def test_gateway_refund_errors(payment_txn_captured):assert exc.value.message == 'This payment cannot be refunded.'[email protected]('gateway_name', settings.PAYMENT_GATEWAYS.keys())[email protected]('gateway_name', dj_settings.PAYMENT_GATEWAYS.keys())def test_payment_gateway_templates_exists(gateway_name):"""Test if for each payment gateway there's a correspondingtemplate for the old checkout.@@ -619,7 +622,7 @@ def test_payment_gateway_templates_exists(gateway_name):get_template(template)[email protected]('gateway_name', settings.PAYMENT_GATEWAYS.keys())[email protected]('gateway_name', dj_settings.PAYMENT_GATEWAYS.keys())def test_payment_gateway_form_exists(gateway_name, payment_dummy):"""Test if for each payment gateway there's a correspondingform for the old checkout.