Skip to content

Commit 9a148c0

Browse files
pvaneckxiangyan99
andauthored
[Core][Corehttp] Update multipart test-server code (#35223)
* [Core][Corehttp] Update multipart test-server code Aiohttp now doesn't set payload `Content-Length` headers. Let's stop checking content length in the test server assertions. Signed-off-by: Paul Van Eck <[email protected]> * Update eng/tox/install_depend_packages.py --------- Signed-off-by: Paul Van Eck <[email protected]> Co-authored-by: Xiang Yan <[email protected]>
1 parent 9e9d5eb commit 9a148c0

File tree

5 files changed

+57
-70
lines changed

5 files changed

+57
-70
lines changed

eng/tox/install_depend_packages.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@
4545
"six": "1.12.0",
4646
"cryptography": "3.3.2",
4747
"msal": "1.23.0",
48+
"azure-storage-file-datalake": "12.2.0",
4849
}
4950

50-
MAXIMUM_VERSION_GENERIC_OVERRIDES = {
51-
"aiohttp": "3.9.3"
52-
}
51+
MAXIMUM_VERSION_GENERIC_OVERRIDES = {}
5352

5453
# SPECIFIC OVERRIDES provide additional filtering of upper and lower bound by
5554
# binding an override to the specific package being processed. As an example, when

sdk/core/azure-core/tests/async_tests/test_rest_http_response_async.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -271,32 +271,32 @@ async def test_text_and_encoding(send_request):
271271
assert response.encoding == "utf-16"
272272

273273

274-
# @pytest.mark.asyncio
275-
# async def test_multipart_encode_non_seekable_filelike(send_request):
276-
# """
277-
# Test that special readable but non-seekable filelike objects are supported,
278-
# at the cost of reading them into memory at most once.
279-
# """
280-
281-
# class IteratorIO(io.IOBase):
282-
# def __init__(self, iterator):
283-
# self._iterator = iterator
284-
285-
# def read(self, *args):
286-
# return b"".join(self._iterator)
287-
288-
# def data():
289-
# yield b"Hello"
290-
# yield b"World"
291-
292-
# fileobj = IteratorIO(data())
293-
# files = {"file": fileobj}
294-
# request = HttpRequest(
295-
# "POST",
296-
# "/multipart/non-seekable-filelike",
297-
# files=files,
298-
# )
299-
# await send_request(request)
274+
@pytest.mark.asyncio
275+
async def test_multipart_encode_non_seekable_filelike(send_request):
276+
"""
277+
Test that special readable but non-seekable filelike objects are supported,
278+
at the cost of reading them into memory at most once.
279+
"""
280+
281+
class IteratorIO(io.IOBase):
282+
def __init__(self, iterator):
283+
self._iterator = iterator
284+
285+
def read(self, *args):
286+
return b"".join(self._iterator)
287+
288+
def data():
289+
yield b"Hello"
290+
yield b"World"
291+
292+
fileobj = IteratorIO(data())
293+
files = {"file": fileobj}
294+
request = HttpRequest(
295+
"POST",
296+
"/multipart/non-seekable-filelike",
297+
files=files,
298+
)
299+
await send_request(request)
300300

301301

302302
def test_initialize_response_abc():

