Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix for storedPaymentSources raising exception
Krzysztof Świątek583f04358883
diff --git a/saleor/graphql/account/resolvers.py b/saleor/graphql/account/resolvers.pyindex e552dabf1c..8657ae764c 100644--- a/saleor/graphql/account/resolvers.py+++ b/saleor/graphql/account/resolvers.py@@ -106,7 +106,8 @@ def resolve_address_validation_rules(def resolve_payment_sources(user: models.User):stored_customer_accounts = (- (gtw, fetch_customer_id(user, gtw)) for gtw in gateway.list_gateways()+ (gtw["name"], fetch_customer_id(user, gtw["name"]))+ for gtw in gateway.list_gateways())return list(chain(diff --git a/tests/api/test_payment.py b/tests/api/test_payment.pyindex b9a5c58cdf..f23004c353 100644--- a/tests/api/test_payment.py+++ b/tests/api/test_payment.py@@ -516,6 +516,11 @@ def braintree_customer_id():return "1234"+def dummy_customer_id():+ return "4321"++def test_store_payment_gateway_meta(customer_user, braintree_customer_id):gateway_name = "braintree"META = {@@ -541,8 +546,15 @@ def set_braintree_customer_id(customer_user, braintree_customer_id):return customer_user+def set_dummy_customer_id(customer_user, dummy_customer_id):+ gateway_name = "dummy"+ store_customer_id(customer_user, gateway_name, dummy_customer_id)+ return customer_user++def test_list_payment_sources(- mocker, braintree_customer_id, set_braintree_customer_id, user_api_client+ mocker, dummy_customer_id, set_dummy_customer_id, user_api_client):query = """{@@ -559,12 +571,7 @@ def test_list_payment_sources(card = CreditCardInfo(last_4="5678", exp_year=2020, exp_month=12, name_on_card="JohnDoe")- source = CustomerSource(id="test1", gateway="braintree", credit_card_info=card)- mocker.patch(- "saleor.graphql.account.resolvers.gateway.list_gateways",- return_value=["braintree"],- autospec=True,- )+ source = CustomerSource(id="test1", gateway="dummy", credit_card_info=card)mock_get_source_list = mocker.patch("saleor.graphql.account.resolvers.gateway.list_payment_sources",return_value=[source],@@ -572,10 +579,7 @@ def test_list_payment_sources()response = user_api_client.post_graphql(query)- mock_get_source_list.assert_called_once_with("braintree", braintree_customer_id)+ mock_get_source_list.assert_called_once_with("Dummy", dummy_customer_id)content = get_graphql_content(response)["data"]["me"]["storedPaymentSources"]assert content is not None and len(content) == 1- assert content[0] == {- "gateway": "braintree",- "creditCardInfo": {"lastDigits": "5678"},- }+ assert content[0] == {"gateway": "dummy", "creditCardInfo": {"lastDigits": "5678"}}diff --git a/tests/gateway/test_gateway.py b/tests/gateway/test_gateway.pyindex d1d585cc7d..153b96f5e7 100644--- a/tests/gateway/test_gateway.py+++ b/tests/gateway/test_gateway.py@@ -250,7 +250,7 @@ def test_confirm_payment(mock_payment_interface, payment_txn_preauth):def test_list_gateways(mock_payment_interface):- gateways = ["Stripe", "Braintree"]+ gateways = [{"name": "Stripe"}, {"name": "Braintree"}]mock_payment_interface.list_payment_gateways.return_value = gatewayslst = gateway.list_gateways()mock_payment_interface.list_payment_gateways.assert_called_once()