Skip to content

Commit 622ba08

Browse files
committed
moved over to testserver
1 parent 866f5c2 commit 622ba08

11 files changed

+124
-140
lines changed

sdk/core/azure-core/azure/core/pipeline/transport/_requests_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class RequestsTransportResponse(HttpResponse, _RequestsTransportResponseBase):
136136
"""Streaming of data from the response.
137137
"""
138138
def stream_download(self, pipeline, **kwargs):
139-
# type: (PipelineType) -> Iterator[bytes]
139+
# type: (PipelineType, Any) -> Iterator[bytes]
140140
"""Generator for streaming request body data."""
141141
return StreamDownloadGenerator(pipeline, self, **kwargs)
142142

sdk/core/azure-core/azure/core/rest/_rest_py3.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@
4646
)
4747
from abc import abstractmethod
4848
from azure.core.exceptions import HttpResponseError
49+
from azure.core.pipeline import Pipeline, AsyncPipeline
50+
from azure.core.pipeline.transport import (
51+
HttpRequest as _PipelineTransportHttpRequest,
52+
)
53+
54+
from azure.core.pipeline.transport._base import (
55+
_HttpResponseBase as _PipelineTransportHttpResponseBase
56+
)
4957

5058
################################### TYPES SECTION #########################
5159

@@ -75,18 +83,6 @@
7583
Sequence[Tuple[str, FileType]]
7684
]
7785

78-
from azure.core.pipeline import Pipeline, AsyncPipeline
79-
from azure.core.pipeline.transport import (
80-
HttpRequest as _PipelineTransportHttpRequest,
81-
)
82-
83-
from azure.core.pipeline.transport._base import (
84-
_HttpResponseBase as _PipelineTransportHttpResponseBase
85-
)
86-
87-
from azure.core._pipeline_client import PipelineClient as _PipelineClient
88-
from azure.core._pipeline_client_async import AsyncPipelineClient as _AsyncPipelineClient
89-
9086
class HttpVerbs(str, Enum):
9187
GET = "GET"
9288
PUT = "PUT"
@@ -111,7 +107,9 @@ def _lookup_encoding(encoding: str) -> bool:
111107
except LookupError:
112108
return False
113109

