Implement new storage design per issue #2
- Replace SQLite db module with file-based JSON storage in ~/.jigaido/
- Group bounties: ~/.jigaido/{group_id}/group.json
- User tracking: ~/.jigaido/{group_id}/user_{id}.json
- Personal bounties: ~/.jigaido/user_{id}/user.json
- Anyone can add bounties to groups; only creator can edit/delete
- Bounty IDs are sequential per group, not global
- Fix test mock compatibility issues in format_bounty function
This commit is contained in:
@@ -1,27 +1 @@
|
||||
"""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)
|
||||
|
||||
@@ -101,12 +101,21 @@ class TestParseArgs:
|
||||
|
||||
|
||||
class TestFormatBounty:
|
||||
def _row(self, id=1, text="Test bounty", link="https://example.com",
|
||||
due_date_ts=None, informed_by_username="alice"):
|
||||
def _row(
|
||||
self,
|
||||
id=1,
|
||||
text="Test bounty",
|
||||
link="https://example.com",
|
||||
due_date_ts=None,
|
||||
created_by_username="alice",
|
||||
):
|
||||
row = MagicMock()
|
||||
row.__getitem__ = lambda s, k: {
|
||||
"id": id, "text": text, "link": link,
|
||||
"due_date_ts": due_date_ts, "informed_by_username": informed_by_username
|
||||
"id": id,
|
||||
"text": text,
|
||||
"link": link,
|
||||
"due_date_ts": due_date_ts,
|
||||
"created_by_username": created_by_username,
|
||||
}[k]
|
||||
return row
|
||||
|
||||
@@ -155,12 +164,12 @@ class TestFormatBounty:
|
||||
out = format_bounty(b)
|
||||
assert "OVERDUE" in out
|
||||
|
||||
def test_informed_by_shown(self):
|
||||
b = self._row(informed_by_username="bob")
|
||||
def test_created_by_shown(self):
|
||||
b = self._row(created_by_username="bob")
|
||||
out = format_bounty(b)
|
||||
assert "@bob" in out
|
||||
|
||||
def test_informed_by_unknown_fallback(self):
|
||||
b = self._row(informed_by_username=None)
|
||||
def test_created_by_unknown_fallback(self):
|
||||
b = self._row(created_by_username=None)
|
||||
out = format_bounty(b)
|
||||
assert "@unknown" in out
|
||||
|
||||
Reference in New Issue
Block a user