mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 06:23:34 -07:00
monkeypatch test db
This commit is contained in:
parent
fd1bde76be
commit
d448d4453b
2 changed files with 11 additions and 11 deletions
|
@ -1,17 +1,11 @@
|
|||
from mealie.core.config import app_dirs, settings
|
||||
|
||||
# ! I don't like it either!
|
||||
DB_URL = app_dirs.DATA_DIR.joinpath("test.db")
|
||||
DB_URL.unlink(missing_ok=True)
|
||||
|
||||
settings.DB_URL = "sqlite:///" + str(DB_URL.absolute())
|
||||
from tests.pre_test import DB_URL, settings # isort:skip
|
||||
|
||||
import json
|
||||
|
||||
import requests
|
||||
from fastapi.testclient import TestClient
|
||||
from mealie.app import app
|
||||
from mealie.db.db_setup import generate_session, sql_global_init
|
||||
from mealie.db.db_setup import SessionLocal, generate_session
|
||||
from mealie.db.init_db import init_db
|
||||
from pytest import fixture
|
||||
|
||||
|
@ -19,13 +13,12 @@ from tests.app_routes import AppRoutes
|
|||
from tests.test_config import TEST_DATA
|
||||
from tests.utils.recipe_data import build_recipe_store, get_raw_no_image, get_raw_recipe
|
||||
|
||||
TestSessionLocal = sql_global_init(settings.DB_URL)
|
||||
init_db(TestSessionLocal())
|
||||
init_db(SessionLocal())
|
||||
|
||||
|
||||
def override_get_db():
|
||||
try:
|
||||
db = TestSessionLocal()
|
||||
db = SessionLocal()
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
|
7
tests/pre_test.py
Normal file
7
tests/pre_test.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from mealie.core.config import app_dirs, settings
|
||||
|
||||
# Monkeypatch Database Testing
|
||||
DB_URL = app_dirs.DATA_DIR.joinpath("test.db")
|
||||
DB_URL.unlink(missing_ok=True)
|
||||
|
||||
settings.DB_URL = "sqlite:///" + str(DB_URL.absolute())
|
Loading…
Add table
Add a link
Reference in a new issue