Add tests + fix db.py SQLite commit pattern
Tests: - tests/test_commands.py: parse_args, extract_args, format_bounty - tests/test_db.py: full CRUD + tracking + reminders - tests/conftest.py: temp DB fixture - requirements-dev.txt: pytest + pytest-asyncio db.py fixes: - Explicit conn.commit() after every write (SQLite row_factory disables implicit transaction management) - fetchone() before commit() (can't commit while cursor open) - Functions return dict instead of sqlite3.Row
This commit is contained in:
27
apps/telegram-bot/tests/conftest.py
Normal file
27
apps/telegram-bot/tests/conftest.py
Normal file
@@ -0,0 +1,27 @@
|
||||
"""Pytest fixtures for telegram-bot tests."""
|
||||
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
# Add the app directory to path so `import db` works when running pytest
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fresh_db(monkeypatch):
|
||||
"""Replace DB_PATH with a temp file before any test runs."""
|
||||
import db as _db
|
||||
|
||||
tmp = tempfile.NamedTemporaryFile(suffix=".db", delete=False)
|
||||
tmp_path = Path(tmp.name)
|
||||
tmp.close()
|
||||
|
||||
monkeypatch.setattr(_db, "DB_PATH", tmp_path)
|
||||
_db.init_db()
|
||||
|
||||
yield tmp_path
|
||||
|
||||
tmp_path.unlink(missing_ok=True)
|
||||
Reference in New Issue
Block a user