101 lines
2.7 KiB
Python
Raw Normal View History

# retoor <retoor@molodetz.nl>
import time
import pytest
import requests
from tests.conftest import BASE_URL
from devplacepy.database import (
create_deepsearch_session,
get_table,
refresh_snapshot,
set_setting,
)
from devplacepy.services.jobs import queue
JSON = {"Accept": "application/json"}
_counter_ds = [0]
@pytest.fixture(scope="module", autouse=True)
def _settings(app_server):
set_setting("rate_limit_per_minute", "1000000")
set_setting("registration_open", "1")
yield
def _user():
_counter_ds[0] += 1
name = f"dsc{int(time.time() * 1000)}{_counter_ds[0]}"
requests.post(
f"{BASE_URL}/auth/signup",
data={
"username": name,
"email": f"{name}@t.dev",
"password": "secret123",
"confirm_password": "secret123",
Add the trust and safety subsystem and the App Store compliance work Implements the moderation and consent obligations a social platform carries, so the web version and any client that speaks to it enforce the same rules. Moderation core (services/moderation/, database/moderation.py): a reportable target registry, the content filter and its choke points, the report queue with atomic resolution, enforcement actions, consent tracking, maturity gating, and account deletion with a grace window. Surfaces: POST /reports plus the member report list, /admin/moderation and the per-report admin view, /workspaces, terms acceptance at /auth/terms, consent and account deletion under /profile, the report button and dialog partials, the maturity gate, and the moderation stylesheet and ReportDialog client. Every user-generated surface stays reportable by construction: new content tables are registered in REPORTABLE_TARGETS or listed in UNREPORTABLE_TABLES with a reason, and the registry test fails the suite on anything left unclassified. Docs: community guidelines, content moderation, intellectual property, privacy, terms, contact, and the admin-only moderation operations page, plus the moderation API group and the Devii moderation actions. Compliance record: applecomp.md is the requirement register, applechanges.md the gap analysis against this codebase, and appleimpl.md the implementation design they resolve to. Tests cover the report flow, admin moderation, consent, account deletion, terms acceptance, workspaces, and the registry invariant across the unit, api, and e2e tiers.
2026-08-09 00:18:20 +02:00
"birth_date": "1990-01-01",
"accept_terms": "1",
},
allow_redirects=True,
)
refresh_snapshot()
user = get_table("users").find_one(username=name)
return user["uid"], user["api_key"]
def _seed_session(owner_id, with_session=True):
uid = queue.enqueue(
"deepsearch",
{"query": "q", "depth": 1, "max_pages": 5},
"user",
owner_id,
"DeepSearch",
)
if with_session:
create_deepsearch_session(
uid, "user", owner_id, "q", 1, 5, f"ds_{uid.replace('-', '')}"
)
refresh_snapshot()
return uid
def test_pause_resume_cancel_owner(app_server):
uid_owner, key = _user()
uid = _seed_session(uid_owner)
h = {"X-API-KEY": key, **JSON}
for action, state in (("pause", "paused"), ("resume", "running"), ("cancel", "cancelled")):
r = requests.post(f"{BASE_URL}/tools/deepsearch/{uid}/{action}", headers=h)
assert r.status_code == 200, f"{action}: {r.text[:200]}"
assert r.json()["ok"] is True
assert r.json()["state"] == state
def test_control_non_owner_forbidden(app_server):
owner_uid, _ = _user()
_, other_key = _user()
uid = _seed_session(owner_uid)
r = requests.post(
f"{BASE_URL}/tools/deepsearch/{uid}/pause",
headers={"X-API-KEY": other_key, **JSON},
)
assert r.status_code == 403
def test_control_unknown_uid_404(app_server):
_, key = _user()
r = requests.post(
f"{BASE_URL}/tools/deepsearch/no-such-uid/pause",
headers={"X-API-KEY": key, **JSON},
)
assert r.status_code == 404
def test_control_job_without_session_404(app_server):
owner_uid, key = _user()
uid = _seed_session(owner_uid, with_session=False)
r = requests.post(
f"{BASE_URL}/tools/deepsearch/{uid}/pause",
headers={"X-API-KEY": key, **JSON},
)
assert r.status_code == 404