"""loomio — create a discussion and read its body back through the public API. Loomio's core object is a discussion. This creates a user + open group + public discussion through the app's Rails console (`DiscussionService.create`, the same service the API controller calls), then reads the discussion back ANONYMOUSLY at `GET /api/v1/discussions/`, asserting the title and the unique body marker survive. Non-vacuous: it exercises the discussion write path (privacy validation against the group, author assignment, event publication) and the anonymous visibility rule (`DiscussionQuery.visible_to` includes public discussions). A read-back of a different path means a stale/echoed setup cannot pass. """ from __future__ import annotations import os import sys sys.path.insert(0, os.path.dirname(__file__)) sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "..", "runner")) import _loomio # noqa: E402 from harness import http as harness_http # noqa: E402 def test_public_discussion_roundtrip(live_app): _group_key, discussion_key = _loomio.ensure_discussion(live_app) url = f"https://{live_app}/api/v1/discussions/{discussion_key}" status, body = harness_http.retry_http_get(url, expect_status=200, max_wait=60, interval=3) assert status == 200, f"anonymous GET {url} HTTP {status} (public discussion not readable)" discussion = _loomio.unwrap(body, "discussions") assert discussion.get("title") == _loomio.DISCUSSION_TITLE, ( f"discussion title did not round-trip: sent {_loomio.DISCUSSION_TITLE!r}, " f"got {discussion.get('title')!r}" ) assert _loomio.DISCUSSION_MARKER in str(discussion.get("description")), ( f"discussion body marker missing: sent {_loomio.DISCUSSION_MARKER!r}, " f"got {discussion.get('description')!r}" )