Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fix black formatter
  • Loading branch information
Himanshu Barak committed Feb 7, 2024
commit d804193edf4b2ec6ef646146ccab8e02d52994be
64 changes: 31 additions & 33 deletions sdk/core/azure-core/tests/async_tests/test_streaming_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,21 @@ 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)
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)
Expand All @@ -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):
Expand All @@ -223,23 +223,22 @@ 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):
# 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)
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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -278,24 +277,23 @@ 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)
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"


Expand All @@ -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"
data = response.stream_download(client._pipeline, decompress=True)
decoded = b"".join([d async for d in data]).decode("utf-8")
assert decoded == "test"
14 changes: 5 additions & 9 deletions sdk/core/azure-core/tests/test_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")



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