50 lines
1.1 KiB
Python
50 lines
1.1 KiB
Python
from typing import Any
|
|
from typing import Generator
|
|
|
|
import pytest
|
|
from fastapi import FastAPI
|
|
from fastapi.testclient import TestClient
|
|
from apis.base import api_router
|
|
from tortoise.contrib.fastapi import register_tortoise
|
|
|
|
|
|
TORTOISE_ORM = {
|
|
"connections": {"default": "sqlite://database/db.sqlite3"},
|
|
"apps": {
|
|
"models": {
|
|
"models": ["database.models", "aerich.models"],
|
|
"default_connection": "default",
|
|
},
|
|
},
|
|
}
|
|
|
|
def start_application():
|
|
app = FastAPI()
|
|
app.include_router(api_router)
|
|
|
|
return app
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def app() -> Generator[FastAPI, Any, None]:
|
|
_app = start_application()
|
|
register_tortoise(
|
|
app,
|
|
config=TORTOISE_ORM,
|
|
#db_url="sqlite://database/db.sqlite3",
|
|
modules={"models": ["database.models"]},
|
|
generate_schemas=True,
|
|
add_exception_handlers=True,
|
|
)
|
|
yield _app
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def client(
|
|
app: FastAPI
|
|
) -> Generator[TestClient, Any, None]:
|
|
with TestClient(app) as client:
|
|
yield client
|