diff --git a/sdk/core/azure-core/CHANGELOG.md b/sdk/core/azure-core/CHANGELOG.md index 7a2d0c81144d..f9d5779cd8d9 100644 --- a/sdk/core/azure-core/CHANGELOG.md +++ b/sdk/core/azure-core/CHANGELOG.md @@ -1,11 +1,15 @@ # Release History -## 1.12.0 (Unreleased) +## 1.12.0 (2021-03-08) ### Features - Added `azure.core.messaging.CloudEvent` model that follows the cloud event spec. -- Added `azure.core.serialization.NULL` sentinel value +- Added `azure.core.serialization.NULL` sentinel value + +### Bug Fixes + +- Improve `repr`s for `HttpRequest` and `HttpResponse`s #16972 ## 1.11.0 (2021-02-08) diff --git a/sdk/core/azure-core/azure/core/pipeline/transport/_base.py b/sdk/core/azure-core/azure/core/pipeline/transport/_base.py index c77212d33e69..6531ea5179f1 100644 --- a/sdk/core/azure-core/azure/core/pipeline/transport/_base.py +++ b/sdk/core/azure-core/azure/core/pipeline/transport/_base.py @@ -234,7 +234,9 @@ def __init__(self, method, url, headers=None, files=None, data=None): self.multipart_mixed_info = None # type: Optional[Tuple] def __repr__(self): - return "" % (self.method) + return "".format( + self.method, self.url + ) def __deepcopy__(self, memo=None): try: @@ -592,6 +594,15 @@ def raise_for_status(self): if self.status_code >= 400: raise HttpResponseError(response=self) + def __repr__(self): + # there doesn't have to be a content type + content_type_str = ( + ", Content-Type: {}".format(self.content_type) if self.content_type else "" + ) + return "<{}: {} {}{}>".format( + type(self).__name__, self.status_code, self.reason, content_type_str + ) + class HttpResponse(_HttpResponseBase): # pylint: disable=abstract-method def stream_download(self, pipeline): diff --git a/sdk/core/azure-core/tests/async_tests/test_universal_http_async.py b/sdk/core/azure-core/tests/async_tests/test_universal_http_async.py index 3c07817cd12b..d4b3e66d523e 100644 --- a/sdk/core/azure-core/tests/async_tests/test_universal_http_async.py +++ b/sdk/core/azure-core/tests/async_tests/test_universal_http_async.py @@ -98,6 +98,8 @@ def __init__(self, body_bytes, headers=None): self._body = body_bytes self._headers = headers self._cache = {} + self.status = 200 + self.reason = "OK" req_response = MockAiohttpClientResponse(body_bytes, headers) @@ -120,3 +122,12 @@ async def test_aiohttp_response_text(): {'Content-Type': 'text/plain'} ) assert res.text(encoding) == '56', "Encoding {} didn't work".format(encoding) + +def test_repr(): + res = _create_aiohttp_response( + b'\xef\xbb\xbf56', + {} + ) + res.content_type = "text/plain" + + assert repr(res) == "" \ No newline at end of file diff --git a/sdk/core/azure-core/tests/test_pipeline.py b/sdk/core/azure-core/tests/test_pipeline.py index fdf11031e4e0..43cf9def610b 100644 --- a/sdk/core/azure-core/tests/test_pipeline.py +++ b/sdk/core/azure-core/tests/test_pipeline.py @@ -285,7 +285,7 @@ def test_request_url_with_params(self): request.format_parameters({"g": "h"}) self.assertIn(request.url, ["a/b/c?g=h&t=y", "a/b/c?t=y&g=h"]) - + def test_request_url_with_params_as_list(self): request = HttpRequest("GET", "/") @@ -300,7 +300,7 @@ def test_request_url_with_params_with_none_in_list(self): request.url = "a/b/c?t=y" with pytest.raises(ValueError): request.format_parameters({"g": ["h",None]}) - + def test_request_url_with_params_with_none(self): request = HttpRequest("GET", "/") @@ -328,6 +328,10 @@ def test_request_text(self): # We want a direct string assert request.data == "foo" + def test_repr(self): + request = HttpRequest("GET", "hello.com") + assert repr(request) == "" + if __name__ == "__main__": unittest.main() diff --git a/sdk/core/azure-core/tests/test_requests_universal.py b/sdk/core/azure-core/tests/test_requests_universal.py index 63f7edebb50e..5a0f778a6b10 100644 --- a/sdk/core/azure-core/tests/test_requests_universal.py +++ b/sdk/core/azure-core/tests/test_requests_universal.py @@ -82,3 +82,10 @@ def test_requests_response_text(): {'Content-Type': 'text/plain'} ) assert res.text(encoding) == '56', "Encoding {} didn't work".format(encoding) + +def test_repr(): + res = _create_requests_response( + b'\xef\xbb\xbf56', + {'Content-Type': 'text/plain'} + ) + assert repr(res) == ""