mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-11-04 03:28:28 -05:00 
			
		
		
		
	* upgrade sqlalchemy to 2.0 * rewrite all db models to sqla 2.0 mapping api * fix some importing and typing weirdness * fix types of a lot of nullable columns * remove get_ref methods * fix issues found by tests * rewrite all queries in repository_recipe to 2.0 style * rewrite all repository queries to 2.0 api * rewrite all remaining queries to 2.0 api * remove now-unneeded __allow_unmapped__ flag * remove and fix some unneeded cases of "# type: ignore" * fix formatting * bump black version * run black * can this please be the last one. okay. just. okay. * fix repository errors * remove return * drop open API validator --------- Co-authored-by: Sören Busch <fleshgolem@gmx.net>
		
			
				
	
	
		
			63 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			63 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
import contextlib
 | 
						|
from collections.abc import Generator
 | 
						|
 | 
						|
from pytest import MonkeyPatch, fixture
 | 
						|
 | 
						|
mp = MonkeyPatch()
 | 
						|
mp.setenv("PRODUCTION", "True")
 | 
						|
mp.setenv("TESTING", "True")
 | 
						|
from pathlib import Path
 | 
						|
 | 
						|
from fastapi.testclient import TestClient
 | 
						|
 | 
						|
from mealie.app import app
 | 
						|
from mealie.core import config
 | 
						|
from mealie.db.db_setup import SessionLocal, generate_session
 | 
						|
from mealie.db.init_db import main
 | 
						|
from tests import data as test_data
 | 
						|
from tests.fixtures import *  # noqa: F403 F401
 | 
						|
 | 
						|
main()
 | 
						|
 | 
						|
 | 
						|
def override_get_db():
 | 
						|
    try:
 | 
						|
        db = SessionLocal()
 | 
						|
        yield db
 | 
						|
    finally:
 | 
						|
        db.close()
 | 
						|
 | 
						|
 | 
						|
@fixture(scope="session")
 | 
						|
def api_client():
 | 
						|
    app.dependency_overrides[generate_session] = override_get_db
 | 
						|
 | 
						|
    yield TestClient(app)
 | 
						|
 | 
						|
    with contextlib.suppress(Exception):
 | 
						|
        settings = config.get_app_settings()
 | 
						|
        settings.DB_PROVIDER.db_path.unlink()  # Handle SQLite Provider
 | 
						|
 | 
						|
 | 
						|
@fixture(scope="session")
 | 
						|
def test_image_jpg():
 | 
						|
    return test_data.images_test_image_1
 | 
						|
 | 
						|
 | 
						|
@fixture(scope="session")
 | 
						|
def test_image_png():
 | 
						|
    return test_data.images_test_image_2
 | 
						|
 | 
						|
 | 
						|
@fixture(scope="session", autouse=True)
 | 
						|
def global_cleanup() -> Generator[None, None, None]:
 | 
						|
    """Purges the .temp directory used for testing"""
 | 
						|
    yield None
 | 
						|
    with contextlib.suppress(Exception):
 | 
						|
        temp_dir = Path(__file__).parent / ".temp"
 | 
						|
 | 
						|
        if temp_dir.exists():
 | 
						|
            import shutil
 | 
						|
 | 
						|
            shutil.rmtree(temp_dir, ignore_errors=True)
 |