kiwi/tests/services/community/test_community_store.py
pyr0ball c18bfec8f5
Some checks are pending
CI / Backend (Python) (push) Waiting to run
CI / Frontend (Vue) (push) Waiting to run
Mirror / mirror (push) Waiting to run
fix(lint): add ruff config, fix all lint errors for GitHub CI
- pyproject.toml: add [tool.ruff] config suppressing E402/W293 globally,
  F841/E741/E702 in tests, E741 in scripts
- inventory.py: split semicolon import (E702)
- recipes.py: fix logger -> log (F821 undefined name)
- shopping.py: rename l -> lnk in list comprehension (E741)
- format_conversion.py: noqa F841 on CUDA flag (used as future hook)
- backfill_keywords.py: rename done -> _done (F841)
- ingest_purplecarrot.py: drop == True comparison (E712)
- Auto-fix: I001 import sorting, F401 unused imports across all files
2026-07-06 02:49:02 -07:00

43 lines
1.5 KiB
Python

# tests/services/community/test_community_store.py
# MIT License
from unittest.mock import MagicMock, patch
from app.services.community.community_store import KiwiCommunityStore, get_or_create_pseudonym
def test_get_or_create_pseudonym_new_user():
"""First-time publish: creates a new pseudonym in per-user SQLite."""
mock_store = MagicMock()
mock_store.get_current_pseudonym.return_value = None
result = get_or_create_pseudonym(
store=mock_store,
directus_user_id="user-123",
requested_name="PastaWitch",
)
mock_store.set_pseudonym.assert_called_once_with("user-123", "PastaWitch")
assert result == "PastaWitch"
def test_get_or_create_pseudonym_existing():
"""If user already has a pseudonym, return it without creating a new one."""
mock_store = MagicMock()
mock_store.get_current_pseudonym.return_value = "PastaWitch"
result = get_or_create_pseudonym(
store=mock_store,
directus_user_id="user-123",
requested_name=None,
)
mock_store.set_pseudonym.assert_not_called()
assert result == "PastaWitch"
def test_kiwi_community_store_list_meal_plans():
"""KiwiCommunityStore.list_meal_plans filters by post_type='plan'."""
mock_db = MagicMock()
store = KiwiCommunityStore(mock_db)
with patch.object(store, "list_posts", return_value=[]) as mock_list:
result = store.list_meal_plans(limit=10)
mock_list.assert_called_once()
call_kwargs = mock_list.call_args.kwargs
assert call_kwargs.get("post_type") == "plan"