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
5 changes: 5 additions & 0 deletions sdk/core/azure-core/samples/example_tracing_async.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
"""
FILE: example_async_tracing.py
DESCRIPTION:
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/azure-core/samples/test_example_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# THE SOFTWARE.
#
# --------------------------------------------------------------------------
# pylint: disable=non-abstract-transport-import,networking-import-outside-azure-core-transport
# pylint: disable=non-abstract-transport-import,networking-import-outside-azure-core-transport,protected-access
from typing import Iterable, MutableSequence, Union

import pytest
Expand Down
1 change: 1 addition & 0 deletions sdk/core/azure-core/samples/test_example_sansio.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# THE SOFTWARE.
#
# --------------------------------------------------------------------------
# pylint: disable=protected-access

from azure.core.pipeline import PipelineRequest
from azure.core.rest import HttpRequest, HttpResponse
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/azure-core/samples/test_example_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# THE SOFTWARE.
#
# --------------------------------------------------------------------------
# pylint: disable=non-abstract-transport-import
# pylint: disable=non-abstract-transport-import,protected-access
from typing import Iterable, MutableSequence, Union
from azure.core.pipeline import Pipeline
from azure.core import PipelineClient
Expand Down
32 changes: 14 additions & 18 deletions sdk/core/azure-core/tests/async_tests/test_base_polling_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
from azure.core.exceptions import DecodeError, HttpResponseError
from azure.core import AsyncPipelineClient
from azure.core.pipeline import PipelineResponse, AsyncPipeline, PipelineContext

# pylint: disable=no-name-in-module
from azure.core.pipeline.transport import AsyncioRequestsTransportResponse, AsyncHttpTransport
from azure.core.polling.base_polling import LROBasePolling
from azure.core.polling.async_base_polling import (
Expand Down Expand Up @@ -196,12 +198,11 @@ async def send(request, **kwargs):
return TestBasePolling.mock_send(
http_request, http_response, "GET", 200, body={"location_result": True}
).http_response
elif request.url == "http://example.org/async_monitor":
if request.url == "http://example.org/async_monitor":
return TestBasePolling.mock_send(
http_request, http_response, "GET", 200, body={"status": "Succeeded"}
).http_response
else:
pytest.fail("No other query allowed")
pytest.fail("No other query allowed")

client = async_pipeline_client_builder(send)

Expand All @@ -217,12 +218,11 @@ async def send(request, **kwargs):

if request.url == "http://example.org/location":
return TestBasePolling.mock_send(http_request, http_response, "GET", 200, body=None).http_response
elif request.url == "http://example.org/async_monitor":
if request.url == "http://example.org/async_monitor":
return TestBasePolling.mock_send(
http_request, http_response, "GET", 200, body={"status": "Succeeded"}
).http_response
else:
pytest.fail("No other query allowed")
pytest.fail("No other query allowed")

client = async_pipeline_client_builder(send)

Expand Down Expand Up @@ -258,16 +258,15 @@ async def send(request, **kwargs):
return TestBasePolling.mock_send(
http_request, http_response, "GET", 200, body={"location_result": True}
).http_response
elif request.url == "http://example.org/async_monitor":
if request.url == "http://example.org/async_monitor":
return TestBasePolling.mock_send(
http_request,
http_response,
"GET",
200,
body={"status": "Succeeded", "resourceLocation": "http://example.org/resource_location"},
).http_response
else:
pytest.fail("No other query allowed")
pytest.fail("No other query allowed")

client = async_pipeline_client_builder(send)

Expand Down Expand Up @@ -727,12 +726,11 @@ async def send(request, **kwargs):
return TestBasePolling.mock_send(
http_request, http_response, "GET", 200, body={"location_result": True}
).http_response
elif request.url == "http://example.org/async_monitor":
if request.url == "http://example.org/async_monitor":
return TestBasePolling.mock_send(
http_request, http_response, "GET", 200, body={"status": "Succeeded"}
).http_response
else:
pytest.fail("No other query allowed")
pytest.fail("No other query allowed")

client = async_pipeline_client_builder(send)

Expand Down Expand Up @@ -768,12 +766,11 @@ async def send(request, **kwargs):

if request.url == "http://example.org/location":
return TestBasePolling.mock_send(http_request, http_response, "GET", 200, body=None).http_response
elif request.url == "http://example.org/async_monitor":
if request.url == "http://example.org/async_monitor":
return TestBasePolling.mock_send(
http_request, http_response, "GET", 200, body={"status": "Succeeded"}
).http_response
else:
pytest.fail("No other query allowed")
pytest.fail("No other query allowed")

client = async_pipeline_client_builder(send)

Expand Down Expand Up @@ -829,12 +826,11 @@ async def send(request, **kwargs):
return TestBasePolling.mock_send(
rest_http[0], rest_http[1], "GET", 200, body={"success": True}
).http_response
elif request.url == "http://example.org/async_monitor":
if request.url == "http://example.org/async_monitor":
return TestBasePolling.mock_send(
rest_http[0], rest_http[1], "GET", 200, body={"status": "Succeeded"}
).http_response
else:
pytest.fail("No other query allowed")
pytest.fail("No other query allowed")

client = async_pipeline_client_builder(send)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import aiohttp
from utils import HTTP_REQUESTS, request_and_responses_product

# pylint: disable=no-name-in-module
from azure.core.pipeline.transport import (
AsyncHttpResponse as PipelineTransportAsyncHttpResponse,
AsyncHttpTransport,
Expand Down Expand Up @@ -1092,7 +1093,7 @@ async def test_aiohttp_timeout_request(http_request):
async with AioHttpTransport() as transport:
transport.session._connector.connect = mock.Mock(side_effect=asyncio.TimeoutError("Too slow!"))

request = http_request("GET", f"http://localhost:12345/basic/string")
request = http_request("GET", "http://localhost:12345/basic/string")

# aiohttp 3.10 introduced separate connection timeout
if Version(aiohttp.__version__) >= Version("3.10"):
Expand All @@ -1102,7 +1103,7 @@ async def test_aiohttp_timeout_request(http_request):
with pytest.raises(ServiceRequestError) as err:
await transport.send(request)

stream_request = http_request("GET", f"http://localhost:12345/streams/basic")
stream_request = http_request("GET", "http://localhost:12345/streams/basic")
with pytest.raises(ServiceRequestTimeoutError) as err:
await transport.send(stream_request, stream=True)

Expand All @@ -1113,6 +1114,6 @@ async def test_aiohttp_timeout_request(http_request):
with pytest.raises(ServiceResponseError) as err:
await transport.send(request)

stream_request = http_request("GET", f"http://localhost:12345/streams/basic")
stream_request = http_request("GET", "http://localhost:12345/streams/basic")
with pytest.raises(ServiceResponseTimeoutError) as err:
await transport.send(stream_request, stream=True)
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


@pytest.mark.parametrize("http_request,http_response", request_and_responses_product(HTTP_RESPONSES))
def test_http_logger(http_request, http_response):
def test_http_logger(http_request, http_response): # pylint: disable=too-many-statements
class MockHandler(logging.Handler):
def __init__(self):
super(MockHandler, self).__init__()
Expand Down Expand Up @@ -133,7 +133,7 @@ def emit(self, record):


@pytest.mark.parametrize("http_request,http_response", request_and_responses_product(HTTP_RESPONSES))
def test_http_logger_operation_level(http_request, http_response):
def test_http_logger_operation_level(http_request, http_response): # pylint: disable=too-many-statements
class MockHandler(logging.Handler):
def __init__(self):
super(MockHandler, self).__init__()
Expand Down
9 changes: 3 additions & 6 deletions sdk/core/azure-core/tests/async_tests/test_paging_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ async def get_next(continuation_token=None):
"""Simplify my life and return JSON and not response, but should be response."""
if not continuation_token:
return {"nextLink": "page2", "value": ["value1.0", "value1.1"]}
else:
return {"nextLink": None, "value": ["value2.0", "value2.1"]}
return {"nextLink": None, "value": ["value2.0", "value2.1"]}

async def extract_data(response):
return response["nextLink"], AsyncList(response["value"])
Expand All @@ -71,8 +70,7 @@ async def get_next(continuation_token=None):
"""Simplify my life and return JSON and not response, but should be response."""
if not continuation_token:
return {"nextLink": "page2", "value": ["value1.0", "value1.1"]}
else:
return {"nextLink": None, "value": ["value2.0", "value2.1"]}
return {"nextLink": None, "value": ["value2.0", "value2.1"]}

async def extract_data(response):
return response["nextLink"], AsyncList(response["value"])
Expand Down Expand Up @@ -106,8 +104,7 @@ async def test_paging_continue_on_error(self):
async def get_next(continuation_token=None):
if not continuation_token:
return {"nextLink": "foo", "value": ["bar"]}
else:
raise HttpResponseError()
raise HttpResponseError()

async def extract_data(response):
return response["nextLink"], iter(response["value"] or [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
HttpLoggingPolicy,
SensitiveHeaderCleanupPolicy,
)

# pylint: disable=no-name-in-module
from azure.core.pipeline.transport import (
AsyncHttpTransport,
AsyncioRequestsTransport,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pytest
from utils import HTTP_REQUESTS

# pylint: disable=no-name-in-module
from azure.core.pipeline.transport import AsyncioRequestsTransport
from azure.core.pipeline._tools import is_rest

Expand Down
5 changes: 3 additions & 2 deletions sdk/core/azure-core/tests/async_tests/test_request_trio.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pytest
from utils import HTTP_REQUESTS

# pylint: disable=no-name-in-module
from azure.core.pipeline.transport import TrioRequestsTransport
from azure.core.pipeline._tools import is_rest

Expand All @@ -25,8 +26,8 @@ def __aiter__(self):
async def __anext__(self):
try:
return next(self._range)
except StopIteration:
raise StopAsyncIteration
except StopIteration as exc:
raise StopAsyncIteration from exc

async with TrioRequestsTransport() as transport:
req = http_request("GET", "http://localhost:{}/basic/anything".format(port), data=AsyncGen())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from rest_client_async import AsyncMockRestClient
from utils import readonly_checks

# pylint: disable=no-name-in-module
from azure.core.pipeline.transport import AsyncioRequestsTransport
from azure.core.rest import HttpRequest
from azure.core.rest._requests_asyncio import RestAsyncioRequestsTransportResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async def test_headers_response_items_mutability(get_response_headers):
@pytest.mark.asyncio
async def test_header_mutations(get_response_headers):
h = await get_response_headers(HttpRequest("GET", "/headers/empty"))
assert dict(h) == {}
assert not dict(h)
h["a"] = "1"
assert dict(h) == {"a": "1"}
h["a"] = "2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def __aiter__(self):
yield b"test 123"

request = HttpRequest("POST", "http://example.org", content=Content())
assert request.headers == {}
assert not request.headers
await assert_aiterator_body(request, b"test 123")


Expand All @@ -68,23 +68,23 @@ async def hello_world():
assert not isinstance(request._data, collections.abc.Iterable)
assert isinstance(request._data, collections.abc.AsyncIterable)

assert request.headers == {}
assert not request.headers
await assert_aiterator_body(request, b"Hello, world!")

# Support 'data' for compat with requests.
request = HttpRequest("POST", url="http://example.org", data=hello_world())
assert not isinstance(request._data, collections.abc.Iterable)
assert isinstance(request._data, collections.abc.AsyncIterable)

assert request.headers == {}
assert not request.headers
await assert_aiterator_body(request, b"Hello, world!")

# transfer encoding should not be set for GET requests
request = HttpRequest("GET", url="http://example.org", data=hello_world())
assert not isinstance(request._data, collections.abc.Iterable)
assert isinstance(request._data, collections.abc.AsyncIterable)

assert request.headers == {}
assert not request.headers
await assert_aiterator_body(request, b"Hello, world!")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from utils import readonly_checks

from azure.core.rest import HttpRequest, AsyncHttpResponse

# pylint: disable=no-name-in-module
from azure.core.rest._aiohttp import RestAioHttpTransportResponse
from azure.core.exceptions import HttpResponseError

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from azure.core.pipeline.transport import HttpRequest as PipelineTransportHttpRequest
from azure.core.rest import HttpRequest as RestHttpRequest
from azure.core.pipeline import Pipeline

# pylint: disable=no-name-in-module
from azure.core.pipeline.transport import AioHttpTransport, AsyncioRequestsTransport, TrioRequestsTransport

TRANSPORTS = [AioHttpTransport, AsyncioRequestsTransport]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ async def test_iter_text(client):
request = HttpRequest("GET", "/basic/string")

async with client.send_request(request, stream=True) as response:
content = ""
async for part in response.iter_text():
content += part
content = "".join([part async for part in response.iter_text()])
assert content == "Hello, world!"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from rest_client_async import AsyncMockRestClient
from utils import readonly_checks

# pylint: disable=no-name-in-module
from azure.core.pipeline.transport import TrioRequestsTransport
from azure.core.rest import HttpRequest
from azure.core.rest._requests_trio import RestTrioRequestsTransportResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,8 @@ async def send(self, request, **kwargs): # type: (PipelineRequest, Any) -> Pipe
response.status_code = 400
return response

file = tempfile.NamedTemporaryFile(delete=False)
file.write(b"Lots of dataaaa")
file.close()
with tempfile.NamedTemporaryFile(delete=False) as file:
file.write(b"Lots of dataaaa")
http_request = http_request("GET", "http://localhost/")
headers = {"Content-Type": "multipart/form-data"}
http_request.headers = headers
Expand Down Expand Up @@ -345,7 +344,7 @@ def test_configure_retries_uses_constructor_values():
assert retry_settings["max_backoff"] == 60
assert retry_settings["timeout"] == 300
assert retry_settings["methods"] == frozenset(["HEAD", "GET", "PUT", "DELETE", "OPTIONS", "TRACE"])
assert retry_settings["history"] == []
assert not retry_settings["history"]


def test_configure_retries_options_override_constructor():
Expand Down Expand Up @@ -383,7 +382,7 @@ def test_configure_retries_options_override_constructor():
assert retry_settings["max_backoff"] == 180
assert retry_settings["timeout"] == 600
assert retry_settings["methods"] == frozenset(["GET", "POST"])
assert retry_settings["history"] == []
assert not retry_settings["history"]

# Verify options dict was modified (values were popped)
assert "retry_total" not in options
Expand Down Expand Up @@ -413,4 +412,4 @@ def test_configure_retries_default_values():
assert retry_settings["max_backoff"] == 120 # default retry_backoff_max (BACKOFF_MAX)
assert retry_settings["timeout"] == 604800 # default timeout
assert retry_settings["methods"] == frozenset(["HEAD", "GET", "PUT", "DELETE", "OPTIONS", "TRACE"])
assert retry_settings["history"] == []
assert not retry_settings["history"]
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pytest
from utils import request_and_responses_product, ASYNC_HTTP_RESPONSES, create_http_response

# pylint: disable=no-name-in-module
from azure.core.pipeline.transport import (
AsyncHttpTransport,
AsyncioRequestsTransportResponse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import pytest
from utils import HTTP_REQUESTS

# pylint: disable=no-name-in-module
from azure.core.pipeline.transport import AioHttpTransport

"""This file does a simple call to the testserver to make sure we can use the testserver"""
Expand Down
Loading
Loading