sdk/core/azure-core/tests/testserver_tests/coretestserver/coretestserver/test_routes/multipart.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ def basic():
2525
assert_with_message("content type", multipart_header_start, request.content_type[: len(multipart_header_start)])
2626
if request.files:
2727
# aiohttp
28-
assert_with_message("content length", 228, request.content_length)
2928
assert_with_message("num files", 1, len(request.files))
3029
assert_with_message("has file named fileContent", True, bool(request.files.get("fileContent")))
3130
file_content = request.files["fileContent"]
3231
assert_with_message("file content type", "application/octet-stream", file_content.content_type)
33-
assert_with_message("file content length", 14, file_content.content_length)
3432
assert_with_message("filename", "fileContent", file_content.filename)
3533
assert_with_message(
3634
"has content disposition header", True, bool(file_content.headers.get("Content-Disposition"))
@@ -42,7 +40,6 @@ def basic():
4240
)
4341
elif request.form:
4442
# requests
45-
assert_with_message("content length", 184, request.content_length)
4643
assert_with_message("fileContent", "<file content>", request.form["fileContent"])
4744
else:
4845
return Response(status=400) # should be either of these
@@ -58,7 +55,6 @@ def data_and_files():
5855
assert_with_message("message", "Hello, world!", request.form["message"])
5956
file_content = request.files["fileContent"]
6057
assert_with_message("file content type", "application/octet-stream", file_content.content_type)
61-
assert_with_message("file content length", 14, file_content.content_length)
6258
assert_with_message("filename", "fileContent", file_content.filename)
6359
assert_with_message(
6460
"has content disposition header", True, bool(file_content.headers.get("Content-Disposition"))
@@ -93,17 +89,15 @@ def non_seekable_filelike():
9389
# aiohttp
9490
len_files = len(request.files)
9591
assert_with_message("num files", 1, len_files)
96-
# assert_with_message("content length", 258, request.content_length)
9792
assert_with_message("num files", 1, len(request.files))
9893
assert_with_message("has file named file", True, bool(request.files.get("file")))
9994
file = request.files["file"]
10095
assert_with_message("file content type", "application/octet-stream", file.content_type)
101-
assert_with_message("file content length", 14, file.content_length)
10296
assert_with_message("filename", "file", file.filename)
10397
assert_with_message("has content disposition header", True, bool(file.headers.get("Content-Disposition")))
10498
assert_with_message(
10599
"content disposition",
106-
'form-data; name="fileContent"; filename="fileContent"; filename*=utf-8\'\'fileContent',
100+
'form-data; name="file"; filename="file"',
107101
file.headers["Content-Disposition"],
108102
)
109103
elif request.form:

sdk/core/corehttp/tests/async_tests/test_rest_http_response_async.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -252,33 +252,33 @@ async def test_text_and_encoding(send_request, transport):
252252
assert response.encoding == "utf-16"
253253

254254

255-
# @pytest.mark.asyncio
256-
# @pytest.mark.parametrize("transport", ASYNC_TRANSPORTS)
257-
# async def test_multipart_encode_non_seekable_filelike(send_request, transport):
258-
# """
259-
# Test that special readable but non-seekable filelike objects are supported,
260-
# at the cost of reading them into memory at most once.
261-
# """
262-
263-
# class IteratorIO(io.IOBase):
264-
# def __init__(self, iterator):
265-
# self._iterator = iterator
266-
267-
# def read(self, *args):
268-
# return b"".join(self._iterator)
269-
270-
# def data():
271-
# yield b"Hello"
272-
# yield b"World"
273-
274-
# fileobj = IteratorIO(data())
275-
# files = {"file": fileobj}
276-
# request = HttpRequest(
277-
# "POST",
278-
# "/multipart/non-seekable-filelike",
279-
# files=files,
280-
# )
281-
# await send_request(request, transport())
255+
@pytest.mark.asyncio
256+
@pytest.mark.parametrize("transport", ASYNC_TRANSPORTS)
257+
async def test_multipart_encode_non_seekable_filelike(send_request, transport):
258+
"""
259+
Test that special readable but non-seekable filelike objects are supported,
260+
at the cost of reading them into memory at most once.
261+
"""
262+
263+
class IteratorIO(io.IOBase):
264+
def __init__(self, iterator):
265+
self._iterator = iterator
266+
267+
def read(self, *args):
268+
return b"".join(self._iterator)
269+
270+
def data():
271+
yield b"Hello"
272+
yield b"World"
273+
274+
fileobj = IteratorIO(data())
275+
files = {"file": fileobj}
276+
request = HttpRequest(
277+
"POST",
278+
"/multipart/non-seekable-filelike",
279+
files=files,
280+
)
281+
await send_request(request, transport())
282282

283283

284284
def test_initialize_response_abc():

sdk/core/corehttp/tests/testserver_tests/coretestserver/coretestserver/test_routes/multipart.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ def basic():
2525
assert_with_message("content type", multipart_header_start, request.content_type[: len(multipart_header_start)])
2626
if request.files:
2727
# aiohttp
28-
assert_with_message("content length", 228, request.content_length)
2928
assert_with_message("num files", 1, len(request.files))
3029
assert_with_message("has file named fileContent", True, bool(request.files.get("fileContent")))
3130
file_content = request.files["fileContent"]
3231
assert_with_message("file content type", "application/octet-stream", file_content.content_type)
33-
assert_with_message("file content length", 14, file_content.content_length)
3432
assert_with_message("filename", "fileContent", file_content.filename)
3533
assert_with_message(
3634
"has content disposition header", True, bool(file_content.headers.get("Content-Disposition"))
@@ -42,7 +40,6 @@ def basic():
4240
)
4341
elif request.form:
4442
# requests
45-
assert_with_message("content length", 184, request.content_length)
4643
assert_with_message("fileContent", "<file content>", request.form["fileContent"])
4744
else:
4845
return Response(status=400) # should be either of these
@@ -58,7 +55,6 @@ def data_and_files():
5855
assert_with_message("message", "Hello, world!", request.form["message"])
5956
file_content = request.files["fileContent"]
6057
assert_with_message("file content type", "application/octet-stream", file_content.content_type)
61-
assert_with_message("file content length", 14, file_content.content_length)
6258
assert_with_message("filename", "fileContent", file_content.filename)
6359
assert_with_message(
6460
"has content disposition header", True, bool(file_content.headers.get("Content-Disposition"))
@@ -93,17 +89,15 @@ def non_seekable_filelike():
9389
# aiohttp
9490
len_files = len(request.files)
9591
assert_with_message("num files", 1, len_files)
96-
# assert_with_message("content length", 258, request.content_length)
9792
assert_with_message("num files", 1, len(request.files))
9893
assert_with_message("has file named file", True, bool(request.files.get("file")))
9994
file = request.files["file"]
10095
assert_with_message("file content type", "application/octet-stream", file.content_type)
101-
assert_with_message("file content length", 14, file.content_length)
10296
assert_with_message("filename", "file", file.filename)
10397
assert_with_message("has content disposition header", True, bool(file.headers.get("Content-Disposition")))
10498
assert_with_message(
10599
"content disposition",
106-
'form-data; name="fileContent"; filename="fileContent"; filename*=utf-8\'\'fileContent',
100+
'form-data; name="file"; filename="file"',
107101
file.headers["Content-Disposition"],
108102
)
109103
elif request.form:

0 commit comments

Comments
 (0)