114-
def _set_content_length_header(header_name: str, header_value: str, internal_request: _PipelineTransportHttpRequest) -> None:
110+
def _set_content_length_header(
111+
header_name: str, header_value: str, internal_request: _PipelineTransportHttpRequest
112+
) -> None:
115113
valid_methods = ["put", "post", "patch"]
116114
content_length_headers = ["Content-Length", "Transfer-Encoding"]
117115
if (
@@ -326,8 +324,6 @@ def __init__(
326324
files: Optional[FilesType] = None,
327325
**kwargs
328326
):
329-
# type: (str, str, Any) -> None
330-
331327
self._internal_request = kwargs.pop("_internal_request", _PipelineTransportHttpRequest(
332328
method=method,
333329
url=url,
@@ -475,7 +471,6 @@ def _get_charset_encoding(self) -> str:
475471

476472
@encoding.setter
477473
def encoding(self, value: str) -> None:
478-
# type: (str) -> None
479474
"""Sets the response encoding"""
480475
self._encoding = value
481476

sdk/core/azure-core/tests/test_rest/conftest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
# Licensed under the MIT License. See License.txt in the project root for
66
# license information.
77
# --------------------------------------------------------------------------
8-
98
import sys
109

1110

1211
# Ignore async tests for Python < 3.5
1312
collect_ignore_glob = []
1413
if sys.version_info < (3, 5):
1514
collect_ignore_glob.append("test_async*.py")
16-

sdk/core/azure-core/tests/test_rest/test_async_http_response.py

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,20 @@
66

77
# NOTE: These tests are heavily inspired from the httpx test suite: https://github.com/encode/httpx/tree/master/tests
88
# Thank you httpx for your wonderful tests!
9-
import json
9+
import functools
1010
import pytest
1111
import aiohttp
1212
from azure.core.pipeline.transport import AioHttpTransport
1313
from azure.core.rest import HttpRequest, AsyncHttpResponse
1414
from azure.core.exceptions import HttpResponseError
1515
from typing import Any, Dict
16+
from testcase_async import _create_http_response
1617

17-
async def _create_http_response(request=None):
18-
internal_response = await AioHttpTransport().send(request._internal_request, stream=False)
19-
response = AsyncHttpResponse(
20-
request=request,
21-
_internal_response=internal_response
22-
)
23-
return response
18+
create_http_response = functools.partial(_create_http_response, stream=False)
2419

2520
@pytest.mark.asyncio
2621
async def test_response():
27-
response = await _create_http_response(
22+
response = await create_http_response(
2823
request=HttpRequest("GET", "http://localhost:3000/basic/helloWorld/string"),
2924
)
3025

@@ -40,7 +35,7 @@ async def test_response():
4035

4136
@pytest.mark.asyncio
4237
async def test_response_content():
43-
response = await _create_http_response(
38+
response = await create_http_response(
4439
request=HttpRequest("GET", "http://localhost:3000/basic/helloWorld/bytes"),
4540
)
4641

@@ -54,7 +49,7 @@ async def test_response_content():
5449

5550
@pytest.mark.asyncio
5651
async def test_response_text():
57-
response = await _create_http_response(
52+
response = await create_http_response(
5853
request=HttpRequest("GET", "http://localhost:3000/basic/helloWorld/text"),
5954
)
6055

@@ -70,7 +65,7 @@ async def test_response_text():
7065

7166
@pytest.mark.asyncio
7267
async def test_response_html():
73-
response = await _create_http_response(
68+
response = await create_http_response(
7469
request=HttpRequest("GET", "http://localhost:3000/basic/helloWorld/html"),
7570
)
7671

@@ -83,19 +78,19 @@ async def test_response_html():
8378

8479
@pytest.mark.asyncio
8580
async def test_raise_for_status():
86-
response = await _create_http_response(
81+
response = await create_http_response(
8782
request=HttpRequest("GET", "http://localhost:3000/basic/helloWorld/text"),
8883
)
8984
response.raise_for_status()
9085

91-
response = await _create_http_response(
86+
response = await create_http_response(
9287
request=HttpRequest("GET", "http://localhost:3000/errors/403"),
9388
)
9489
assert response.status_code == 403
9590
with pytest.raises(HttpResponseError):
9691
response.raise_for_status()
9792

98-
response = await _create_http_response(
93+
response = await create_http_response(
9994
request=HttpRequest("GET", "http://localhost:3000/errors/500"),
10095
)
10196
assert response.status_code == 500
@@ -104,7 +99,7 @@ async def test_raise_for_status():
10499

105100
@pytest.mark.asyncio
106101
async def test_response_repr():
107-
response = await _create_http_response(
102+
response = await create_http_response(
108103
request=HttpRequest("GET", "http://localhost:3000/basic/helloWorld/text")
109104
)
110105
assert repr(response) == "<AsyncHttpResponse: 200 OK, Content-Type: text/plain; charset=utf-8>"
@@ -114,7 +109,7 @@ async def test_response_content_type_encoding():
114109
"""
115110
Use the charset encoding in the Content-Type header if possible.
116111
"""
117-
response = await _create_http_response(
112+
response = await create_http_response(
118113
request=HttpRequest("GET", "http://localhost:3000/encoding/latin-1")
119114
)
120115
await response.read()
@@ -128,7 +123,7 @@ async def test_response_autodetect_encoding():
128123
"""
129124
Autodetect encoding if there is no Content-Type header.
130125
"""
131-
response = await _create_http_response(
126+
response = await create_http_response(
132127
request=HttpRequest("GET", "http://localhost:3000/encoding/latin-1")
133128
)
134129
await response.read()
@@ -144,7 +139,7 @@ async def test_response_fallback_to_autodetect():
144139
"""
145140
Fallback to autodetection if we get an invalid charset in the Content-Type header.
146141
"""
147-
response = await _create_http_response(
142+
response = await create_http_response(
148143
request=HttpRequest("GET", "http://localhost:3000/encoding/latin-1")
149144
)
150145
await response.read()
@@ -161,7 +156,7 @@ async def test_response_no_charset_with_ascii_content():
161156
A response with ascii encoded content should decode correctly,
162157
even with no charset specified.
163158
"""
164-
response = await _create_http_response(
159+
response = await create_http_response(
165160
request=HttpRequest("GET", "http://localhost:3000/basic/helloWorld/string"),
166161
)
167162

@@ -181,7 +176,7 @@ async def test_response_no_charset_with_iso_8859_1_content():
181176
A response with ISO 8859-1 encoded content should decode correctly,
182177
even with no charset specified.
183178
"""
184-
response = await _create_http_response(
179+
response = await create_http_response(
185180
request=HttpRequest("GET", "http://localhost:3000/encoding/iso-8859-1"),
186181
)
187182
content = await response.read()
@@ -194,7 +189,7 @@ async def test_response_no_charset_with_iso_8859_1_content():
194189

195190
@pytest.mark.asyncio
196191
async def test_response_set_explicit_encoding():
197-
response = await _create_http_response(
192+
response = await create_http_response(
198193
request=HttpRequest("GET", "http://localhost:3000/encoding/latin-1-string-with-utf-8"),
199194
)
200195
response.encoding = "latin-1"
@@ -205,15 +200,15 @@ async def test_response_set_explicit_encoding():
205200

206201
@pytest.mark.asyncio
207202
async def test_json():
208-
response = await _create_http_response(
203+
response = await create_http_response(
209204
request=HttpRequest("GET", "http://localhost:3000/basic/json"),
210205
)
211206
await response.read()
212207
assert response.json() == {"greeting": "hello", "recipient": "world"}
213208

214209
@pytest.mark.asyncio
215210
async def test_json_with_specified_encoding():
216-
response = await _create_http_response(
211+
response = await create_http_response(
217212
request=HttpRequest("GET", "http://localhost:3000/encoding/json"),
218213
)
219214
await response.read()
@@ -222,23 +217,23 @@ async def test_json_with_specified_encoding():
222217

223218
@pytest.mark.asyncio
224219
async def test_emoji():
225-
response = await _create_http_response(
220+
response = await create_http_response(
226221
request=HttpRequest("GET", "http://localhost:3000/encoding/emoji"),
227222
)
228223
await response.read()
229224
assert response.text == "👩"
230225

231226
@pytest.mark.asyncio
232227
async def test_emoji_family_with_skin_tone_modifier():
233-
response = await _create_http_response(
228+
response = await create_http_response(
234229
request=HttpRequest("GET", "http://localhost:3000/encoding/emoji-family-skin-tone-modifier"),
235230
)
236231
await response.read()
237232
assert response.text == "👩🏻‍👩🏽‍👧🏾‍👦🏿 SSN: 859-98-0987"
238233

239234
@pytest.mark.asyncio
240235
async def test_korean_nfc():
241-
response = await _create_http_response(
236+
response = await create_http_response(
242237
request=HttpRequest("GET", "http://localhost:3000/encoding/korean"),
243238
)
244239
await response.read()

sdk/core/azure-core/tests/test_rest/test_async_stream_context_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async def test_stream_context_manager_error():
5454
with pytest.raises(ResponseNotReadError):
5555
r.content
5656
await r.read()
57-
assert str(e.value) == "HttpResponseError: 404 NOT FOUND"
57+
assert str(e.value) == "Operation returned an invalid status 'NOT FOUND'"
5858
assert r.content == b''
5959
assert r.is_closed
6060
assert r.is_stream_consumed

0 commit comments

Comments
 (0)