From c13129dced486196585d91f7ea8ca53ab25b4c73 Mon Sep 17 00:00:00 2001 From: HimanshuBarak Date: Thu, 11 Jan 2024 12:28:04 +0530 Subject: [PATCH 1/4] Add async test for test_compress_compressed_no_header_offline --- .../tests/async_tests/test_streaming_async.py | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/sdk/core/azure-core/tests/async_tests/test_streaming_async.py b/sdk/core/azure-core/tests/async_tests/test_streaming_async.py index b7b4f8cc17dc..b28758312f07 100644 --- a/sdk/core/azure-core/tests/async_tests/test_streaming_async.py +++ b/sdk/core/azure-core/tests/async_tests/test_streaming_async.py @@ -180,7 +180,26 @@ async def test_decompress_compressed_header(http_request): decoded = content.decode("utf-8") assert decoded == "test" - +@pytest.mark.asyncio +@pytest.mark.parametrize("http_request", HTTP_REQUESTS) +async def test_compress_compressed_no_header_offline(port, http_request): + # expect compressed text + client = AsyncPipelineClient("") + async with client: + request = http_request(method="GET", url="http://localhost:{}/streams/compressed_no_header".format(port)) + pipeline_response = await client._pipeline.run(request,stream=True) + response = pipeline_response.http_response + data = response.stream_download(client._pipeline,decompress=False) + content = b"" + async for d in data: + content += d + try: + decoded = content.decode("utf-8") + assert False + except UnicodeDecodeError: + pass + + @pytest.mark.live_test_only @pytest.mark.asyncio @pytest.mark.parametrize("http_request", HTTP_REQUESTS) From 5f5627ca1a5982d3ec0c0aeaf31e47771c9e3d33 Mon Sep 17 00:00:00 2001 From: Himanshu Barak Date: Sat, 20 Jan 2024 15:39:17 +0530 Subject: [PATCH 2/4] move core tests offline --- .../tests/async_tests/test_streaming_async.py | 127 +++++++++++++++++- sdk/core/azure-core/tests/test_streaming.py | 56 ++++++++ .../coretestserver/test_routes/streams.py | 9 ++ 3 files changed, 190 insertions(+), 2 deletions(-) diff --git a/sdk/core/azure-core/tests/async_tests/test_streaming_async.py b/sdk/core/azure-core/tests/async_tests/test_streaming_async.py index b28758312f07..363e923aa08b 100644 --- a/sdk/core/azure-core/tests/async_tests/test_streaming_async.py +++ b/sdk/core/azure-core/tests/async_tests/test_streaming_async.py @@ -24,6 +24,7 @@ # # -------------------------------------------------------------------------- import os +import zlib import pytest from azure.core import AsyncPipelineClient from azure.core.exceptions import DecodeError @@ -121,7 +122,6 @@ async def test_compress_compressed_no_header(http_request): @pytest.mark.parametrize("http_request", HTTP_REQUESTS) async def test_decompress_plain_header(http_request): # expect error - import zlib account_name = "coretests" account_url = "https://{}.blob.core.windows.net".format(account_name) @@ -198,7 +198,7 @@ async def test_compress_compressed_no_header_offline(port, http_request): assert False except UnicodeDecodeError: pass - + @pytest.mark.live_test_only @pytest.mark.asyncio @@ -222,3 +222,126 @@ async def test_compress_compressed_header(http_request): assert False except UnicodeDecodeError: pass + + + +@pytest.mark.asyncio +@pytest.mark.parametrize("http_request", HTTP_REQUESTS) +async def test_decompress_plain_no_header_offline(port, http_request): + # expect plain text + client = AsyncPipelineClient("") + async with client: + request = http_request(method="GET", url="http://localhost:{}/streams/string".format(port)) + pipeline_response = await client._pipeline.run(request, stream=True) + response = pipeline_response.http_response + data = response.stream_download(client._pipeline, decompress=True) + content = b"" + async for d in data: + content += d + decoded = content.decode("utf-8") + assert decoded == "test" + + + +@pytest.mark.asyncio +@pytest.mark.parametrize("http_request", HTTP_REQUESTS) +async def test_compress_plain_header_offline(port, http_request): + # expect plain text + client = AsyncPipelineClient("") + async with client: + request = http_request(method="GET", url="http://localhost:{}/streams/plain_header".format(port)) + pipeline_response = await client._pipeline.run(request,stream=True) + response = pipeline_response.http_response + data = response.stream_download(client._pipeline,decompress=False) + content = b"" + async for d in data: + content += d + decoded = content.decode("utf-8") + assert decoded == "test" + + +@pytest.mark.asyncio +@pytest.mark.parametrize("http_request", HTTP_REQUESTS) +async def test_decompress_compressed_no_header_offline(port, http_request): + # expect compressed text + client = AsyncPipelineClient("") + async with client: + request = http_request(method='GET',url="http://localhost:{}/streams/compressed_no_header".format(port)) + pipeline_response = await client._pipeline.run(request,stream=True) + response = pipeline_response.http_response + data = response.stream_download(client._pipeline,decompress=True) + content = b"" + async for d in data: + content += d + with pytest.raises(UnicodeDecodeError): + content.decode("utf-8") + + +@pytest.mark.asyncio +@pytest.mark.parametrize("http_request", HTTP_REQUESTS) +async def test_compress_compressed_header_offline(port, http_request): + # expect compressed text + client = AsyncPipelineClient("") + async with client: + request = http_request(method='GET',url="http://localhost:{}/streams/compressed_header".format(port)) + pipeline_response = await client._pipeline.run(request,stream=True) + response = pipeline_response.http_response + data = response.stream_download(client._pipeline,decompress=False) + content = b"" + async for d in data: + content += d + with pytest.raises(UnicodeDecodeError): + content.decode("utf-8") + + +@pytest.mark.asyncio +@pytest.mark.parametrize("http_request", HTTP_REQUESTS) +async def test_decompress_plain_header_offline(port, http_request): + # expect error + client = AsyncPipelineClient("") + async with client: + request = http_request(method="GET", url="http://localhost:{}/streams/compressed".format(port)) + pipeline_response = await client._pipeline.run(request,stream=True) + response = pipeline_response.http_response + print(f"this is the pipeline respone {response}") + data = response.stream_download(client._pipeline,decompress=True) + try: + content = b"" + async for d in data: + content += d + assert False + except (zlib.error, DecodeError): + pass + + +@pytest.mark.asyncio +@pytest.mark.parametrize("http_request", HTTP_REQUESTS) +async def test_compress_plain_no_header_offline(port, http_request): + client = AsyncPipelineClient("") + async with client: + request = http_request(method="GET", url="http://localhost:{}/streams/string".format(port)) + pipeline_response = await client._pipeline.run(request,stream=True) + response = pipeline_response.http_response + data = response.stream_download(client._pipeline,decompress=False) + content = b"" + async for d in data: + content += d + decoded = content.decode("utf-8") + assert decoded == "test" + + +@pytest.mark.asyncio +@pytest.mark.parametrize("http_request", HTTP_REQUESTS) +async def test_decompress_compressed_header_offline(port, http_request): + # expect compressed text + client = AsyncPipelineClient("") + async with client: + request = http_request(method='GET',url="http://localhost:{}/streams/decompress_header".format(port)) + pipeline_response = await client._pipeline.run(request, stream=True) + response = pipeline_response.http_response + data = response.stream_download(client._pipeline , decompress=True) + content = b"" + async for d in data: + content += d + decoded = content.decode("utf-8") + assert decoded == "test" \ No newline at end of file diff --git a/sdk/core/azure-core/tests/test_streaming.py b/sdk/core/azure-core/tests/test_streaming.py index 3ce3099fedda..a467261a0670 100644 --- a/sdk/core/azure-core/tests/test_streaming.py +++ b/sdk/core/azure-core/tests/test_streaming.py @@ -221,3 +221,59 @@ def test_compress_compressed_header(http_request): assert False except UnicodeDecodeError: pass + + +@pytest.mark.parametrize("http_request", HTTP_REQUESTS) +def test_decompress_plain_no_header_offline(port, http_request): + # expect plain text + request = http_request(method="GET", url="http://localhost:{}/streams/string".format(port)) + with RequestsTransport() as sender: + response = sender.send(request, stream=True) + response.raise_for_status() + data = response.stream_download(sender, decompress=True) + content = b"".join(list(data)) + decoded = content.decode("utf-8") + assert decoded == "test" + + +@pytest.mark.parametrize("http_request", HTTP_REQUESTS) +def test_compress_plain_header_offline(port,http_request): + # expect plain text + request = http_request(method="GET", url="http://localhost:{}/streams/plain_header".format(port)) + with RequestsTransport() as sender: + response = sender.send(request, stream=True) + response.raise_for_status() + data = response.stream_download(sender, decompress=True) + content = b"".join(list(data)) + decoded = content.decode("utf-8") + assert decoded == "test" + + + +@pytest.mark.parametrize("http_request", HTTP_REQUESTS) +def test_decompress_compressed_no_header_offline(port, http_request): + # expect compressed text + client = PipelineClient("") + request = http_request(method='GET',url="http://localhost:{}/streams/compressed_no_header".format(port)) + response = client._pipeline.run(request, stream=True).http_response + response.raise_for_status() + data = response.stream_download(client._pipeline, decompress=True) + content = b"".join(list(data)) + with pytest.raises(UnicodeDecodeError): + content.decode("utf-8") + + +@pytest.mark.parametrize("http_request", HTTP_REQUESTS) +def test_compress_compressed_header_offline(port, http_request): + # expect compressed text + client = PipelineClient("") + request = http_request(method='GET',url="http://localhost:{}/streams/compressed_header".format(port)) + response = client._pipeline.run(request, stream=True).http_response + response.raise_for_status() + data = response.stream_download(client._pipeline, decompress=False) + content = b"".join(list(data)) + with pytest.raises(UnicodeDecodeError): + content.decode("utf-8") + + + diff --git a/sdk/core/azure-core/tests/testserver_tests/coretestserver/coretestserver/test_routes/streams.py b/sdk/core/azure-core/tests/testserver_tests/coretestserver/coretestserver/test_routes/streams.py index cdf38a895f5a..d171359018aa 100644 --- a/sdk/core/azure-core/tests/testserver_tests/coretestserver/coretestserver/test_routes/streams.py +++ b/sdk/core/azure-core/tests/testserver_tests/coretestserver/coretestserver/test_routes/streams.py @@ -58,12 +58,21 @@ def error(): def string(): return Response(streaming_test(), status=200, mimetype="text/plain") +@streams_api.route("/plain_header", methods=["GET"]) +def plain_header(): + return Response(streaming_test(), status=200, mimetype="text/plain", headers={"Content-Type": "text/plain"}) + @streams_api.route("/compressed_no_header", methods=["GET"]) def compressed_no_header(): return Response(compressed_stream(), status=300) +@streams_api.route("/compressed_header", methods=["GET"]) +def compressed_header(): + return Response(compressed_stream(), status=200,headers={"Content-Encoding": "gzip"}) + + @streams_api.route("/compressed", methods=["GET"]) def compressed(): return Response(stream_compressed_header_error(), status=300, headers={"Content-Encoding": "gzip"}) From fb4840dbe23e82409e0a4e5526bec7f7859c16bb Mon Sep 17 00:00:00 2001 From: Himanshu Barak Date: Fri, 2 Feb 2024 00:39:21 +0530 Subject: [PATCH 3/4] update plain_header response and minor fixes --- .../tests/async_tests/test_streaming_async.py | 64 +++++-------------- sdk/core/azure-core/tests/test_streaming.py | 2 +- .../coretestserver/test_routes/streams.py | 2 +- 3 files changed, 17 insertions(+), 51 deletions(-) diff --git a/sdk/core/azure-core/tests/async_tests/test_streaming_async.py b/sdk/core/azure-core/tests/async_tests/test_streaming_async.py index 363e923aa08b..260ab8deb97b 100644 --- a/sdk/core/azure-core/tests/async_tests/test_streaming_async.py +++ b/sdk/core/azure-core/tests/async_tests/test_streaming_async.py @@ -190,15 +190,9 @@ async def test_compress_compressed_no_header_offline(port, http_request): pipeline_response = await client._pipeline.run(request,stream=True) response = pipeline_response.http_response data = response.stream_download(client._pipeline,decompress=False) - content = b"" - async for d in data: - content += d - try: - decoded = content.decode("utf-8") - assert False - except UnicodeDecodeError: - pass - + with pytest.raises(UnicodeDecodeError): + b''.join([d async for d in data]).decode("utf-8") + @pytest.mark.live_test_only @pytest.mark.asyncio @@ -214,14 +208,8 @@ async def test_compress_compressed_header(http_request): pipeline_response = await client._pipeline.run(request, stream=True) response = pipeline_response.http_response data = response.stream_download(client._pipeline, decompress=False) - content = b"" - async for d in data: - content += d - try: - decoded = content.decode("utf-8") - assert False - except UnicodeDecodeError: - pass + with pytest.raises(UnicodeDecodeError): + b''.join([d async for d in data]).decode("utf-8") @@ -235,10 +223,7 @@ async def test_decompress_plain_no_header_offline(port, http_request): pipeline_response = await client._pipeline.run(request, stream=True) response = pipeline_response.http_response data = response.stream_download(client._pipeline, decompress=True) - content = b"" - async for d in data: - content += d - decoded = content.decode("utf-8") + decoded = b''.join([d async for d in data]).decode("utf-8") assert decoded == "test" @@ -253,10 +238,7 @@ async def test_compress_plain_header_offline(port, http_request): pipeline_response = await client._pipeline.run(request,stream=True) response = pipeline_response.http_response data = response.stream_download(client._pipeline,decompress=False) - content = b"" - async for d in data: - content += d - decoded = content.decode("utf-8") + decoded = b''.join([d async for d in data]).decode("utf-8") assert decoded == "test" @@ -270,11 +252,9 @@ async def test_decompress_compressed_no_header_offline(port, http_request): pipeline_response = await client._pipeline.run(request,stream=True) response = pipeline_response.http_response data = response.stream_download(client._pipeline,decompress=True) - content = b"" - async for d in data: - content += d + with pytest.raises(UnicodeDecodeError): - content.decode("utf-8") + b''.join([d async for d in data]).decode("utf-8") @pytest.mark.asyncio @@ -287,11 +267,8 @@ async def test_compress_compressed_header_offline(port, http_request): pipeline_response = await client._pipeline.run(request,stream=True) response = pipeline_response.http_response data = response.stream_download(client._pipeline,decompress=False) - content = b"" - async for d in data: - content += d with pytest.raises(UnicodeDecodeError): - content.decode("utf-8") + b''.join([d async for d in data]).decode("utf-8") @pytest.mark.asyncio @@ -303,15 +280,10 @@ async def test_decompress_plain_header_offline(port, http_request): request = http_request(method="GET", url="http://localhost:{}/streams/compressed".format(port)) pipeline_response = await client._pipeline.run(request,stream=True) response = pipeline_response.http_response - print(f"this is the pipeline respone {response}") data = response.stream_download(client._pipeline,decompress=True) - try: - content = b"" - async for d in data: - content += d - assert False - except (zlib.error, DecodeError): - pass + with pytest.raises((zlib.error, DecodeError)): + b''.join([d async for d in data]) + @pytest.mark.asyncio @@ -323,10 +295,7 @@ async def test_compress_plain_no_header_offline(port, http_request): pipeline_response = await client._pipeline.run(request,stream=True) response = pipeline_response.http_response data = response.stream_download(client._pipeline,decompress=False) - content = b"" - async for d in data: - content += d - decoded = content.decode("utf-8") + decoded = b''.join([d async for d in data]).decode("utf-8") assert decoded == "test" @@ -340,8 +309,5 @@ async def test_decompress_compressed_header_offline(port, http_request): pipeline_response = await client._pipeline.run(request, stream=True) response = pipeline_response.http_response data = response.stream_download(client._pipeline , decompress=True) - content = b"" - async for d in data: - content += d - decoded = content.decode("utf-8") + decoded = b''.join([d async for d in data]).decode("utf-8") assert decoded == "test" \ No newline at end of file diff --git a/sdk/core/azure-core/tests/test_streaming.py b/sdk/core/azure-core/tests/test_streaming.py index a467261a0670..be6575bb8546 100644 --- a/sdk/core/azure-core/tests/test_streaming.py +++ b/sdk/core/azure-core/tests/test_streaming.py @@ -243,7 +243,7 @@ def test_compress_plain_header_offline(port,http_request): with RequestsTransport() as sender: response = sender.send(request, stream=True) response.raise_for_status() - data = response.stream_download(sender, decompress=True) + data = response.stream_download(sender, decompress=False) content = b"".join(list(data)) decoded = content.decode("utf-8") assert decoded == "test" diff --git a/sdk/core/azure-core/tests/testserver_tests/coretestserver/coretestserver/test_routes/streams.py b/sdk/core/azure-core/tests/testserver_tests/coretestserver/coretestserver/test_routes/streams.py index d171359018aa..3e93674e89da 100644 --- a/sdk/core/azure-core/tests/testserver_tests/coretestserver/coretestserver/test_routes/streams.py +++ b/sdk/core/azure-core/tests/testserver_tests/coretestserver/coretestserver/test_routes/streams.py @@ -60,7 +60,7 @@ def string(): @streams_api.route("/plain_header", methods=["GET"]) def plain_header(): - return Response(streaming_test(), status=200, mimetype="text/plain", headers={"Content-Type": "text/plain"}) + return Response(streaming_test(), status=200, mimetype="text/plain", headers={"Content-Encoding": "gzip"}) @streams_api.route("/compressed_no_header", methods=["GET"]) From d804193edf4b2ec6ef646146ccab8e02d52994be Mon Sep 17 00:00:00 2001 From: Himanshu Barak Date: Wed, 7 Feb 2024 22:30:39 +0530 Subject: [PATCH 4/4] fix black formatter --- .../tests/async_tests/test_streaming_async.py | 64 +++++++++---------- sdk/core/azure-core/tests/test_streaming.py | 14 ++-- .../coretestserver/test_routes/streams.py | 7 +- 3 files changed, 40 insertions(+), 45 deletions(-) diff --git a/sdk/core/azure-core/tests/async_tests/test_streaming_async.py b/sdk/core/azure-core/tests/async_tests/test_streaming_async.py index 260ab8deb97b..8e005344561d 100644 --- a/sdk/core/azure-core/tests/async_tests/test_streaming_async.py +++ b/sdk/core/azure-core/tests/async_tests/test_streaming_async.py @@ -180,6 +180,7 @@ async def test_decompress_compressed_header(http_request): decoded = content.decode("utf-8") assert decoded == "test" + @pytest.mark.asyncio @pytest.mark.parametrize("http_request", HTTP_REQUESTS) async def test_compress_compressed_no_header_offline(port, http_request): @@ -187,13 +188,13 @@ async def test_compress_compressed_no_header_offline(port, http_request): client = AsyncPipelineClient("") async with client: request = http_request(method="GET", url="http://localhost:{}/streams/compressed_no_header".format(port)) - pipeline_response = await client._pipeline.run(request,stream=True) + pipeline_response = await client._pipeline.run(request, stream=True) response = pipeline_response.http_response - data = response.stream_download(client._pipeline,decompress=False) + data = response.stream_download(client._pipeline, decompress=False) with pytest.raises(UnicodeDecodeError): - b''.join([d async for d in data]).decode("utf-8") - - + b"".join([d async for d in data]).decode("utf-8") + + @pytest.mark.live_test_only @pytest.mark.asyncio @pytest.mark.parametrize("http_request", HTTP_REQUESTS) @@ -209,10 +210,9 @@ async def test_compress_compressed_header(http_request): response = pipeline_response.http_response data = response.stream_download(client._pipeline, decompress=False) with pytest.raises(UnicodeDecodeError): - b''.join([d async for d in data]).decode("utf-8") + b"".join([d async for d in data]).decode("utf-8") - @pytest.mark.asyncio @pytest.mark.parametrize("http_request", HTTP_REQUESTS) async def test_decompress_plain_no_header_offline(port, http_request): @@ -223,11 +223,10 @@ async def test_decompress_plain_no_header_offline(port, http_request): pipeline_response = await client._pipeline.run(request, stream=True) response = pipeline_response.http_response data = response.stream_download(client._pipeline, decompress=True) - decoded = b''.join([d async for d in data]).decode("utf-8") + decoded = b"".join([d async for d in data]).decode("utf-8") assert decoded == "test" - @pytest.mark.asyncio @pytest.mark.parametrize("http_request", HTTP_REQUESTS) async def test_compress_plain_header_offline(port, http_request): @@ -235,11 +234,11 @@ async def test_compress_plain_header_offline(port, http_request): client = AsyncPipelineClient("") async with client: request = http_request(method="GET", url="http://localhost:{}/streams/plain_header".format(port)) - pipeline_response = await client._pipeline.run(request,stream=True) + pipeline_response = await client._pipeline.run(request, stream=True) response = pipeline_response.http_response - data = response.stream_download(client._pipeline,decompress=False) - decoded = b''.join([d async for d in data]).decode("utf-8") - assert decoded == "test" + data = response.stream_download(client._pipeline, decompress=False) + decoded = b"".join([d async for d in data]).decode("utf-8") + assert decoded == "test" @pytest.mark.asyncio @@ -248,13 +247,13 @@ async def test_decompress_compressed_no_header_offline(port, http_request): # expect compressed text client = AsyncPipelineClient("") async with client: - request = http_request(method='GET',url="http://localhost:{}/streams/compressed_no_header".format(port)) - pipeline_response = await client._pipeline.run(request,stream=True) + request = http_request(method="GET", url="http://localhost:{}/streams/compressed_no_header".format(port)) + pipeline_response = await client._pipeline.run(request, stream=True) response = pipeline_response.http_response - data = response.stream_download(client._pipeline,decompress=True) + data = response.stream_download(client._pipeline, decompress=True) with pytest.raises(UnicodeDecodeError): - b''.join([d async for d in data]).decode("utf-8") + b"".join([d async for d in data]).decode("utf-8") @pytest.mark.asyncio @@ -263,12 +262,12 @@ async def test_compress_compressed_header_offline(port, http_request): # expect compressed text client = AsyncPipelineClient("") async with client: - request = http_request(method='GET',url="http://localhost:{}/streams/compressed_header".format(port)) - pipeline_response = await client._pipeline.run(request,stream=True) + request = http_request(method="GET", url="http://localhost:{}/streams/compressed_header".format(port)) + pipeline_response = await client._pipeline.run(request, stream=True) response = pipeline_response.http_response - data = response.stream_download(client._pipeline,decompress=False) + data = response.stream_download(client._pipeline, decompress=False) with pytest.raises(UnicodeDecodeError): - b''.join([d async for d in data]).decode("utf-8") + b"".join([d async for d in data]).decode("utf-8") @pytest.mark.asyncio @@ -278,13 +277,12 @@ async def test_decompress_plain_header_offline(port, http_request): client = AsyncPipelineClient("") async with client: request = http_request(method="GET", url="http://localhost:{}/streams/compressed".format(port)) - pipeline_response = await client._pipeline.run(request,stream=True) + pipeline_response = await client._pipeline.run(request, stream=True) response = pipeline_response.http_response - data = response.stream_download(client._pipeline,decompress=True) + data = response.stream_download(client._pipeline, decompress=True) with pytest.raises((zlib.error, DecodeError)): - b''.join([d async for d in data]) - - + b"".join([d async for d in data]) + @pytest.mark.asyncio @pytest.mark.parametrize("http_request", HTTP_REQUESTS) @@ -292,10 +290,10 @@ async def test_compress_plain_no_header_offline(port, http_request): client = AsyncPipelineClient("") async with client: request = http_request(method="GET", url="http://localhost:{}/streams/string".format(port)) - pipeline_response = await client._pipeline.run(request,stream=True) + pipeline_response = await client._pipeline.run(request, stream=True) response = pipeline_response.http_response - data = response.stream_download(client._pipeline,decompress=False) - decoded = b''.join([d async for d in data]).decode("utf-8") + data = response.stream_download(client._pipeline, decompress=False) + decoded = b"".join([d async for d in data]).decode("utf-8") assert decoded == "test" @@ -305,9 +303,9 @@ async def test_decompress_compressed_header_offline(port, http_request): # expect compressed text client = AsyncPipelineClient("") async with client: - request = http_request(method='GET',url="http://localhost:{}/streams/decompress_header".format(port)) + request = http_request(method="GET", url="http://localhost:{}/streams/decompress_header".format(port)) pipeline_response = await client._pipeline.run(request, stream=True) response = pipeline_response.http_response - data = response.stream_download(client._pipeline , decompress=True) - decoded = b''.join([d async for d in data]).decode("utf-8") - assert decoded == "test" \ No newline at end of file + data = response.stream_download(client._pipeline, decompress=True) + decoded = b"".join([d async for d in data]).decode("utf-8") + assert decoded == "test" diff --git a/sdk/core/azure-core/tests/test_streaming.py b/sdk/core/azure-core/tests/test_streaming.py index be6575bb8546..c636fc2637c0 100644 --- a/sdk/core/azure-core/tests/test_streaming.py +++ b/sdk/core/azure-core/tests/test_streaming.py @@ -237,9 +237,9 @@ def test_decompress_plain_no_header_offline(port, http_request): @pytest.mark.parametrize("http_request", HTTP_REQUESTS) -def test_compress_plain_header_offline(port,http_request): +def test_compress_plain_header_offline(port, http_request): # expect plain text - request = http_request(method="GET", url="http://localhost:{}/streams/plain_header".format(port)) + request = http_request(method="GET", url="http://localhost:{}/streams/plain_header".format(port)) with RequestsTransport() as sender: response = sender.send(request, stream=True) response.raise_for_status() @@ -249,31 +249,27 @@ def test_compress_plain_header_offline(port,http_request): assert decoded == "test" - @pytest.mark.parametrize("http_request", HTTP_REQUESTS) def test_decompress_compressed_no_header_offline(port, http_request): # expect compressed text client = PipelineClient("") - request = http_request(method='GET',url="http://localhost:{}/streams/compressed_no_header".format(port)) + request = http_request(method="GET", url="http://localhost:{}/streams/compressed_no_header".format(port)) response = client._pipeline.run(request, stream=True).http_response response.raise_for_status() data = response.stream_download(client._pipeline, decompress=True) content = b"".join(list(data)) with pytest.raises(UnicodeDecodeError): content.decode("utf-8") - + @pytest.mark.parametrize("http_request", HTTP_REQUESTS) def test_compress_compressed_header_offline(port, http_request): # expect compressed text client = PipelineClient("") - request = http_request(method='GET',url="http://localhost:{}/streams/compressed_header".format(port)) + request = http_request(method="GET", url="http://localhost:{}/streams/compressed_header".format(port)) response = client._pipeline.run(request, stream=True).http_response response.raise_for_status() data = response.stream_download(client._pipeline, decompress=False) content = b"".join(list(data)) with pytest.raises(UnicodeDecodeError): content.decode("utf-8") - - - diff --git a/sdk/core/azure-core/tests/testserver_tests/coretestserver/coretestserver/test_routes/streams.py b/sdk/core/azure-core/tests/testserver_tests/coretestserver/coretestserver/test_routes/streams.py index 3e93674e89da..be13b18b15ce 100644 --- a/sdk/core/azure-core/tests/testserver_tests/coretestserver/coretestserver/test_routes/streams.py +++ b/sdk/core/azure-core/tests/testserver_tests/coretestserver/coretestserver/test_routes/streams.py @@ -58,9 +58,10 @@ def error(): def string(): return Response(streaming_test(), status=200, mimetype="text/plain") + @streams_api.route("/plain_header", methods=["GET"]) def plain_header(): - return Response(streaming_test(), status=200, mimetype="text/plain", headers={"Content-Encoding": "gzip"}) + return Response(streaming_test(), status=200, mimetype="text/plain", headers={"Content-Encoding": "gzip"}) @streams_api.route("/compressed_no_header", methods=["GET"]) @@ -70,9 +71,9 @@ def compressed_no_header(): @streams_api.route("/compressed_header", methods=["GET"]) def compressed_header(): - return Response(compressed_stream(), status=200,headers={"Content-Encoding": "gzip"}) + return Response(compressed_stream(), status=200, headers={"Content-Encoding": "gzip"}) + - @streams_api.route("/compressed", methods=["GET"]) def compressed(): return Response(stream_compressed_header_error(), status=300, headers={"Content-Encoding": "gzip"})