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
4 changes: 3 additions & 1 deletion sdk/core/azure-core/samples/example_shared_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
1) AZURE_STORAGE_CONNECTION_STRING - the endpoint of your Azure Metrics Advisor service
"""

# pylint: disable=non-abstract-transport-import,networking-import-outside-azure-core-transport
import os
from azure.core.pipeline.transport import RequestsTransport
from azure.storage.blob import BlobServiceClient
Expand All @@ -33,7 +34,8 @@ def shared_transport():
session = requests.Session()
shared_transport = RequestsTransport(
session=session, session_owner=False
) # here we set session_owner to False to indicate that we don't want to close the session when the client is closed
) # here we set session_owner to False to indicate that we don't want to
# close the session when the client is closed
with shared_transport:
blob_service_client1 = BlobServiceClient.from_connection_string(
connection_string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
1) AZURE_STORAGE_CONNECTION_STRING - the endpoint of your Azure Metrics Advisor service
"""

# pylint: disable=non-abstract-transport-import,networking-import-outside-azure-core-transport
import os
import asyncio
from azure.core.pipeline.transport import AioHttpTransport
Expand All @@ -34,7 +35,8 @@ async def shared_transport_async():
session = aiohttp.ClientSession()
shared_transport = AioHttpTransport(
session=session, session_owner=False
) # here we set session_owner to False to indicate that we don't want to close the session when the client is closed
) # here we set session_owner to False to indicate that we don't want to
# close the session when the client is closed
async with shared_transport:
blob_service_client1 = BlobServiceClient.from_connection_string(
connection_string,
Expand Down
3 changes: 3 additions & 0 deletions sdk/core/azure-core/samples/example_truststore_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
# Inject truststore BEFORE importing Azure SDK libraries
truststore.inject_into_ssl()

# Azure SDK imports must follow truststore injection so the OS certificate
# store is used for TLS; the out-of-order position is intentional here.
# pylint: disable=wrong-import-position
# Synchronous imports
from azure.identity import DefaultAzureCredential
from azure.storage.blob import BlobServiceClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
python example_truststore_ssl_context.py
"""

# pylint: disable=non-abstract-transport-import,networking-import-outside-azure-core-transport
import ssl
import asyncio
import truststore
Expand Down
6 changes: 4 additions & 2 deletions sdk/core/azure-core/samples/test_example_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@
# THE SOFTWARE.
#
# --------------------------------------------------------------------------
# pylint: disable=non-abstract-transport-import,networking-import-outside-azure-core-transport
from typing import Iterable, MutableSequence, Union

import pytest
import trio

from azure.core.pipeline import AsyncPipeline
from azure.core import AsyncPipelineClient
from azure.core.pipeline.policies import AsyncHTTPPolicy, SansIOHTTPPolicy, UserAgentPolicy, AsyncRedirectPolicy
from azure.core.rest import HttpRequest, AsyncHttpResponse

import trio


@pytest.mark.asyncio
async def test_example_trio():
Expand Down
3 changes: 1 addition & 2 deletions sdk/core/azure-core/samples/test_example_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def callback(response):

from azure.core.pipeline import Pipeline
from azure.core.rest import HttpRequest
from azure.core.pipeline.policies import RedirectPolicy, UserAgentPolicy
from azure.core.pipeline.transport import RequestsTransport
from azure.core.pipeline.transport import RequestsTransport # pylint: disable=non-abstract-transport-import
from azure.core.pipeline.policies import CustomHookPolicy

request = HttpRequest("GET", "https://bing.com")
Expand Down
4 changes: 0 additions & 4 deletions sdk/core/azure-core/samples/test_example_sansio.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
#
# --------------------------------------------------------------------------

import sys
from azure.core.pipeline import PipelineRequest
from azure.core.rest import HttpRequest, HttpResponse
from azure.core import PipelineClient
from azure.core.pipeline.policies import RedirectPolicy
from azure.core.pipeline.policies import UserAgentPolicy
from azure.core.pipeline.policies import SansIOHTTPPolicy
from azure.core.pipeline.policies import RequestIdPolicy


Expand Down Expand Up @@ -62,8 +60,6 @@ def test_example_request_id_policy():
policies = [UserAgentPolicy("myuseragent"), RedirectPolicy()]

# [START request_id_policy]
from azure.core.pipeline.policies import HeadersPolicy

request_id_policy = RequestIdPolicy()
request_id_policy.set_request_id("azconfig-test")

Expand Down
1 change: 1 addition & 0 deletions sdk/core/azure-core/samples/test_example_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# THE SOFTWARE.
#
# --------------------------------------------------------------------------
# pylint: disable=non-abstract-transport-import
from typing import Iterable, MutableSequence, Union
from azure.core.pipeline import Pipeline
from azure.core import PipelineClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
import sys
import time
from unittest.mock import Mock, patch, AsyncMock, create_autospec

from requests import Response
import pytest
import trio

from utils import HTTP_REQUESTS

from azure.core.credentials import AccessToken, AccessTokenInfo
from azure.core.credentials_async import AsyncTokenCredential, AsyncSupportsTokenInfo
Expand All @@ -23,10 +28,6 @@
)
from azure.core.pipeline.policies._authentication import MAX_REFRESH_JITTER_SECONDS
from azure.core.pipeline.transport import AsyncHttpTransport, HttpRequest
import pytest
import trio

from utils import HTTP_REQUESTS


@pytest.mark.asyncio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,25 @@
import base64
import json
import re
from utils import HTTP_REQUESTS
from azure.core.pipeline._tools import is_rest
import types
from unittest import mock

import pytest

from requests import Request, Response
from utils import HTTP_REQUESTS
from utils import ASYNCIO_REQUESTS_TRANSPORT_RESPONSES, request_and_responses_product, create_transport_response
from rest_client_async import AsyncMockRestClient

from azure.core.pipeline._tools import is_rest
from azure.core.polling import async_poller, AsyncLROPoller
from azure.core.exceptions import DecodeError, HttpResponseError
from azure.core import AsyncPipelineClient
from azure.core.pipeline import PipelineResponse, AsyncPipeline, PipelineContext
from azure.core.pipeline.transport import AsyncioRequestsTransportResponse, AsyncHttpTransport

from azure.core.polling.base_polling import LROBasePolling
from azure.core.polling.async_base_polling import (
AsyncLROBasePolling,
)
from utils import ASYNCIO_REQUESTS_TRANSPORT_RESPONSES, request_and_responses_product, create_transport_response
from rest_client_async import AsyncMockRestClient


class SimpleResource:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
# license information.
# -------------------------------------------------------------------------

import pytest
# pylint: disable=line-too-long,useless-suppression
import sys
import asyncio
from packaging.version import Version
from unittest import mock

import pytest
from packaging.version import Version
import aiohttp
from utils import HTTP_REQUESTS, request_and_responses_product

from azure.core.pipeline.transport import (
AsyncHttpResponse as PipelineTransportAsyncHttpResponse,
Expand All @@ -31,8 +33,6 @@
ServiceResponseTimeoutError,
)

from utils import HTTP_REQUESTS, request_and_responses_product


# transport = mock.MagicMock(spec=AsyncHttpTransport)
# MagicMock support async cxt manager only after 3.8
Expand Down Expand Up @@ -970,9 +970,6 @@ async def test_recursive_multipart_receive(http_request, mock_response):

@pytest.mark.skipif(sys.version_info < (3, 10), reason="Loop parameter is deprecated since Python 3.10")
def test_aiohttp_loop():
import asyncio
from azure.core.pipeline.transport import AioHttpTransport

loop = asyncio.new_event_loop()
try:
with pytest.raises(ValueError):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
# Licensed under the MIT License. See LICENSE.txt in the project root for
# license information.
# -------------------------------------------------------------------------
from azure.core.pipeline import AsyncPipeline
import pytest

from azure.core.pipeline.transport import (
HttpRequest,
)
from azure.core import AsyncPipelineClient
from azure.core.exceptions import IncompleteReadError
import pytest


@pytest.mark.asyncio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@

import logging
import types
import pytest
import sys
from unittest.mock import Mock

import pytest
from utils import HTTP_RESPONSES, request_and_responses_product, create_http_response

from azure.core.pipeline import PipelineResponse, PipelineRequest, PipelineContext
from azure.core.pipeline.policies import (
HttpLoggingPolicy,
)
from utils import HTTP_RESPONSES, request_and_responses_product, create_http_response


@pytest.mark.parametrize("http_request,http_response", request_and_responses_product(HTTP_RESPONSES))
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/azure-core/tests/async_tests/test_paging_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@

from typing import AsyncIterator, TypeVar, List

import pytest

from azure.core.async_paging import AsyncItemPaged, AsyncList
from azure.core.exceptions import HttpResponseError

import pytest


T = TypeVar("T")

Expand Down
12 changes: 5 additions & 7 deletions sdk/core/azure-core/tests/async_tests/test_pipeline_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
import sys
from unittest.mock import Mock

import aiohttp
import trio
import pytest
from utils import HTTP_REQUESTS

from azure.core.credentials import AccessToken
from azure.core.pipeline import AsyncPipeline
from azure.core.pipeline.policies import (
Expand All @@ -36,7 +41,6 @@
AsyncRetryPolicy,
AsyncRedirectPolicy,
AsyncHTTPPolicy,
AsyncRetryPolicy,
HttpLoggingPolicy,
SensitiveHeaderCleanupPolicy,
)
Expand All @@ -55,12 +59,6 @@
from azure.core import AsyncPipelineClient
from azure.core.exceptions import AzureError

import aiohttp
import trio

import pytest
from utils import HTTP_REQUESTS


try:
from unittest.mock import AsyncMock, PropertyMock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#
# --------------------------------------------------------------------------
import asyncio
import time

try:
from unittest import mock
Expand All @@ -34,7 +33,7 @@
import pytest

from azure.core import AsyncPipelineClient
from azure.core.polling import *
from azure.core.polling import NoPolling, AsyncNoPolling, AsyncPollingMethod, AsyncLROPoller
from azure.core.exceptions import ServiceResponseError

# from msrest.serialization import Model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
# -------------------------------------------------------------------------
import json

from azure.core.pipeline.transport import AsyncioRequestsTransport
import pytest
from utils import HTTP_REQUESTS

from azure.core.pipeline.transport import AsyncioRequestsTransport
from azure.core.pipeline._tools import is_rest
import pytest


@pytest.mark.asyncio
Expand Down
6 changes: 3 additions & 3 deletions sdk/core/azure-core/tests/async_tests/test_request_trio.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
# -------------------------------------------------------------------------
import json

from azure.core.pipeline.transport import TrioRequestsTransport
import pytest
from utils import HTTP_REQUESTS
from azure.core.pipeline._tools import is_rest

import pytest
from azure.core.pipeline.transport import TrioRequestsTransport
from azure.core.pipeline._tools import is_rest


@pytest.mark.trio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
# Licensed under the MIT License. See LICENSE.txt in the project root for
# license information.
# -------------------------------------------------------------------------
from azure.core.pipeline.transport import AsyncioRequestsTransport
from azure.core.rest import HttpRequest
from azure.core.rest._requests_asyncio import RestAsyncioRequestsTransportResponse
from rest_client_async import AsyncMockRestClient

import pytest
import pytest_asyncio
from rest_client_async import AsyncMockRestClient
from utils import readonly_checks

from azure.core.pipeline.transport import AsyncioRequestsTransport
from azure.core.rest import HttpRequest
from azure.core.rest._requests_asyncio import RestAsyncioRequestsTransportResponse


@pytest_asyncio.fixture
async def client(port):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
# Licensed under the MIT License. See LICENSE.txt in the project root for
# license information.
# -------------------------------------------------------------------------
from azure.core.exceptions import ResponseNotReadError
import pytest

from azure.core.exceptions import ResponseNotReadError
from azure.core.rest import HttpRequest
from rest_client_async import AsyncMockRestClient


@pytest.mark.asyncio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
# Licensed under the MIT License. See LICENSE.txt in the project root for
# license information.
# -------------------------------------------------------------------------

import pytest
import platform

from azure.core.rest import HttpRequest
import aiohttp
from azure.core.rest._aiohttp import RestAioHttpTransportResponse

# flask returns these response headers, which we don't really need for these following tests
RESPONSE_HEADERS_TO_IGNORE = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

# NOTE: These tests are heavily inspired from the httpx test suite: https://github.com/encode/httpx/tree/master/tests
# Thank you httpx for your wonderful tests!
import pytest
from azure.core.rest import HttpRequest
import collections.abc

import pytest
from utils import NamedIo

from azure.core.rest import HttpRequest


@pytest.fixture
def assert_aiterator_body():
Expand Down
Loading
Loading