-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make data in ./run_local.sh persistent across reloads and support par…
…ameter DBs
- Loading branch information
Showing
4 changed files
with
61 additions
and
19 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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from __future__ import annotations | ||
|
||
from contextlib import asynccontextmanager | ||
from functools import partial | ||
|
||
from diracx.testing.mock_osdb import fake_available_osdb_implementations | ||
|
||
|
||
@asynccontextmanager | ||
async def ensure_dbs_exist(): | ||
from diracx.db.__main__ import init_os, init_sql | ||
|
||
await init_sql() | ||
await init_os() | ||
yield | ||
|
||
|
||
def create_app(): | ||
"""Create a FastAPI application for testing purposes. | ||
This is a wrapper around diracx.routers.create_app that: | ||
* adds a lifetime function to ensure the DB schemas are initialized | ||
* replaces the parameter DBs with sqlite-backed versions | ||
""" | ||
from diracx.db.os.utils import BaseOSDB | ||
from diracx.routers import create_app | ||
|
||
BaseOSDB.available_implementations = partial( | ||
fake_available_osdb_implementations, | ||
real_available_implementations=BaseOSDB.available_implementations, | ||
) | ||
|
||
app = create_app() | ||
app.lifetime_functions.append(ensure_dbs_exist) | ||
|
||
return app |
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