1515from gsrest .app import create_app # noqa: E402
1616
1717
18- class AioHTTPClientShim :
19- """Shim to make httpx.AsyncClient look like aiohttp.ClientSession for tests .
18+ class HTTPClientShim :
19+ """Shim providing async-style API for httpx.AsyncClient .
2020
21- This allows existing tests that use aiohttp-style API to work with httpx .
21+ Provides await-based response methods for backward compatibility with existing tests .
2222 """
2323
2424 def __init__ (self , httpx_client : AsyncClient ):
@@ -27,16 +27,11 @@ def __init__(self, httpx_client: AsyncClient):
2727 async def request (
2828 self , path : str = None , method : str = "GET" , json = None , headers = None , ** kwargs
2929 ):
30- """Mimic aiohttp's client.request() API.
31-
32- aiohttp uses: client.request(path="/foo", method="GET")
33- httpx uses: client.request(method="GET", url="/foo")
34- """
3530 url = path or kwargs .get ("url" , "/" )
3631 response = await self ._client .request (
3732 method = method , url = url , json = json , headers = headers
3833 )
39- return AioHTTPResponseShim (response )
34+ return HTTPResponseShim (response )
4035
4136 async def get (self , path : str , headers = None , ** kwargs ):
4237 return await self .request (path = path , method = "GET" , headers = headers , ** kwargs )
@@ -47,27 +42,23 @@ async def post(self, path: str, json=None, headers=None, **kwargs):
4742 )
4843
4944
50- class AioHTTPResponseShim :
51- """Shim to make httpx.Response look like aiohttp.ClientResponse for tests ."""
45+ class HTTPResponseShim :
46+ """Shim providing async-style API for httpx.Response ."""
5247
5348 def __init__ (self , httpx_response ):
5449 self ._response = httpx_response
5550
5651 @property
5752 def status (self ) -> int :
58- """aiohttp uses .status, httpx uses .status_code"""
5953 return self ._response .status_code
6054
6155 async def read (self ) -> bytes :
62- """aiohttp uses await response.read(), httpx has response.content"""
6356 return self ._response .content
6457
6558 async def text (self ) -> str :
66- """aiohttp uses await response.text(), httpx has response.text"""
6759 return self ._response .text
6860
6961 async def json (self ):
70- """aiohttp uses await response.json(), httpx has response.json()"""
7162 return self ._response .json ()
7263
7364 @property
@@ -100,10 +91,7 @@ def __getitem__(self, key):
10091
10192
10293class BaseTestCase :
103- """Base test case for FastAPI tests using httpx.
104-
105- Maintains backward compatibility with existing aiohttp-style tests.
106- """
94+ """Base test case for FastAPI tests using httpx."""
10795
10896 config : dict = None # Set by conftest.py
10997 app = None # Will be set during setup
@@ -131,8 +119,7 @@ async def setup_client(self):
131119 async with AsyncClient (
132120 transport = transport , base_url = "http://test"
133121 ) as httpx_client :
134- # Wrap httpx client in aiohttp-compatible shim
135- self .client = AioHTTPClientShim (httpx_client )
122+ self .client = HTTPClientShim (httpx_client )
136123 self ._httpx_client = (
137124 httpx_client # Keep reference for direct access if needed
138125 )
0 commit comments