3131from 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 )
19236async 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 )
22450async 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
0 commit comments