@@ -17,6 +17,18 @@ async def get_user(self, user_id: str) -> User:
1717 @post ("/users" )
1818 async def create_user (self , name : str , email : str ) -> User :
1919 ...
20+
21+ @post ("/users/string" )
22+ async def get_user_string (self , name : str ) -> str :
23+ ...
24+
25+ @post ("/users/bytes" )
26+ async def get_user_bytes (self , name : str ) -> bytes :
27+ ...
28+
29+ @post ("/users/dict" )
30+ async def get_user_dict (self , name : str ) -> dict :
31+ ...
2032
2133
2234class TestHttpxClient (HttpxWebClient ):
@@ -27,6 +39,18 @@ async def get_user(self, user_id: str) -> User:
2739 @post ("/users" )
2840 async def create_user (self , name : str , email : str ) -> User :
2941 ...
42+
43+ @post ("/users/string" )
44+ async def get_user_string (self , name : str ) -> str :
45+ ...
46+
47+ @post ("/users/bytes" )
48+ async def get_user_bytes (self , name : str ) -> bytes :
49+ ...
50+
51+ @post ("/users/dict" )
52+ async def get_user_dict (self , name : str ) -> dict :
53+ ...
3054
3155
3256@pytest .mark .asyncio
@@ -62,4 +86,58 @@ async def test_aiohttp_error_handling(mock_server, base_url):
6286async def test_httpx_error_handling (mock_server , base_url ):
6387 client = TestHttpxClient (base_url = f"{ base_url } /nonexistent" )
6488 with pytest .raises (BaseException ):
65- await client .get_user ("123" )
89+ await client .get_user ("123" )
90+
91+
92+ @pytest .mark .asyncio
93+ async def test_aiohttp_get_string_request (mock_server , base_url ):
94+ client = TestAiohttpClient (base_url = base_url )
95+ response = await client .get_user_string ("123" )
96+
97+ assert isinstance (response , str )
98+ assert response == "abc"
99+
100+
101+ @pytest .mark .asyncio
102+ async def test_aiohttp_get_bytes_request (mock_server , base_url ):
103+ client = TestAiohttpClient (base_url = base_url )
104+ response = await client .get_user_bytes ("123" )
105+ print (response )
106+ assert isinstance (response , bytes )
107+ assert response == "abc" .encode ()
108+
109+
110+ @pytest .mark .asyncio
111+ async def test_httpx_get_dict_request (mock_server , base_url ):
112+ client = TestAiohttpClient (base_url = base_url )
113+ response = await client .get_user_dict ("123" )
114+
115+ assert isinstance (response , dict )
116+ assert response == {"users" : []}
117+
118+
119+ @pytest .mark .asyncio
120+ async def test_httpx_get_string_request (mock_server , base_url ):
121+ client = TestHttpxClient (base_url = base_url )
122+ response = await client .get_user_string ("123" )
123+
124+ assert isinstance (response , str )
125+ assert response == "abc"
126+
127+
128+ @pytest .mark .asyncio
129+ async def test_httpx_get_bytes_request (mock_server , base_url ):
130+ client = TestHttpxClient (base_url = base_url )
131+ response = await client .get_user_bytes ("123" )
132+ print (response )
133+ assert isinstance (response , bytes )
134+ assert response == "abc" .encode ()
135+
136+
137+ @pytest .mark .asyncio
138+ async def test_aiohttp_get_dict_request (mock_server , base_url ):
139+ client = TestHttpxClient (base_url = base_url )
140+ response = await client .get_user_dict ("123" )
141+
142+ assert isinstance (response , dict )
143+ assert response == {"users" : []}
0 commit comments