56 lines
1.6 KiB
Python
56 lines
1.6 KiB
Python
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
_backend = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(_backend))
|
|
_root = _backend.parent / "Temp" / "pytest"
|
|
_root.mkdir(parents=True, exist_ok=True)
|
|
os.environ["EUNIV_SECRET_KEY"] = "test-secret-key-0123456789abcdef"
|
|
os.environ["EUNIV_DB_PATH"] = str(_root / f"euniv-{os.getpid()}.db")
|
|
os.environ["EUNIV_DISABLE_REFRESH"] = "1"
|
|
os.environ["EUNIV_ADMIN_PASSWORD"] = "test-admin-pass"
|
|
os.environ["EUNIV_COOKIE_SECURE"] = "0"
|
|
os.environ.pop("EUNIV_ADMIN_RESET", None)
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def fresh_database():
|
|
from sqlalchemy import text
|
|
|
|
from admin.settings import ensure_admin_seed, ensure_key_check, load_admin_identity
|
|
from euniv.db import engine, init_db
|
|
from euniv.models import Base
|
|
import admin.models # noqa: F401
|
|
|
|
Base.metadata.drop_all(bind=engine)
|
|
with engine.begin() as connection:
|
|
connection.execute(text("DROP TABLE IF EXISTS alembic_version"))
|
|
init_db()
|
|
ensure_admin_seed()
|
|
ensure_key_check()
|
|
load_admin_identity()
|
|
from admin.login_limit import reset
|
|
|
|
reset()
|
|
from euniv.login_limit import reset as reset_login
|
|
|
|
reset_login()
|
|
from euniv.proxy_pool import _holds
|
|
|
|
_holds.clear()
|
|
from euniv import autostudy as autostudy_mod
|
|
|
|
autostudy_mod._wanted.clear()
|
|
autostudy_mod._running.clear()
|
|
autostudy_mod._retry_at.clear()
|
|
autostudy_mod._retry_count.clear()
|
|
autostudy_mod._done_month.clear()
|
|
autostudy_mod._targets.clear()
|
|
autostudy_mod._user_halts.clear()
|
|
users = autostudy_mod._status.get("users")
|
|
if isinstance(users, dict):
|
|
users.clear()
|