-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Aisuko <[email protected]>
- Loading branch information
Showing
2 changed files
with
68 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,34 @@ | ||
import asgi_lifespan | ||
import fastapi | ||
import httpx | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
|
||
from src.main import initialize_backend_application | ||
from src.main import app | ||
|
||
client=TestClient(app) | ||
|
||
@pytest.fixture(name="backend_test_app") | ||
def backend_test_app() -> fastapi.FastAPI: | ||
""" | ||
A fixture that re-initializes the FastAPI instance for test application. | ||
""" | ||
# TODO more specific test cases for each endpoint | ||
def test_chat(): | ||
response = client.get("/api/models") | ||
assert response.status_code == 200 | ||
|
||
return initialize_backend_application() | ||
# @pytest.fixture(name="backend_test_app") | ||
# def backend_test_app() -> fastapi.FastAPI: | ||
# """ | ||
# A fixture that re-initializes the FastAPI instance for test application. | ||
# """ | ||
|
||
# return initialize_backend_application() | ||
|
||
@pytest.fixture(name="initialize_backend_test_application") | ||
async def initialize_backend_test_application(backend_test_app: fastapi.FastAPI) -> fastapi.FastAPI: # type: ignore | ||
async with asgi_lifespan.LifespanManager(backend_test_app): | ||
yield backend_test_app | ||
|
||
# @pytest.fixture(name="initialize_backend_test_application") | ||
# async def initialize_backend_test_application(backend_test_app: fastapi.FastAPI) -> fastapi.FastAPI: # type: ignore | ||
# async with asgi_lifespan.LifespanManager(backend_test_app): | ||
# yield backend_test_app | ||
|
||
@pytest.fixture(name="async_client") | ||
async def async_client(initialize_backend_test_application: fastapi.FastAPI) -> httpx.AsyncClient: # type: ignore | ||
async with httpx.AsyncClient( | ||
app=initialize_backend_test_application, | ||
base_url="http://testserver", | ||
headers={"Content-Type": "application/json"}, | ||
) as client: | ||
yield client | ||
|
||
# @pytest.fixture(name="async_client") | ||
# async def async_client(initialize_backend_test_application: fastapi.FastAPI) -> httpx.AsyncClient: # type: ignore | ||
# async with httpx.AsyncClient( | ||
# app=initialize_backend_test_application, | ||
# base_url="http://testserver", | ||
# headers={"Content-Type": "application/json"}, | ||
# ) as client: | ||
# yield client |