|
7 | 7 | AsyncHttpResponse as PipelineTransportAsyncHttpResponse,
|
8 | 8 | AsyncHttpTransport,
|
9 | 9 | AioHttpTransport,
|
| 10 | + HttpRequest, |
| 11 | + AioHttpTransportResponse, |
10 | 12 | )
|
| 13 | +from azure.core.pipeline.transport._aiohttp import AioHttpStreamDownloadGenerator |
11 | 14 | from azure.core.rest._http_response_impl_async import AsyncHttpResponseImpl as RestAsyncHttpResponse
|
12 | 15 | from azure.core.pipeline.policies import HeadersPolicy
|
13 | 16 | from azure.core.pipeline import AsyncPipeline
|
14 |
| -from azure.core.exceptions import HttpResponseError |
| 17 | +from azure.core.exceptions import HttpResponseError, ServiceResponseError |
15 | 18 | from utils import HTTP_REQUESTS, request_and_responses_product
|
16 | 19 | import pytest
|
17 | 20 | import sys
|
| 21 | +import aiohttp |
18 | 22 |
|
19 | 23 |
|
20 | 24 | # transport = mock.MagicMock(spec=AsyncHttpTransport)
|
@@ -79,7 +83,6 @@ def content(self):
|
79 | 83 | @pytest.mark.asyncio
|
80 | 84 | @pytest.mark.parametrize("http_request", HTTP_REQUESTS)
|
81 | 85 | async def test_basic_options_aiohttp(port, http_request):
|
82 |
| - |
83 | 86 | request = http_request("OPTIONS", "http://localhost:{}/basic/string".format(port))
|
84 | 87 | async with AsyncPipeline(AioHttpTransport(), policies=[]) as pipeline:
|
85 | 88 | response = await pipeline.run(request)
|
@@ -138,7 +141,6 @@ async def on_request(self, request):
|
138 | 141 | @pytest.mark.asyncio
|
139 | 142 | @pytest.mark.parametrize("http_request", HTTP_REQUESTS)
|
140 | 143 | async def test_multipart_send_with_context(http_request):
|
141 |
| - |
142 | 144 | transport = MockAsyncHttpTransport()
|
143 | 145 | header_policy = HeadersPolicy()
|
144 | 146 |
|
@@ -583,7 +585,6 @@ async def test_multipart_receive_with_one_changeset(http_request, mock_response)
|
583 | 585 | @pytest.mark.asyncio
|
584 | 586 | @pytest.mark.parametrize("http_request,mock_response", request_and_responses_product(MOCK_RESPONSES))
|
585 | 587 | async def test_multipart_receive_with_multiple_changesets(http_request, mock_response):
|
586 |
| - |
587 | 588 | changeset1 = http_request("", "")
|
588 | 589 | changeset1.set_multipart_mixed(
|
589 | 590 | http_request("DELETE", "/container0/blob0"), http_request("DELETE", "/container1/blob1")
|
@@ -666,7 +667,6 @@ async def test_multipart_receive_with_multiple_changesets(http_request, mock_res
|
666 | 667 | @pytest.mark.asyncio
|
667 | 668 | @pytest.mark.parametrize("http_request,mock_response", request_and_responses_product(MOCK_RESPONSES))
|
668 | 669 | async def test_multipart_receive_with_combination_changeset_first(http_request, mock_response):
|
669 |
| - |
670 | 670 | changeset = http_request("", "")
|
671 | 671 | changeset.set_multipart_mixed(
|
672 | 672 | http_request("DELETE", "/container0/blob0"), http_request("DELETE", "/container1/blob1")
|
@@ -744,7 +744,6 @@ def test_raise_for_status_good_response(mock_response):
|
744 | 744 | @pytest.mark.asyncio
|
745 | 745 | @pytest.mark.parametrize("http_request,mock_response", request_and_responses_product(MOCK_RESPONSES))
|
746 | 746 | async def test_multipart_receive_with_combination_changeset_middle(http_request, mock_response):
|
747 |
| - |
748 | 747 | changeset = http_request("", "")
|
749 | 748 | changeset.set_multipart_mixed(http_request("DELETE", "/container1/blob1"))
|
750 | 749 |
|
@@ -807,7 +806,6 @@ async def test_multipart_receive_with_combination_changeset_middle(http_request,
|
807 | 806 | @pytest.mark.asyncio
|
808 | 807 | @pytest.mark.parametrize("http_request,mock_response", request_and_responses_product(MOCK_RESPONSES))
|
809 | 808 | async def test_multipart_receive_with_combination_changeset_last(http_request, mock_response):
|
810 |
| - |
811 | 809 | changeset = http_request("", "")
|
812 | 810 | changeset.set_multipart_mixed(
|
813 | 811 | http_request("DELETE", "/container1/blob1"), http_request("DELETE", "/container2/blob2")
|
@@ -871,7 +869,6 @@ async def test_multipart_receive_with_combination_changeset_last(http_request, m
|
871 | 869 | @pytest.mark.asyncio
|
872 | 870 | @pytest.mark.parametrize("http_request,mock_response", request_and_responses_product(MOCK_RESPONSES))
|
873 | 871 | async def test_multipart_receive_with_bom(http_request, mock_response):
|
874 |
| - |
875 | 872 | req0 = http_request("DELETE", "/container0/blob0")
|
876 | 873 |
|
877 | 874 | request = http_request("POST", "http://account.blob.core.windows.net/?comp=batch")
|
@@ -971,3 +968,32 @@ def test_aiohttp_loop():
|
971 | 968 | loop = asyncio.get_event_loop()
|
972 | 969 | with pytest.raises(ValueError):
|
973 | 970 | transport = AioHttpTransport(loop=loop)
|
| 971 | + |
| 972 | + |
| 973 | +class MockAiohttpResponse: |
| 974 | + def __init__(self): |
| 975 | + self.status = 200 |
| 976 | + self.reason = "OK" |
| 977 | + self.headers = {"content-type": "application/json"} |
| 978 | + self.content = MockAiohttpContent() |
| 979 | + |
| 980 | + def read(self): |
| 981 | + request_info = aiohttp.RequestInfo("http://example.org", "GET", {}) |
| 982 | + raise aiohttp.client_exceptions.ClientResponseError(request_info, None) |
| 983 | + |
| 984 | + |
| 985 | +class MockAiohttpContent: |
| 986 | + async def read(self, block_size): |
| 987 | + request_info = aiohttp.RequestInfo("http://example.org", "GET", {}) |
| 988 | + raise aiohttp.client_exceptions.ClientResponseError(request_info, None) |
| 989 | + |
| 990 | + |
| 991 | +async def test_aiohttp_errors(): |
| 992 | + request = HttpRequest("GET", "http://example.org") |
| 993 | + response = AioHttpTransportResponse(request, MockAiohttpResponse()) |
| 994 | + with pytest.raises(ServiceResponseError): |
| 995 | + await response.load_body() |
| 996 | + |
| 997 | + generator = AioHttpStreamDownloadGenerator(None, response) |
| 998 | + with pytest.raises(ServiceResponseError): |
| 999 | + await generator.__anext__() |
0 commit comments