fastapi-testing 0.1.1__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fastapi_testing-0.1.1 → fastapi_testing-0.2.0}/PKG-INFO +1 -1
- {fastapi_testing-0.1.1 → fastapi_testing-0.2.0}/pyproject.toml +1 -1
- {fastapi_testing-0.1.1 → fastapi_testing-0.2.0}/src/fastapi_testing/__init__.py +6 -6
- {fastapi_testing-0.1.1 → fastapi_testing-0.2.0}/src/fastapi_testing/async_fastapi_testing.py +17 -17
- {fastapi_testing-0.1.1 → fastapi_testing-0.2.0}/LICENSE +0 -0
- {fastapi_testing-0.1.1 → fastapi_testing-0.2.0}/docs/index.rst +0 -0
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
from fastapi_testing.async_fastapi_testing import (
|
|
2
2
|
PortGenerator,
|
|
3
3
|
UvicornTestServer,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
AsyncTestServer,
|
|
5
|
+
AsyncTestClient,
|
|
6
|
+
AsyncTestResponse,
|
|
7
7
|
create_test_server,
|
|
8
8
|
)
|
|
9
9
|
|
|
10
10
|
__all__ = [
|
|
11
11
|
"PortGenerator",
|
|
12
12
|
"UvicornTestServer",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
13
|
+
"AsyncTestServer",
|
|
14
|
+
"AsyncTestClient",
|
|
15
|
+
"AsyncTestResponse",
|
|
16
16
|
"create_test_server",
|
|
17
17
|
]
|
{fastapi_testing-0.1.1 → fastapi_testing-0.2.0}/src/fastapi_testing/async_fastapi_testing.py
RENAMED
|
@@ -63,7 +63,7 @@ class UvicornTestServer(uvicorn.Server):
|
|
|
63
63
|
self.startup_handler.set()
|
|
64
64
|
|
|
65
65
|
|
|
66
|
-
class
|
|
66
|
+
class AsyncTestServer:
|
|
67
67
|
def __init__(
|
|
68
68
|
self,
|
|
69
69
|
lifespan: Optional[Lifespan[AppType]] = None,
|
|
@@ -78,7 +78,7 @@ class TestServer:
|
|
|
78
78
|
self._server_task: Optional[asyncio.Task] = None
|
|
79
79
|
self._port: Optional[int] = None
|
|
80
80
|
self._host = "127.0.0.1"
|
|
81
|
-
self._client: Optional[
|
|
81
|
+
self._client: Optional[AsyncTestClient] = None
|
|
82
82
|
self._server: Optional[UvicornTestServer] = None
|
|
83
83
|
|
|
84
84
|
async def start(self) -> None:
|
|
@@ -107,7 +107,7 @@ class TestServer:
|
|
|
107
107
|
await asyncio.wait_for(startup_handler.wait(), timeout=self.startup_timeout)
|
|
108
108
|
|
|
109
109
|
# Initialize test client after server is confirmed running
|
|
110
|
-
self._client =
|
|
110
|
+
self._client = AsyncTestClient(
|
|
111
111
|
base_url=self.base_url,
|
|
112
112
|
timeout=self.startup_timeout
|
|
113
113
|
)
|
|
@@ -164,7 +164,7 @@ class TestServer:
|
|
|
164
164
|
raise RuntimeError("Server is not running")
|
|
165
165
|
return f"http://{self._host}:{self._port}"
|
|
166
166
|
|
|
167
|
-
async def __aenter__(self) -> '
|
|
167
|
+
async def __aenter__(self) -> 'AsyncTestServer':
|
|
168
168
|
await self.start()
|
|
169
169
|
return self
|
|
170
170
|
|
|
@@ -172,13 +172,13 @@ class TestServer:
|
|
|
172
172
|
await self.stop()
|
|
173
173
|
|
|
174
174
|
@property
|
|
175
|
-
def client(self) -> '
|
|
175
|
+
def client(self) -> 'AsyncTestClient':
|
|
176
176
|
if not self._client:
|
|
177
177
|
raise RuntimeError("Server is not running")
|
|
178
178
|
return self._client
|
|
179
179
|
|
|
180
180
|
|
|
181
|
-
class
|
|
181
|
+
class AsyncTestClient:
|
|
182
182
|
def __init__(
|
|
183
183
|
self,
|
|
184
184
|
base_url: str,
|
|
@@ -204,27 +204,27 @@ class TestClient:
|
|
|
204
204
|
method: str,
|
|
205
205
|
url: str,
|
|
206
206
|
**kwargs: Any
|
|
207
|
-
) -> '
|
|
207
|
+
) -> 'AsyncTestResponse':
|
|
208
208
|
response = await self._client.request(method, url, **kwargs)
|
|
209
|
-
return
|
|
209
|
+
return AsyncTestResponse(response)
|
|
210
210
|
|
|
211
|
-
async def get(self, url: str, **kwargs: Any) -> '
|
|
211
|
+
async def get(self, url: str, **kwargs: Any) -> 'AsyncTestResponse':
|
|
212
212
|
return await self.request('GET', url, **kwargs)
|
|
213
213
|
|
|
214
|
-
async def post(self, url: str, **kwargs: Any) -> '
|
|
214
|
+
async def post(self, url: str, **kwargs: Any) -> 'AsyncTestResponse':
|
|
215
215
|
return await self.request('POST', url, **kwargs)
|
|
216
216
|
|
|
217
|
-
async def put(self, url: str, **kwargs: Any) -> '
|
|
217
|
+
async def put(self, url: str, **kwargs: Any) -> 'AsyncTestResponse':
|
|
218
218
|
return await self.request('PUT', url, **kwargs)
|
|
219
219
|
|
|
220
|
-
async def delete(self, url: str, **kwargs: Any) -> '
|
|
220
|
+
async def delete(self, url: str, **kwargs: Any) -> 'AsyncTestResponse':
|
|
221
221
|
return await self.request('DELETE', url, **kwargs)
|
|
222
222
|
|
|
223
|
-
async def patch(self, url: str, **kwargs: Any) -> '
|
|
223
|
+
async def patch(self, url: str, **kwargs: Any) -> 'AsyncTestResponse':
|
|
224
224
|
return await self.request('PATCH', url, **kwargs)
|
|
225
225
|
|
|
226
226
|
|
|
227
|
-
class
|
|
227
|
+
class AsyncTestResponse:
|
|
228
228
|
def __init__(self, response: httpx.Response):
|
|
229
229
|
self._response = response
|
|
230
230
|
|
|
@@ -237,7 +237,7 @@ class TestResponse:
|
|
|
237
237
|
def status_code(self) -> int:
|
|
238
238
|
return self._response.status_code
|
|
239
239
|
|
|
240
|
-
async def expect_status(self, status_code: int) -> '
|
|
240
|
+
async def expect_status(self, status_code: int) -> 'AsyncTestResponse':
|
|
241
241
|
assert self._response.status_code == status_code, \
|
|
242
242
|
f"Expected status {status_code}, got {self._response.status_code}"
|
|
243
243
|
return self
|
|
@@ -246,9 +246,9 @@ class TestResponse:
|
|
|
246
246
|
@asynccontextmanager
|
|
247
247
|
async def create_test_server(
|
|
248
248
|
lifespan: Optional[Lifespan[AppType]] = None,
|
|
249
|
-
) -> AsyncGenerator[
|
|
249
|
+
) -> AsyncGenerator[AsyncTestServer, None]:
|
|
250
250
|
"""Create and manage a TestServer instance with proper lifecycle"""
|
|
251
|
-
server =
|
|
251
|
+
server = AsyncTestServer(lifespan=lifespan)
|
|
252
252
|
try:
|
|
253
253
|
await server.start()
|
|
254
254
|
yield server
|
|
File without changes
|
|
File without changes
|