Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 144 additions & 2 deletions sdk/core/azure-core/tests/async_tests/test_streaming_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#
# --------------------------------------------------------------------------
import os
import zlib
import pytest
from azure.core import AsyncPipelineClient
from azure.core.exceptions import DecodeError
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -203,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"
56 changes: 56 additions & 0 deletions sdk/core/azure-core/tests/test_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")



Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand Down