Skip to content

Commit bba0c81

Browse files
authored
[Core][Corehttp] Fix stream tests (Azure#35433)
Some tests hit an external endpoint that we no longer have access to. These are adjusted to hit the local endpoint if possible. Some tests were removed that test live endpoints. Signed-off-by: Paul Van Eck <[email protected]>
1 parent 5ea1750 commit bba0c81

File tree

9 files changed

+14
-712
lines changed

9 files changed

+14
-712
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,7 @@ async def test_cannot_read_after_response_closed(port, client):
138138
@pytest.mark.asyncio
139139
async def test_decompress_plain_no_header(client):
140140
# thanks to Xiang Yan for this test!
141-
account_name = "coretests"
142-
url = "https://{}.blob.core.windows.net/tests/test.txt".format(account_name)
143-
request = HttpRequest("GET", url)
141+
request = HttpRequest("GET", "/streams/string")
144142
async with client:
145143
response = await client.send_request(request, stream=True)
146144
with pytest.raises(ResponseNotReadError):
@@ -152,9 +150,7 @@ async def test_decompress_plain_no_header(client):
152150
@pytest.mark.asyncio
153151
async def test_compress_plain_no_header(client):
154152
# thanks to Xiang Yan for this test!
155-
account_name = "coretests"
156-
url = "https://{}.blob.core.windows.net/tests/test.txt".format(account_name)
157-
request = HttpRequest("GET", url)
153+
request = HttpRequest("GET", "/streams/string")
158154
async with client:
159155
response = await client.send_request(request, stream=True)
160156
iter = response.iter_raw()

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

Lines changed: 3 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -31,162 +31,6 @@
3131
from utils import HTTP_REQUESTS
3232

3333

34-
@pytest.mark.live_test_only
35-
@pytest.mark.asyncio
36-
@pytest.mark.parametrize("http_request", HTTP_REQUESTS)
37-
async def test_decompress_plain_no_header(http_request):
38-
# expect plain text
39-
account_name = "coretests"
40-
account_url = "https://{}.blob.core.windows.net".format(account_name)
41-
url = "https://{}.blob.core.windows.net/tests/test.txt".format(account_name)
42-
client = AsyncPipelineClient(account_url)
43-
async with client:
44-
request = http_request("GET", url)
45-
pipeline_response = await client._pipeline.run(request, stream=True)
46-
response = pipeline_response.http_response
47-
data = response.stream_download(client._pipeline, decompress=True)
48-
content = b""
49-
async for d in data:
50-
content += d
51-
decoded = content.decode("utf-8")
52-
assert decoded == "test"
53-
54-
55-
@pytest.mark.live_test_only
56-
@pytest.mark.asyncio
57-
@pytest.mark.parametrize("http_request", HTTP_REQUESTS)
58-
async def test_compress_plain_no_header(http_request):
59-
# expect plain text
60-
account_name = "coretests"
61-
account_url = "https://{}.blob.core.windows.net".format(account_name)
62-
url = "https://{}.blob.core.windows.net/tests/test.txt".format(account_name)
63-
client = AsyncPipelineClient(account_url)
64-
async with client:
65-
request = http_request("GET", url)
66-
pipeline_response = await client._pipeline.run(request, stream=True)
67-
response = pipeline_response.http_response
68-
data = response.stream_download(client._pipeline, decompress=False)
69-
content = b""
70-
async for d in data:
71-
content += d
72-
decoded = content.decode("utf-8")
73-
assert decoded == "test"
74-
75-
76-
@pytest.mark.live_test_only
77-
@pytest.mark.asyncio
78-
@pytest.mark.parametrize("http_request", HTTP_REQUESTS)
79-
async def test_decompress_compressed_no_header(http_request):
80-
# expect compressed text
81-
account_name = "coretests"
82-
account_url = "https://{}.blob.core.windows.net".format(account_name)
83-
url = "https://{}.blob.core.windows.net/tests/test.tar.gz".format(account_name)
84-
client = AsyncPipelineClient(account_url)
85-
async with client:
86-
request = http_request("GET", url)
87-
pipeline_response = await client._pipeline.run(request, stream=True)
88-
response = pipeline_response.http_response
89-
data = response.stream_download(client._pipeline, decompress=True)
90-
content = b""
91-
async for d in data:
92-
content += d
93-
try:
94-
decoded = content.decode("utf-8")
95-
assert False
96-
except UnicodeDecodeError:
97-
pass
98-
99-
100-
@pytest.mark.live_test_only
101-
@pytest.mark.asyncio
102-
@pytest.mark.parametrize("http_request", HTTP_REQUESTS)
103-
async def test_compress_compressed_no_header(http_request):
104-
# expect compressed text
105-
account_name = "coretests"
106-
account_url = "https://{}.blob.core.windows.net".format(account_name)
107-
url = "https://{}.blob.core.windows.net/tests/test.tar.gz".format(account_name)
108-
client = AsyncPipelineClient(account_url)
109-
async with client:
110-
request = http_request("GET", url)
111-
pipeline_response = await client._pipeline.run(request, stream=True)
112-
response = pipeline_response.http_response
113-
data = response.stream_download(client._pipeline, decompress=False)
114-
content = b""
115-
async for d in data:
116-
content += d
117-
try:
118-
decoded = content.decode("utf-8")
119-
assert False
120-
except UnicodeDecodeError:
121-
pass
122-
123-
124-
@pytest.mark.live_test_only
125-
@pytest.mark.asyncio
126-
@pytest.mark.parametrize("http_request", HTTP_REQUESTS)
127-
async def test_decompress_plain_header(http_request):
128-
# expect error
129-
130-
account_name = "coretests"
131-
account_url = "https://{}.blob.core.windows.net".format(account_name)
132-
url = "https://{}.blob.core.windows.net/tests/test_with_header.txt".format(account_name)
133-
client = AsyncPipelineClient(account_url)
134-
async with client:
135-
request = http_request("GET", url)
136-
pipeline_response = await client._pipeline.run(request, stream=True)
137-
response = pipeline_response.http_response
138-
data = response.stream_download(client._pipeline, decompress=True)
139-
try:
140-
content = b""
141-
async for d in data:
142-
content += d
143-
assert False
144-
except (zlib.error, DecodeError):
145-
pass
146-
147-
148-
@pytest.mark.live_test_only
149-
@pytest.mark.asyncio
150-
@pytest.mark.parametrize("http_request", HTTP_REQUESTS)
151-
async def test_compress_plain_header(http_request):
152-
# expect plain text
153-
account_name = "coretests"
154-
account_url = "https://{}.blob.core.windows.net".format(account_name)
155-
url = "https://{}.blob.core.windows.net/tests/test_with_header.txt".format(account_name)
156-
client = AsyncPipelineClient(account_url)
157-
async with client:
158-
request = http_request("GET", url)
159-
pipeline_response = await client._pipeline.run(request, stream=True)
160-
response = pipeline_response.http_response
161-
data = response.stream_download(client._pipeline, decompress=False)
162-
content = b""
163-
async for d in data:
164-
content += d
165-
decoded = content.decode("utf-8")
166-
assert decoded == "test"
167-
168-
169-
@pytest.mark.live_test_only
170-
@pytest.mark.asyncio
171-
@pytest.mark.parametrize("http_request", HTTP_REQUESTS)
172-
async def test_decompress_compressed_header(http_request):
173-
# expect plain text
174-
account_name = "coretests"
175-
account_url = "https://{}.blob.core.windows.net".format(account_name)
176-
url = "https://{}.blob.core.windows.net/tests/test_with_header.tar.gz".format(account_name)
177-
client = AsyncPipelineClient(account_url)
178-
async with client:
179-
request = http_request("GET", url)
180-
pipeline_response = await client._pipeline.run(request, stream=True)
181-
response = pipeline_response.http_response
182-
data = response.stream_download(client._pipeline, decompress=True)
183-
content = b""
184-
async for d in data:
185-
content += d
186-
decoded = content.decode("utf-8")
187-
assert decoded == "test"
188-
189-
19034
@pytest.mark.asyncio
19135
@pytest.mark.parametrize("http_request", HTTP_REQUESTS)
19236
async def test_compress_compressed_no_header_offline(port, http_request):
@@ -201,24 +45,6 @@ async def test_compress_compressed_no_header_offline(port, http_request):
20145
b"".join([d async for d in data]).decode("utf-8")
20246

20347

204-
@pytest.mark.live_test_only
205-
@pytest.mark.asyncio
206-
@pytest.mark.parametrize("http_request", HTTP_REQUESTS)
207-
async def test_compress_compressed_header(http_request):
208-
# expect compressed text
209-
account_name = "coretests"
210-
account_url = "https://{}.blob.core.windows.net".format(account_name)
211-
url = "https://{}.blob.core.windows.net/tests/test_with_header.tar.gz".format(account_name)
212-
client = AsyncPipelineClient(account_url)
213-
async with client:
214-
request = http_request("GET", url)
215-
pipeline_response = await client._pipeline.run(request, stream=True)
216-
response = pipeline_response.http_response
217-
data = response.stream_download(client._pipeline, decompress=False)
218-
with pytest.raises(UnicodeDecodeError):
219-
b"".join([d async for d in data]).decode("utf-8")
220-
221-
22248
@pytest.mark.asyncio
22349
@pytest.mark.parametrize("http_request", HTTP_REQUESTS)
22450
async def test_decompress_plain_no_header_offline(port, http_request):
@@ -257,9 +83,10 @@ async def test_decompress_compressed_no_header_offline(port, http_request):
25783
pipeline_response = await client._pipeline.run(request, stream=True)
25884
response = pipeline_response.http_response
25985
data = response.stream_download(client._pipeline, decompress=True)
260-
86+
content = b"".join([d async for d in data])
87+
assert content.startswith(b"\x1f\x8b") # gzip magic number
26188
with pytest.raises(UnicodeDecodeError):
262-
b"".join([d async for d in data]).decode("utf-8")
89+
content.decode("utf-8")
26390

26491

26592
@pytest.mark.asyncio

sdk/core/azure-core/tests/test_rest_stream_responses.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,7 @@ def test_cannot_read_after_response_closed(port, client):
147147

148148
def test_decompress_plain_no_header(client):
149149
# thanks to Xiang Yan for this test!
150-
account_name = "coretests"
151-
url = "https://{}.blob.core.windows.net/tests/test.txt".format(account_name)
152-
request = HttpRequest("GET", url)
150+
request = HttpRequest("GET", "/streams/string")
153151
response = client.send_request(request, stream=True)
154152
with pytest.raises(ResponseNotReadError):
155153
response.content
@@ -159,9 +157,7 @@ def test_decompress_plain_no_header(client):
159157

160158
def test_compress_plain_no_header(client):
161159
# thanks to Xiang Yan for this test!
162-
account_name = "coretests"
163-
url = "https://{}.blob.core.windows.net/tests/test.txt".format(account_name)
164-
request = HttpRequest("GET", url)
160+
request = HttpRequest("GET", "/streams/string")
165161
response = client.send_request(request, stream=True)
166162
iter = response.iter_raw()
167163
data = b"".join(list(iter))
@@ -170,25 +166,11 @@ def test_compress_plain_no_header(client):
170166

171167
def test_decompress_compressed_no_header(client):
172168
# thanks to Xiang Yan for this test!
173-
account_name = "coretests"
174-
url = "https://{}.blob.core.windows.net/tests/test.tar.gz".format(account_name)
175-
request = HttpRequest("GET", url)
169+
request = HttpRequest("GET", "/streams/compressed_no_header")
176170
response = client.send_request(request, stream=True)
177171
iter = response.iter_bytes()
178172
data = b"".join(list(iter))
179-
assert data == b"\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\n+I-.\x01\x00\x0c~\x7f\xd8\x04\x00\x00\x00"
180-
181-
182-
def test_decompress_compressed_header(client):
183-
# thanks to Xiang Yan for this test!
184-
account_name = "coretests"
185-
account_url = "https://{}.blob.core.windows.net".format(account_name)
186-
url = "https://{}.blob.core.windows.net/tests/test_with_header.tar.gz".format(account_name)
187-
request = HttpRequest("GET", url)
188-
response = client.send_request(request, stream=True)
189-
iter = response.iter_bytes()
190-
data = b"".join(list(iter))
191-
assert data == b"test"
173+
assert data.startswith(b"\x1f\x8b") # gzip magic number
192174

193175

194176
def test_iter_read(client):

0 commit comments

Comments
 (0)