def test_use_customer_id_from_meta_on_client_token_generation( mocker, token_config_with_customer, braintree_customer_id, set_braintree_customer_id, user_api_client, ): query = """ query paymentClientToken($gateway: GatewaysEnum) { paymentClientToken(gateway: $gateway) } """ TOKEN = "sample_token" mock_get_token = mocker.patch( "saleor.graphql.payment.resolvers.gateway_get_client_token", return_value=TOKEN, autospec=True, ) variables = {"gateway": PaymentGatewayEnum.BRAINTREE.name} response = user_api_client.post_graphql(query, variables) mock_get_token.assert_called_once_with( "braintree", TokenConfig(customer_id=braintree_customer_id) ) content = get_graphql_content(response) assert content["data"]["paymentClientToken"] == TOKEN
def test_get_client_token_with_no_customer_id_when_disabled( mock_gateway, gateway_config): expected_token = "client-token" mock_generate = Mock(return_value=expected_token) mock_gateway.return_value = Mock(client_token=Mock(generate=mock_generate)) token = get_client_token(gateway_config, TokenConfig(customer_id="1234")) mock_gateway.assert_called_once_with(**gateway_config.connection_params) mock_generate.assert_called_once_with({}) assert token == expected_token
def test_get_client_token_with_customer_id(mock_gateway, gateway_config_with_store_enabled): expected_token = "client-token" mock_generate = Mock(return_value=expected_token) mock_gateway.return_value = Mock(client_token=Mock(generate=mock_generate)) token = get_client_token(gateway_config_with_store_enabled, TokenConfig(customer_id="1234")) mock_gateway.assert_called_once_with( **gateway_config_with_store_enabled.connection_params) mock_generate.assert_called_once_with({"customer_id": "1234"}) assert token == expected_token
def test_gateway_get_client_token(get_payment_gateway_mock, gateway_config): get_client_token_mock = Mock(return_value="client-token") get_payment_gateway_mock.return_value = ( Mock(get_client_token=get_client_token_mock), gateway_config, ) token = gateway_get_client_token("some-gateway") assert token == "client-token" get_client_token_mock.assert_called_once_with(config=gateway_config, token_config=TokenConfig())
def token_config_with_customer(braintree_customer_id): return TokenConfig(customer_id=braintree_customer_id)