Skip to content

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

Update test_adyen_check_payment_timeout test (#9070)

Iga Karbowiak003a1657a227
diff --git a/saleor/payment/gateways/adyen/tests/test_plugin.py b/saleor/payment/gateways/adyen/tests/test_plugin.py
index 4fe7744603..20be0cf3d8 100644
--- a/saleor/payment/gateways/adyen/tests/test_plugin.py
+++ b/saleor/payment/gateways/adyen/tests/test_plugin.py
@@ -4,9 +4,8 @@ from unittest import mock
import Adyen
import pytest
-import requests
from django.core.exceptions import ValidationError
-from requests.exceptions import RequestException, SSLError
+from requests.exceptions import ConnectTimeout, RequestException, SSLError
from .....plugins.models import PluginConfiguration
from .... import PaymentError, TransactionKind
@@ -670,9 +669,7 @@ def test_adyen_check_payment_balance(
@mock.patch("saleor.payment.gateways.adyen.plugin.api_call")
-def test_adyen_check_payment_balance_adyen_raises_error(
- api_call_mock, adyen_plugin, adyen_check_balance_response
-):
+def test_adyen_check_payment_balance_adyen_raises_error(api_call_mock, adyen_plugin):
api_call_mock.return_value = Adyen.AdyenError("Error")
plugin = adyen_plugin()
@@ -705,8 +702,8 @@ def test_adyen_check_payment_balance_adyen_raises_error(
)
[email protected]("saleor.payment.gateways.adyen.utils.common.HTTP_TIMEOUT", 0.001)
-def test_adyen_check_payment_timeout(adyen_plugin, adyen_check_balance_response):
[email protected]("requests.post")
+def test_adyen_check_payment_timeout(request_post_mock, adyen_plugin):
plugin = adyen_plugin()
data = {
@@ -719,5 +716,6 @@ def test_adyen_check_payment_timeout(adyen_plugin, adyen_check_balance_response)
},
}
- with pytest.raises(requests.exceptions.ConnectTimeout):
- plugin.check_payment_balance(data)
+ request_post_mock.side_effect = ConnectTimeout()
+ res = plugin.check_payment_balance(data)
+ assert res.startswith("Unable to process the payment request")
diff --git a/saleor/payment/gateways/adyen/utils/common.py b/saleor/payment/gateways/adyen/utils/common.py
index 2ae78e5efd..730697c13d 100644
--- a/saleor/payment/gateways/adyen/utils/common.py
+++ b/saleor/payment/gateways/adyen/utils/common.py
@@ -9,6 +9,7 @@ import opentracing.tags
from Adyen.httpclient import HTTPClient
from django.conf import settings
from django_countries.fields import Country
+from requests.exceptions import ConnectTimeout
from .....checkout.calculations import checkout_shipping_price, checkout_total
from .....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
@@ -73,7 +74,7 @@ def api_call(
) -> Adyen.Adyen:
try:
return method(request_data, **kwargs)
- except (Adyen.AdyenError, ValueError, TypeError) as e:
+ except (Adyen.AdyenError, ValueError, TypeError, ConnectTimeout) as e:
logger.warning(f"Unable to process the payment: {e}")
raise PaymentError(f"Unable to process the payment request: {e}.")