1010from utils import readonly_checks
1111import pytest
1212
13+ @pytest .fixture
14+ async def client (port ):
15+ async with TrioRequestsTransport () as transport :
16+ async with AsyncTestRestClient (port , transport = transport ) as client :
17+ yield client
1318
1419@pytest .mark .trio
15- async def test_async_gen_data (port ):
20+ async def test_async_gen_data (client , port ):
1621 class AsyncGen :
1722 def __init__ (self ):
1823 self ._range = iter ([b"azerty" ])
@@ -26,30 +31,51 @@ async def __anext__(self):
2631 except StopIteration :
2732 raise StopAsyncIteration
2833
29- async with TrioRequestsTransport () as transport :
30- client = AsyncTestRestClient (port , transport = transport )
31- request = HttpRequest ('GET' , 'http://localhost:{}/basic/anything' .format (port ), content = AsyncGen ())
32- response = await client .send_request (request )
33- assert response .json ()['data' ] == "azerty"
34+ request = HttpRequest ('GET' , 'http://localhost:{}/basic/anything' .format (port ), content = AsyncGen ())
35+ response = await client .send_request (request )
36+ assert response .json ()['data' ] == "azerty"
3437
3538@pytest .mark .trio
36- async def test_send_data (port ):
37- async with TrioRequestsTransport () as transport :
38- request = HttpRequest ('PUT' , 'http://localhost:{}/basic/anything' .format (port ), content = b"azerty" )
39- client = AsyncTestRestClient (port , transport = transport )
40- response = await client .send_request (request )
41-
42- assert response .json ()['data' ] == "azerty"
39+ async def test_send_data (port , client ):
40+ request = HttpRequest ('PUT' , 'http://localhost:{}/basic/anything' .format (port ), content = b"azerty" )
41+ response = await client .send_request (request )
42+ assert response .json ()['data' ] == "azerty"
4343
4444@pytest .mark .trio
45- async def test_readonly (port ):
45+ async def test_readonly (client ):
4646 """Make sure everything that is readonly is readonly"""
47- async with TrioRequestsTransport () as transport :
48- request = HttpRequest ('GET' , 'http://localhost:{}/health' .format (port ))
49- client = AsyncTestRestClient (port , transport = transport )
50- response = await client .send_request (HttpRequest ("GET" , "/health" ))
51- response .raise_for_status ()
47+ response = await client .send_request (HttpRequest ("GET" , "/health" ))
48+ response .raise_for_status ()
5249
5350 assert isinstance (response , RestTrioRequestsTransportResponse )
5451 from azure .core .pipeline .transport import TrioRequestsTransportResponse
5552 readonly_checks (response , old_response_class = TrioRequestsTransportResponse )
53+
54+ @pytest .mark .trio
55+ async def test_decompress_compressed_header (client ):
56+ # expect plain text
57+ request = HttpRequest ("GET" , "/encoding/gzip" )
58+ response = await client .send_request (request )
59+ content = await response .read ()
60+ assert content == b"hello world"
61+ assert response .content == content
62+ assert response .text () == "hello world"
63+
64+ @pytest .mark .trio
65+ async def test_decompress_compressed_header_stream (client ):
66+ # expect plain text
67+ request = HttpRequest ("GET" , "/encoding/gzip" )
68+ response = await client .send_request (request , stream = True )
69+ content = await response .read ()
70+ assert content == b"hello world"
71+ assert response .content == content
72+ assert response .text () == "hello world"
73+
74+ @pytest .mark .trio
75+ async def test_decompress_compressed_header_stream_body_content (client ):
76+ # expect plain text
77+ request = HttpRequest ("GET" , "/encoding/gzip" )
78+ response = await client .send_request (request , stream = True )
79+ await response .read ()
80+ content = response .content
81+ assert content == response .body ()
0 commit comments