forked from Azure/azure-sdk-for-python
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* decompress body * update * update * update * update * update recorded tests * update * update * update * update * update * add type annotation * update * update * update * update * update * update * update doc * update * update * add comments * update
- Loading branch information
1 parent
802c887
commit 502c702
Showing
701 changed files
with
56,247 additions
and
111,641 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
176 changes: 176 additions & 0 deletions
176
sdk/core/azure-core/tests/async_tests/test_streaming_async.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
# -------------------------------------------------------------------------- | ||
# | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# | ||
# The MIT License (MIT) | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the ""Software""), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
# THE SOFTWARE. | ||
# | ||
# -------------------------------------------------------------------------- | ||
import os | ||
import pytest | ||
from azure.core import AsyncPipelineClient | ||
|
||
@pytest.mark.asyncio | ||
async def test_decompress_plain_no_header(): | ||
# expect plain text | ||
account_name = "coretests" | ||
account_url = "https://{}.blob.core.windows.net".format(account_name) | ||
url = "https://{}.blob.core.windows.net/tests/test.txt".format(account_name) | ||
client = AsyncPipelineClient(account_url) | ||
request = client.get(url) | ||
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 | ||
async def test_compress_plain_no_header(): | ||
# expect plain text | ||
account_name = "coretests" | ||
account_url = "https://{}.blob.core.windows.net".format(account_name) | ||
url = "https://{}.blob.core.windows.net/tests/test.txt".format(account_name) | ||
client = AsyncPipelineClient(account_url) | ||
request = client.get(url) | ||
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 | ||
async def test_decompress_compressed_no_header(): | ||
# expect compressed text | ||
account_name = "coretests" | ||
account_url = "https://{}.blob.core.windows.net".format(account_name) | ||
url = "https://{}.blob.core.windows.net/tests/test.tar.gz".format(account_name) | ||
client = AsyncPipelineClient(account_url) | ||
request = client.get(url) | ||
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 | ||
try: | ||
decoded = content.decode('utf-8') | ||
assert False | ||
except UnicodeDecodeError: | ||
pass | ||
|
||
@pytest.mark.asyncio | ||
async def test_compress_compressed_no_header(): | ||
# expect compressed text | ||
account_name = "coretests" | ||
account_url = "https://{}.blob.core.windows.net".format(account_name) | ||
url = "https://{}.blob.core.windows.net/tests/test.tar.gz".format(account_name) | ||
client = AsyncPipelineClient(account_url) | ||
request = client.get(url) | ||
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.asyncio | ||
async def test_decompress_plain_header(): | ||
# expect error | ||
import zlib | ||
account_name = "coretests" | ||
account_url = "https://{}.blob.core.windows.net".format(account_name) | ||
url = "https://{}.blob.core.windows.net/tests/test_with_header.txt".format(account_name) | ||
client = AsyncPipelineClient(account_url) | ||
request = client.get(url) | ||
pipeline_response = await client._pipeline.run(request, stream=True) | ||
response = pipeline_response.http_response | ||
data = response.stream_download(client._pipeline, decompress=True) | ||
try: | ||
content = b"" | ||
async for d in data: | ||
content += d | ||
assert False | ||
except zlib.error: | ||
pass | ||
|
||
@pytest.mark.asyncio | ||
async def test_compress_plain_header(): | ||
# expect plain text | ||
account_name = "coretests" | ||
account_url = "https://{}.blob.core.windows.net".format(account_name) | ||
url = "https://{}.blob.core.windows.net/tests/test_with_header.txt".format(account_name) | ||
client = AsyncPipelineClient(account_url) | ||
request = client.get(url) | ||
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 | ||
async def test_decompress_compressed_header(): | ||
# expect plain text | ||
account_name = "coretests" | ||
account_url = "https://{}.blob.core.windows.net".format(account_name) | ||
url = "https://{}.blob.core.windows.net/tests/test_with_header.tar.gz".format(account_name) | ||
client = AsyncPipelineClient(account_url) | ||
request = client.get(url) | ||
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 | ||
async def test_compress_compressed_header(): | ||
# expect compressed text | ||
account_name = "coretests" | ||
account_url = "https://{}.blob.core.windows.net".format(account_name) | ||
url = "https://{}.blob.core.windows.net/tests/test_with_header.tar.gz".format(account_name) | ||
client = AsyncPipelineClient(account_url) | ||
request = client.get(url) | ||
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 |
Oops, something went wrong.