fastapi-testing 0.1.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: fastapi-testing
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: A lightweight, async-first testing framework for FastAPI applications
5
5
  License: MIT
6
6
  Keywords: fastapi,testing,async,pytest,integration-testing,test-framework
@@ -20,11 +20,11 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
20
  Classifier: Topic :: Software Development :: Testing
21
21
  Classifier: Typing :: Typed
22
22
  Requires-Dist: fastapi (>=0.115.0,<0.116.0)
23
- Requires-Dist: httpx[http2] (>=0.28.1,<0.29.0)
23
+ Requires-Dist: httpx[http2] (>=0.23.0,<0.28.0)
24
24
  Requires-Dist: pydantic (>=2.10.6,<3.0.0)
25
25
  Requires-Dist: starlette (>=0.45.0,<0.46.0)
26
26
  Requires-Dist: uvicorn (>=0.34.0,<0.35.0)
27
- Project-URL: Documentation, https://github.com/descoped/fastapi-testing/tree/main/docs
27
+ Project-URL: Documentation, https://github.com/descoped/fastapi-testing/tree/master/docs
28
28
  Project-URL: Homepage, https://github.com/descoped/fastapi-testing
29
29
  Project-URL: Repository, https://github.com/descoped/fastapi-testing
30
30
  Description-Content-Type: text/x-rst
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "fastapi-testing"
3
- version = "0.1.0"
3
+ version = "0.2.0"
4
4
  description = "A lightweight, async-first testing framework for FastAPI applications"
5
5
  authors = ["Ove Ranheim <oranheim@gmail.com>"]
6
6
  readme = "docs/index.rst"
@@ -19,14 +19,14 @@ classifiers = [
19
19
  ]
20
20
  homepage = "https://github.com/descoped/fastapi-testing"
21
21
  repository = "https://github.com/descoped/fastapi-testing"
22
- documentation = "https://github.com/descoped/fastapi-testing/tree/main/docs"
22
+ documentation = "https://github.com/descoped/fastapi-testing/tree/master/docs"
23
23
  keywords = ["fastapi", "testing", "async", "pytest", "integration-testing", "test-framework"]
24
24
 
25
25
 
26
26
  [tool.poetry.dependencies]
27
27
  python = "^3.11"
28
28
  fastapi = "^0.115.0"
29
- httpx = { extras = ["http2"], version = "^0.28.1" }
29
+ httpx = { extras = ["http2"], version = ">=0.23.0,<0.28.0" }
30
30
  uvicorn = "^0.34.0"
31
31
  starlette = "^0.45.0"
32
32
  pydantic = "^2.10.6"
@@ -1,17 +1,17 @@
1
1
  from fastapi_testing.async_fastapi_testing import (
2
2
  PortGenerator,
3
3
  UvicornTestServer,
4
- TestServer,
5
- TestClient,
6
- TestResponse,
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
- "TestServer",
14
- "TestClient",
15
- "TestResponse",
13
+ "AsyncTestServer",
14
+ "AsyncTestClient",
15
+ "AsyncTestResponse",
16
16
  "create_test_server",
17
17
  ]
@@ -63,7 +63,7 @@ class UvicornTestServer(uvicorn.Server):
63
63
  self.startup_handler.set()
64
64
 
65
65
 
66
- class TestServer:
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[TestClient] = None
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 = TestClient(
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) -> 'TestServer':
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) -> 'TestClient':
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 TestClient:
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
- ) -> 'TestResponse':
207
+ ) -> 'AsyncTestResponse':
208
208
  response = await self._client.request(method, url, **kwargs)
209
- return TestResponse(response)
209
+ return AsyncTestResponse(response)
210
210
 
211
- async def get(self, url: str, **kwargs: Any) -> 'TestResponse':
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) -> 'TestResponse':
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) -> 'TestResponse':
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) -> 'TestResponse':
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) -> 'TestResponse':
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 TestResponse:
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) -> 'TestResponse':
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[TestServer, None]:
249
+ ) -> AsyncGenerator[AsyncTestServer, None]:
250
250
  """Create and manage a TestServer instance with proper lifecycle"""
251
- server = TestServer(lifespan=lifespan)
251
+ server = AsyncTestServer(lifespan=lifespan)
252
252
  try:
253
253
  await server.start()
254
254
  yield server
File without changes