Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix delivery attempt response content (#9042)
Przemysław Łada9534d6dd83f7
diff --git a/saleor/plugins/webhook/tasks.py b/saleor/plugins/webhook/tasks.pyindex 06572f5243..7febc38ac8 100644--- a/saleor/plugins/webhook/tasks.py+++ b/saleor/plugins/webhook/tasks.py@@ -342,7 +342,9 @@ def send_webhook_request_sync(app_name, delivery):attempt.id,)response.status = EventDeliveryStatus.FAILED- response.content = e.response+ if e.response:+ response.content = e.response.text+ response.response_headers = dict(e.response.headers)except JSONDecodeError as e:logger.warning(@@ -353,7 +355,6 @@ def send_webhook_request_sync(app_name, delivery):attempt.id,)response.status = EventDeliveryStatus.FAILED- response.content = e.msgelse:logger.debug("[Webhook] Success response from %r."diff --git a/saleor/plugins/webhook/tests/test_payment_webhook.py b/saleor/plugins/webhook/tests/test_payment_webhook.pyindex e3cf39d86e..b091cf6726 100644--- a/saleor/plugins/webhook/tests/test_payment_webhook.py+++ b/saleor/plugins/webhook/tests/test_payment_webhook.py@@ -5,7 +5,7 @@ from unittest import mockimport pytestfrom django.conf import settings-from requests import RequestException+from requests import RequestException, TooManyRedirectsfrom ....app.models import Appfrom ....core import EventDeliveryStatus@@ -171,11 +171,32 @@ def test_send_webhook_request_sync_request_exception(assert event_delivery.status == "failed"assert attempt.status == "failed"assert attempt.duration == 0.0- assert attempt.response is None+ assert attempt.response == ""assert attempt.response_headers == "null"assert attempt.request_headers == "null"+ "target_url",+ ("http://payment-gateway.com/api/", "https://payment-gateway.com/api/"),+)[email protected]("saleor.plugins.webhook.tasks.requests.post")+def test_send_webhook_request_sync_when_exception_with_response(+ mock_post, target_url, site_settings, app, event_delivery+):+ mock_response = mock.Mock()+ mock_response.text = "response_content"+ mock_response.headers = {"response": "headers"}+ mock_post.side_effect = TooManyRedirects(response=mock_response)+ # when+ send_webhook_request_sync(app.name, event_delivery)+ attempt = EventDeliveryAttempt.objects.first()++ # then+ assert attempt.response == "response_content"+ assert attempt.response_headers == '{"response": "headers"}'++@pytest.mark.parametrize("target_url",("http://payment-gateway.com/api/", "https://payment-gateway.com/api/"),@@ -202,7 +223,7 @@ def test_send_webhook_request_sync_json_parsing_error(assert event_delivery.status == "failed"assert attempt.status == "failed"assert attempt.duration == expected_data["duration"].total_seconds()- assert attempt.response == "Expecting property name enclosed in double quotes"+ assert attempt.response == expected_data["incorrect_content"]assert attempt.response_headers == json.dumps(expected_data["response_headers"])