mealie/tests/conftest.py
Hayden ea7c4771ee
Feature/user photo storage (#877)
* add default assets for user profile

* add recipe avatar

* change user_id to UUID

* add profile image upload

* setup image cache keys

* cleanup tests and add image tests

* purge user data on delete

* new user repository tests

* add user_id validator for int -> UUID conversion

* delete depreciated route

* force set content type

* refactor tests to use temp directory

* validate parent exists before createing

* set user_id to correct type

* update instruction id

* reset primary key on migration
2021-12-18 19:04:36 -09:00

67 lines
1.3 KiB
Python

import os
os.environ["PRODUCTION"] = "True"
os.environ["TESTING"] = "True"
from pathlib import Path
from fastapi.testclient import TestClient
from pytest import fixture
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)
try:
settings = config.get_app_settings()
settings.DB_PROVIDER.db_path.unlink() # Handle SQLite Provider
except Exception:
pass
@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() -> None:
"""Purges the .temp directory used for testing"""
yield None
try:
temp_dir = Path(__file__).parent / ".temp"
if temp_dir.exists():
import shutil
shutil.rmtree(temp_dir, ignore_errors=True)
except Exception:
pass