[7.x] Fix Connection.log_*() body parameter type

Co-authored-by: Seth Michael Larson <[email protected]>
This commit is contained in:
github-actions[bot]
2020-10-05 11:38:13 -05:00
committed by GitHub
co-authored by Seth Michael Larson
parent cde2a53468
commit 52a7cfe3fb
3 changed files with 20 additions and 5 deletions
+4 -4
View File
@@ -88,9 +88,9 @@ class Connection(object):
method: str,
full_url: str,
path: str,
body: str,
body: Optional[bytes],
status_code: int,
response: bytes,
response: str,
duration: float,
) -> None: ...
def log_request_fail(
@@ -98,10 +98,10 @@ class Connection(object):
method: str,
full_url: str,
path: str,
body: str,
body: Optional[bytes],
duration: float,
status_code: Optional[int] = ...,
response: Optional[bytes] = ...,
response: Optional[str] = ...,
exception: Optional[Exception] = ...,
) -> None: ...
def _raise_error(self, status_code: int, raw_data: str) -> NoReturn: ...
+1 -1
View File
@@ -166,7 +166,7 @@ class RequestsHttpConnection(Connection):
method,
url,
prepared_request.path_url,
body,
orig_body,
time.time() - start,
exception=e,
)
+15
View File
@@ -27,6 +27,8 @@ import warnings
from requests.auth import AuthBase
from platform import python_version
import pytest
from elasticsearch.exceptions import (
TransportError,
ConflictError,
@@ -754,6 +756,19 @@ class TestRequestsConnection(TestCase):
self.assertEqual('> {"example": "body"}', req[0][0] % req[0][1:])
self.assertEqual("< {}", resp[0][0] % resp[0][1:])
con = self._get_mock_connection(
connection_params={"http_compress": True},
status_code=500,
response_body=b'{"hello":"world"}',
)
with pytest.raises(TransportError):
con.perform_request("GET", "/", body=b'{"example": "body2"}')
self.assertEqual(4, logger.debug.call_count)
_, _, req, resp = logger.debug.call_args_list
self.assertEqual('> {"example": "body2"}', req[0][0] % req[0][1:])
self.assertEqual('< {"hello":"world"}', resp[0][0] % resp[0][1:])
def test_defaults(self):
con = self._get_mock_connection()
request = self._get_request(con, "GET", "/")