kink-discovery / tests /test_dev_reset_local.py
Perplexed7675's picture
Sync from kink_cli (Docker Space)
6ff91d6 verified
Raw
History Blame Contribute Delete
1.26 kB
"""Smoke test for scripts/dev_reset_local.py DB wipe (no port kill)."""
from __future__ import annotations
import os
import subprocess
import sys
from pathlib import Path
import pytest
from sqlmodel import Session, select
from backend.core import Backend
from models import User
REPO_ROOT = Path(__file__).resolve().parents[1]
@pytest.mark.parametrize("dry_run", [True, False])
def test_dev_reset_local_script_wipes_users(tmp_path: Path, dry_run: bool) -> None:
os.environ["KINK_SKIP_HEAVY_WARM"] = "1"
db = tmp_path / "reset.db"
b = Backend(db)
b.create_user()
b.create_user()
with Session(b.engine) as session:
assert len(session.exec(select(User)).all()) == 2
cmd = [
sys.executable,
str(REPO_ROOT / "scripts" / "dev_reset_local.py"),
"--db",
str(db),
"--skip-port-kill",
]
if dry_run:
cmd.append("--dry-run")
else:
cmd.append("--i-am-sure")
r = subprocess.run(cmd, cwd=str(REPO_ROOT), capture_output=True, text=True)
assert r.returncode == 0, r.stderr + r.stdout
with Session(b.engine) as session:
rows = session.exec(select(User)).all()
if dry_run:
assert len(rows) == 2
else:
assert len(rows) == 0