2026-07-31 20:23:10 +00:00
|
|
|
"""``roboco/api/schemas/x.py`` response-builder wiring for project_slug/
|
2026-07-18 19:11:03 +02:00
|
|
|
project_name. The sa_inspect(task).unloaded guard branches themselves are
|
|
|
|
|
covered once on the shared helper in tests/unit/api/schemas/test_project_fields.py
|
2026-07-31 20:23:10 +00:00
|
|
|
— this only asserts task_to_post_response/task_to_post_history_response
|
|
|
|
|
actually populate the response from it (loaded case; a real ORM task always
|
|
|
|
|
resolves the "loaded" branch since ``project`` is lazy="joined")."""
|
2026-07-18 19:11:03 +02:00
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from types import SimpleNamespace
|
|
|
|
|
from typing import Any
|
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
|
|
2026-07-31 20:23:10 +00:00
|
|
|
from roboco.api.schemas.x import task_to_post_history_response, task_to_post_response
|
2026-07-18 19:11:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def _stub_task(*, with_project: bool = False) -> Any:
|
2026-07-31 20:23:10 +00:00
|
|
|
"""A TaskTable stand-in matching the response builders' reads."""
|
2026-07-18 19:11:03 +02:00
|
|
|
return SimpleNamespace(
|
|
|
|
|
id="task-1",
|
|
|
|
|
source="x_post",
|
|
|
|
|
title="X post: release v1.0.0",
|
|
|
|
|
status="pending",
|
|
|
|
|
description="",
|
|
|
|
|
orchestration_markers=None,
|
|
|
|
|
project=(
|
|
|
|
|
SimpleNamespace(slug="acme-robotics", name="Acme Robotics")
|
|
|
|
|
if with_project
|
|
|
|
|
else None
|
|
|
|
|
),
|
|
|
|
|
updated_at=None,
|
|
|
|
|
created_at="2026-07-18T00:00:00+00:00",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _loaded_inspector() -> MagicMock:
|
|
|
|
|
inspector = MagicMock()
|
|
|
|
|
inspector.unloaded = set()
|
|
|
|
|
return inspector
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_to_response_includes_project_fields_when_loaded() -> None:
|
|
|
|
|
with patch(
|
|
|
|
|
"roboco.api.schemas.project_fields.sa_inspect",
|
|
|
|
|
return_value=_loaded_inspector(),
|
|
|
|
|
):
|
2026-07-31 20:23:10 +00:00
|
|
|
resp = task_to_post_response(_stub_task(with_project=True))
|
2026-07-18 19:11:03 +02:00
|
|
|
assert resp.project_slug == "acme-robotics"
|
|
|
|
|
assert resp.project_name == "Acme Robotics"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_to_response_omits_project_fields_when_project_unset() -> None:
|
|
|
|
|
with patch(
|
|
|
|
|
"roboco.api.schemas.project_fields.sa_inspect",
|
|
|
|
|
return_value=_loaded_inspector(),
|
|
|
|
|
):
|
2026-07-31 20:23:10 +00:00
|
|
|
resp = task_to_post_response(_stub_task(with_project=False))
|
2026-07-18 19:11:03 +02:00
|
|
|
assert resp.project_slug is None
|
|
|
|
|
assert resp.project_name is None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_to_history_response_includes_project_fields_when_loaded() -> None:
|
|
|
|
|
with patch(
|
|
|
|
|
"roboco.api.schemas.project_fields.sa_inspect",
|
|
|
|
|
return_value=_loaded_inspector(),
|
|
|
|
|
):
|
2026-07-31 20:23:10 +00:00
|
|
|
resp = task_to_post_history_response(_stub_task(with_project=True))
|
2026-07-18 19:11:03 +02:00
|
|
|
assert resp.project_slug == "acme-robotics"
|
|
|
|
|
assert resp.project_name == "Acme Robotics"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_to_history_response_omits_project_fields_when_project_unset() -> None:
|
|
|
|
|
with patch(
|
|
|
|
|
"roboco.api.schemas.project_fields.sa_inspect",
|
|
|
|
|
return_value=_loaded_inspector(),
|
|
|
|
|
):
|
2026-07-31 20:23:10 +00:00
|
|
|
resp = task_to_post_history_response(_stub_task(with_project=False))
|
2026-07-18 19:11:03 +02:00
|
|
|
assert resp.project_slug is None
|
|
|
|
|
assert resp.project_name is None
|