CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 8s
CI & Build / integration (push) Successful in 24s
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / Python tests (push) Successful in 54s
CI & Build / Build & push image (push) Successful in 18s
The shape ledger showed the same test scaffolding defined over and over: _bind_user x12 (byte-identical), _dispose_engine x10 in three wordings, _no_supersession x3, _make_mock_session x7 in three subsets, a get-or-create User helper x2 (+3 inlined), and fifteen hand-rolled MagicMock note factories each re-explaining the same "an auto-MagicMock attribute is truthy" hazard (note 2109). Now: conftest.py carries _bind_user / _dispose_engine / _no_supersession as opt-in fixtures (pytestmark = usefixtures(...) per module, so unit tests pay nothing), and tests/helpers.py carries make_mock_session(), ensure_user() and fake_note(**attrs) — the hazard documented once, real values on every attribute the product reads. Call sites were rewritten by AST so titles with dashes and commas survived; the three SimpleNamespace _note stand-ins that only feed a single function stay local. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
"""task_kind create + list-filter behavior in services/notes.py."""
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
|
|
|
import pytest
|
|
from tests.helpers import make_mock_session
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_note_passes_task_kind_to_model():
|
|
mock_session = make_mock_session()
|
|
captured = {}
|
|
|
|
def _capture_add(obj):
|
|
captured["task_kind"] = getattr(obj, "task_kind", "MISSING")
|
|
|
|
mock_session.add = MagicMock(side_effect=_capture_add)
|
|
with patch("scribe.services.notes.async_session") as mock_cls, \
|
|
patch("scribe.services.notes._maybe_reactivate_project", AsyncMock()):
|
|
mock_cls.return_value = mock_session
|
|
from scribe.services.notes import create_note
|
|
await create_note(user_id=1, title="P", status="todo", task_kind="plan")
|
|
assert captured["task_kind"] == "plan"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_notes_filters_by_task_kind():
|
|
mock_session = make_mock_session()
|
|
mock_session.scalar = AsyncMock(return_value=0)
|
|
exec_result = MagicMock()
|
|
exec_result.scalars.return_value.all.return_value = []
|
|
mock_session.execute = AsyncMock(return_value=exec_result)
|
|
with patch("scribe.services.notes.async_session") as mock_cls:
|
|
mock_cls.return_value = mock_session
|
|
from scribe.services.notes import list_notes
|
|
# Should not raise; task_kind is a recognized kwarg.
|
|
rows, total = await list_notes(user_id=1, is_task=True, task_kind="plan")
|
|
assert rows == []
|
|
assert total == 0
|