Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions sdk/core/azure-core/tests/test_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#
# --------------------------------------------------------------------------
import pytest
from azure.core.pipeline.transport import RequestsTransport
from azure.core import PipelineClient
from azure.core.exceptions import DecodeError
from azure.core.pipeline.transport import RequestsTransport
Expand All @@ -44,6 +45,20 @@ def test_decompress_plain_no_header(http_request):
decoded = content.decode('utf-8')
assert decoded == "test"

@pytest.mark.parametrize("http_request", HTTP_REQUESTS)
def test_compress_plain_no_header_offline(port, http_request):
# thanks to Daisy Cisneros for this test!
# 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=False)
content = b"".join(list(data))
decoded = content.decode('utf-8')
assert decoded == "test"

@pytest.mark.live_test_only
@pytest.mark.parametrize("http_request", HTTP_REQUESTS)
def test_compress_plain_no_header(http_request):
# expect plain text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def stream_json_error():
yield '{"error": {"code": "BadRequest", '
yield' "message": "You made a bad request"}}'

def streaming_test():
yield b"test"

def stream_compressed_header_error():
yield b'test'

Expand All @@ -40,7 +43,13 @@ def iterable():
def error():
return Response(stream_json_error(), status=400)

@streams_api.route('/string', methods=['GET'])
def string():
return Response(
streaming_test(), status=200, mimetype="text/plain"
)

@streams_api.route('/compressed', methods=['GET'])
def compressed():
return Response(stream_compressed_header_error(), status=300, headers={"Content-Encoding": "gzip"})