41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
import os
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
from wisegrade.config import get_settings
|
|
from wisegrade.db import Base, engine_for
|
|
from wisegrade.seed import seed_initial
|
|
from wisegrade import models # noqa: F401
|
|
|
|
|
|
@pytest.fixture
|
|
def environment(tmp_path, monkeypatch):
|
|
inbox = tmp_path / "inbox"
|
|
inbox.mkdir()
|
|
monkeypatch.setenv("INBOX_PATH", str(inbox))
|
|
monkeypatch.setenv("PROCESSED_PATH", str(tmp_path / "processed"))
|
|
monkeypatch.setenv("EXPORTS_PATH", str(tmp_path / "exports"))
|
|
monkeypatch.setenv("WISEGRADE_SECRET_KEY", "test-only-secret-key-of-at-least-32-characters")
|
|
get_settings.cache_clear()
|
|
yield tmp_path
|
|
get_settings.cache_clear()
|
|
|
|
|
|
@pytest.fixture
|
|
def session_factory(environment):
|
|
engine = engine_for(f"sqlite:///{environment / 'test.db'}")
|
|
Base.metadata.create_all(engine)
|
|
factory = sessionmaker(bind=engine, expire_on_commit=False)
|
|
with factory() as db:
|
|
seed_initial(db)
|
|
yield factory
|
|
engine.dispose()
|
|
|
|
|
|
@pytest.fixture
|
|
def db(session_factory):
|
|
with session_factory() as session:
|
|
yield session
|