157 lines
4.8 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 get_table, refresh_snapshot, set_setting
JSON = {"Accept": "application/json"}
_counter_bs = [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 _admin(seeded_db):
refresh_snapshot()
key = get_table("users").find_one(username="alice_test")["api_key"]
s = requests.Session()
s.headers.update({"X-API-KEY": key, **JSON})
return s
def _member():
_counter_bs[0] += 1
name = f"bsmem{int(time.time() * 1000)}{_counter_bs[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()
s = requests.Session()
s.headers.update(
{"X-API-KEY": get_table("users").find_one(username=name)["api_key"], **JSON}
)
return s
def _name():
_counter_bs[0] += 1
return f"sched{int(time.time() * 1000)}{_counter_bs[0]}"
def _create(admin, name, **extra):
payload = {"name": name, "target": "database", "kind": "interval", "every_seconds": "3600"}
payload.update(extra)
r = admin.post(f"{BASE_URL}/admin/backups/schedules/create", data=payload)
assert r.status_code in (200, 302), r.text[:200]
refresh_snapshot()
return get_table("backup_schedules").find_one(name=name, deleted_at=None)
def test_create_schedule(seeded_db):
admin = _admin(seeded_db)
name = _name()
row = _create(admin, name)
assert row is not None
assert row["target"] == "database"
assert row["deleted_at"] is None
def test_create_cron_without_expression_rejected(seeded_db):
admin = _admin(seeded_db)
r = admin.post(
f"{BASE_URL}/admin/backups/schedules/create",
data={"name": _name(), "target": "full", "kind": "cron", "cron": ""},
)
assert r.status_code == 422
def test_toggle_schedule(seeded_db):
admin = _admin(seeded_db)
row = _create(admin, _name())
before = int(row.get("enabled") or 0)
r = admin.post(f"{BASE_URL}/admin/backups/schedules/{row['uid']}/toggle")
assert r.status_code in (200, 302)
refresh_snapshot()
after = int(get_table("backup_schedules").find_one(uid=row["uid"])["enabled"] or 0)
assert after != before
def test_edit_schedule(seeded_db):
admin = _admin(seeded_db)
row = _create(admin, _name())
new_name = _name()
r = admin.post(
f"{BASE_URL}/admin/backups/schedules/{row['uid']}/edit",
data={"name": new_name, "target": "uploads", "kind": "interval", "every_seconds": "7200"},
)
assert r.status_code in (200, 302)
refresh_snapshot()
updated = get_table("backup_schedules").find_one(uid=row["uid"])
assert updated["name"] == new_name
assert updated["target"] == "uploads"
def test_run_schedule_enqueues_backup(seeded_db):
admin = _admin(seeded_db)
row = _create(admin, _name())
r = admin.post(f"{BASE_URL}/admin/backups/schedules/{row['uid']}/run")
assert r.status_code in (200, 302)
refresh_snapshot()
assert get_table("backups").count(schedule_uid=row["uid"]) >= 1
def test_delete_schedule(seeded_db):
admin = _admin(seeded_db)
row = _create(admin, _name())
r = admin.post(f"{BASE_URL}/admin/backups/schedules/{row['uid']}/delete")
assert r.status_code in (200, 302)
refresh_snapshot()
assert get_table("backup_schedules").find_one(uid=row["uid"], deleted_at=None) is None
def test_unknown_schedule_404(seeded_db):
admin = _admin(seeded_db)
for path in ("edit", "toggle", "run", "delete"):
if path == "edit":
r = admin.post(
f"{BASE_URL}/admin/backups/schedules/nope-uid/edit",
data={"name": "x", "target": "full", "kind": "interval"},
)
else:
r = admin.post(f"{BASE_URL}/admin/backups/schedules/nope-uid/{path}")
assert r.status_code == 404, f"{path}: {r.status_code}"
def test_member_cannot_create_schedule(app_server):
member = _member()
r = member.post(
f"{BASE_URL}/admin/backups/schedules/create",
data={"name": _name(), "target": "full", "kind": "interval"},
allow_redirects=False,
)
assert r.status_code in (302, 303, 403)
def test_guest_cannot_create_schedule(app_server):
r = requests.post(
f"{BASE_URL}/admin/backups/schedules/create",
data={"name": _name(), "target": "full", "kind": "interval"},
allow_redirects=False,
)
assert r.status_code in (302, 303, 401)