167 lines
5.4 KiB
Python
Raw Normal View History

# retoor <retoor@molodetz.nl>
import io
import uuid
import requests
from PIL import Image
from tests.conftest import BASE_URL
from devplacepy.database import get_table
JSON_media = {"Accept": "application/json"}
def _png_bytes_media(color=(200, 30, 30)):
buf = io.BytesIO()
Image.new("RGB", (8, 8), color).save(buf, "PNG")
return buf.getvalue()
def _signup_media(prefix="media"):
s = requests.Session()
name = f"{prefix}_{uuid.uuid4().hex[:10]}"
s.post(
f"{BASE_URL}/auth/signup",
data={
"username": name,
"email": f"{name}@test.devplace",
"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,
)
return s, name
def _login_media(seeded_db, who):
s = requests.Session()
creds = seeded_db[who]
s.post(
f"{BASE_URL}/auth/login",
data={"email": creds["email"], "password": creds["password"]},
allow_redirects=True,
)
return s
def _upload_media(s, name="pic.png", content=None, mime="image/png"):
files = {"file": (name, content if content is not None else _png_bytes_media(), mime)}
r = s.post(f"{BASE_URL}/uploads/upload", files=files)
assert r.status_code == 201, r.text
return r.json()["uid"]
def _create_post_media(s, attachment_uids, title="media post"):
r = s.post(
f"{BASE_URL}/posts/create",
data={
"content": "A post that carries media for the gallery tests.",
"title": title,
"topic": "random",
"attachment_uids": attachment_uids,
},
allow_redirects=True,
)
assert r.status_code == 200, r.text[:300]
assert "/posts/" in r.url, r.url
return r.url
def _create_project_media(s, attachment_uids, title="Media Project"):
r = s.post(
f"{BASE_URL}/projects/create",
data={
"title": title,
"description": "Project with media for gallery tests.",
"project_type": "software",
"platforms": "linux",
"status": "In Development",
"attachment_uids": attachment_uids,
},
allow_redirects=True,
)
assert r.status_code == 200, r.text[:300]
assert "/projects/" in r.url, r.url
return r.url
def _media_json(session, username):
r = session.get(f"{BASE_URL}/profile/{username}?tab=media", headers=JSON_media)
assert r.status_code == 200, r.text[:300]
return r.json()
def _media_uids(session, username):
return [m["uid"] for m in _media_json(session, username)["media"]]
def _seed_media_via_browser(page, title="ui media"):
up = page.request.post(
f"{BASE_URL}/uploads/upload",
multipart={
"file": {
"name": "pic.png",
"mimeType": "image/png",
"buffer": _png_bytes_media(),
}
},
)
assert up.ok, up.text()
uid = up.json()["uid"]
post = page.request.post(
f"{BASE_URL}/posts/create",
form={
"content": "media for the ui gallery test",
"title": title,
"topic": "random",
"attachment_uids": uid,
},
)
assert post.ok, post.text()
return uid
def _media_uids_via_page(page, username):
resp = page.request.get(f"{BASE_URL}/profile/{username}?tab=media", headers=JSON_media)
return [m["uid"] for m in resp.json()["media"]]
def test_media_tab_lists_linked_attachment(app_server):
s, name = _signup_media()
uid = _upload_media(s)
_create_post_media(s, uid)
data = _media_json(s, name)
uids = [m["uid"] for m in data["media"]]
assert uid in uids
item = next(m for m in data["media"] if m["uid"] == uid)
assert item["is_image"] is True
assert item["target_type"] == "post"
assert item["target_url"].startswith("/posts/")
def test_media_tab_is_public(app_server):
owner, name = _signup_media()
uid = _upload_media(owner)
_create_post_media(owner, uid)
# an anonymous visitor can browse the gallery
anon = requests.Session()
assert uid in _media_uids(anon, name)
def test_orphan_upload_not_listed(app_server):
s, name = _signup_media()
uid = _upload_media(s) # uploaded but never linked to any content
assert uid not in _media_uids(s, name)
def test_media_newest_first(app_server):
s, name = _signup_media()
first = _upload_media(s)
_create_post_media(s, first, title="older")
second = _upload_media(s)
_create_post_media(s, second, title="newer")
uids = _media_uids(s, name)
assert uids.index(second) < uids.index(first)
def test_media_covers_multiple_target_types(app_server):
s, name = _signup_media()
post_att = _upload_media(s)
_create_post_media(s, post_att)
project_att = _upload_media(s)
_create_project_media(s, project_att)
items = {m["uid"]: m for m in _media_json(s, name)["media"]}
assert items[post_att]["target_type"] == "post"
assert items[project_att]["target_type"] == "project"
def test_media_json_omits_deleted_at(app_server):
# Members must never be shown the soft-delete column.
s, name = _signup_media()
uid = _upload_media(s)
_create_post_media(s, uid)
data = _media_json(s, name)
assert data["media"], "expected at least one media item"
for item in data["media"]:
assert "deleted_at" not in item