Files
roboco/tests/unit/api/schemas/test_project_fields.py
T
7e01c0cecf feat(marketing): project-branded drafts + project badges on the X/video queues (#570)
Item B+C of the video/X per-project targeting spec, plus the
company_goals.company_name field they depend on (migration 075).

- CompanyGoalsService.resolve_product_name is the single fallback chain
  (project name -> charter company_name -> RoboCo); XEngine and
  VideoEngine both call it and their prompt builders are pure functions
  taking product_name — release posts/videos stop hardcoding RoboCo.
- The X and video queue responses carry project_slug/project_name via one
  shared unloaded-guard helper (api/schemas/project_fields.py); both
  panel queues render a shared ProjectBadge so multi-project drafts are
  tellable apart.
- Business -> Goals editor gains the company-name input.
- Fixes a pre-existing test-isolation leak: the company-goals routes test
  commits the charter singleton into the session-scoped test DB and
  polluted later suites; it now deletes the row on teardown.

Co-authored-by: Renn F <rennf93@users.noreply.github.com>
2026-07-18 19:11:03 +02:00

53 lines
1.8 KiB
Python

"""``task_project_fields`` — the shared (project_slug, project_name)
response-builder helper the X and video routes' five builders all call.
Mirrors tests/unit/api/test_schemas_tasks.py's task_to_response project_slug
coverage for the same sa_inspect(task).unloaded guard convention."""
from __future__ import annotations
from types import SimpleNamespace
from typing import Any
from unittest.mock import MagicMock, patch
from roboco.api.schemas.project_fields import task_project_fields
def _stub_task(*, with_project: bool = False) -> Any:
return SimpleNamespace(
project=(
SimpleNamespace(slug="acme-robotics", name="Acme Robotics")
if with_project
else None
),
)
def test_omits_fields_when_project_unloaded() -> None:
stub = _stub_task(with_project=False)
fake_inspector = MagicMock()
fake_inspector.unloaded = {"project"}
with patch(
"roboco.api.schemas.project_fields.sa_inspect", return_value=fake_inspector
):
assert task_project_fields(stub) == (None, None)
def test_omits_fields_when_project_id_unset() -> None:
stub = _stub_task(with_project=False)
fake_inspector = MagicMock()
fake_inspector.unloaded = set() # loaded, but task.project is None
with patch(
"roboco.api.schemas.project_fields.sa_inspect", return_value=fake_inspector
):
assert task_project_fields(stub) == (None, None)
def test_returns_slug_and_name_when_loaded() -> None:
stub = _stub_task(with_project=True)
fake_inspector = MagicMock()
fake_inspector.unloaded = set()
with patch(
"roboco.api.schemas.project_fields.sa_inspect", return_value=fake_inspector
):
assert task_project_fields(stub) == ("acme-robotics", "Acme Robotics")