[7.x] Fix Connection.log_*() body parameter type
Co-authored-by: Seth Michael Larson <[email protected]>
This commit is contained in:
co-authored by
Seth Michael Larson
parent
cde2a53468
commit
52a7cfe3fb
@@ -88,9 +88,9 @@ class Connection(object):
|
|||||||
method: str,
|
method: str,
|
||||||
full_url: str,
|
full_url: str,
|
||||||
path: str,
|
path: str,
|
||||||
body: str,
|
body: Optional[bytes],
|
||||||
status_code: int,
|
status_code: int,
|
||||||
response: bytes,
|
response: str,
|
||||||
duration: float,
|
duration: float,
|
||||||
) -> None: ...
|
) -> None: ...
|
||||||
def log_request_fail(
|
def log_request_fail(
|
||||||
@@ -98,10 +98,10 @@ class Connection(object):
|
|||||||
method: str,
|
method: str,
|
||||||
full_url: str,
|
full_url: str,
|
||||||
path: str,
|
path: str,
|
||||||
body: str,
|
body: Optional[bytes],
|
||||||
duration: float,
|
duration: float,
|
||||||
status_code: Optional[int] = ...,
|
status_code: Optional[int] = ...,
|
||||||
response: Optional[bytes] = ...,
|
response: Optional[str] = ...,
|
||||||
exception: Optional[Exception] = ...,
|
exception: Optional[Exception] = ...,
|
||||||
) -> None: ...
|
) -> None: ...
|
||||||
def _raise_error(self, status_code: int, raw_data: str) -> NoReturn: ...
|
def _raise_error(self, status_code: int, raw_data: str) -> NoReturn: ...
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ class RequestsHttpConnection(Connection):
|
|||||||
method,
|
method,
|
||||||
url,
|
url,
|
||||||
prepared_request.path_url,
|
prepared_request.path_url,
|
||||||
body,
|
orig_body,
|
||||||
time.time() - start,
|
time.time() - start,
|
||||||
exception=e,
|
exception=e,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ import warnings
|
|||||||
from requests.auth import AuthBase
|
from requests.auth import AuthBase
|
||||||
from platform import python_version
|
from platform import python_version
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from elasticsearch.exceptions import (
|
from elasticsearch.exceptions import (
|
||||||
TransportError,
|
TransportError,
|
||||||
ConflictError,
|
ConflictError,
|
||||||
@@ -754,6 +756,19 @@ class TestRequestsConnection(TestCase):
|
|||||||
self.assertEqual('> {"example": "body"}', req[0][0] % req[0][1:])
|
self.assertEqual('> {"example": "body"}', req[0][0] % req[0][1:])
|
||||||
self.assertEqual("< {}", resp[0][0] % resp[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):
|
def test_defaults(self):
|
||||||
con = self._get_mock_connection()
|
con = self._get_mock_connection()
|
||||||
request = self._get_request(con, "GET", "/")
|
request = self._get_request(con, "GET", "/")
|
||||||
|
|||||||
Reference in New Issue
Block a user