2026-06-13 16:32:33 +02:00
|
|
|
# retoor <retoor@molodetz.nl>
|
2026-06-05 20:34:03 +02:00
|
|
|
|
2026-06-13 16:32:33 +02:00
|
|
|
import time
|
2026-06-05 20:34:03 +02:00
|
|
|
import requests
|
|
|
|
|
from tests.conftest import BASE_URL
|
2026-06-13 16:32:33 +02:00
|
|
|
def _session_validation():
|
|
|
|
|
s = requests.Session()
|
|
|
|
|
name = f"val_{int(time.time() * 1000)}"
|
|
|
|
|
s.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",
|
2026-06-13 16:32:33 +02:00
|
|
|
},
|
|
|
|
|
allow_redirects=True,
|
|
|
|
|
)
|
|
|
|
|
return s
|
|
|
|
|
from datetime import datetime, timezone
|
2026-06-05 20:34:03 +02:00
|
|
|
from devplacepy.database import get_table
|
|
|
|
|
from devplacepy.utils import generate_uid
|
2026-06-13 16:32:33 +02:00
|
|
|
_counter_votes = [0]
|
|
|
|
|
AJAX_votes = {"X-Requested-With": "fetch"}
|
|
|
|
|
def _session_votes():
|
|
|
|
|
_counter_votes[0] += 1
|
|
|
|
|
name = f"vot{int(time.time() * 1000)}{_counter_votes[0]}"
|
2026-06-05 20:34:03 +02:00
|
|
|
s = requests.Session()
|
2026-06-09 18:48:08 +02:00
|
|
|
s.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",
|
2026-06-09 18:48:08 +02:00
|
|
|
},
|
|
|
|
|
allow_redirects=True,
|
|
|
|
|
)
|
2026-06-05 20:34:03 +02:00
|
|
|
return s, name
|
2026-06-13 16:32:33 +02:00
|
|
|
def _uid_votes(username):
|
2026-06-05 20:34:03 +02:00
|
|
|
return get_table("users").find_one(username=username)["uid"]
|
2026-06-13 16:32:33 +02:00
|
|
|
def _make_post_votes(owner_uid):
|
2026-06-05 20:34:03 +02:00
|
|
|
uid = generate_uid()
|
2026-06-09 18:48:08 +02:00
|
|
|
get_table("posts").insert(
|
|
|
|
|
{
|
2026-06-14 16:46:36 +02:00
|
|
|
"deleted_at": None,
|
|
|
|
|
"deleted_by": None,
|
2026-06-09 18:48:08 +02:00
|
|
|
"uid": uid,
|
|
|
|
|
"user_uid": owner_uid,
|
|
|
|
|
"slug": f"{uid[:8]}-vote-post",
|
|
|
|
|
"title": None,
|
|
|
|
|
"content": "vote target content",
|
|
|
|
|
"topic": "random",
|
|
|
|
|
"project_uid": None,
|
|
|
|
|
"image": None,
|
|
|
|
|
"stars": 0,
|
|
|
|
|
"created_at": datetime.now(timezone.utc).isoformat(),
|
|
|
|
|
}
|
|
|
|
|
)
|
2026-06-05 20:34:03 +02:00
|
|
|
return uid
|
|
|
|
|
|
|
|
|
|
|
2026-06-13 16:32:33 +02:00
|
|
|
def test_vote_bad_value_is_handled_not_500(app_server):
|
|
|
|
|
s = _session_validation()
|
|
|
|
|
r = s.post(
|
|
|
|
|
f"{BASE_URL}/votes/post/nonexistent",
|
|
|
|
|
data={"value": "abc"},
|
|
|
|
|
allow_redirects=False,
|
|
|
|
|
)
|
|
|
|
|
assert r.status_code != 500
|
|
|
|
|
assert r.status_code in (302, 303, 400)
|
|
|
|
|
|
|
|
|
|
|
2026-06-05 20:34:03 +02:00
|
|
|
def test_upvote_returns_ajax_payload(app_server):
|
2026-06-13 16:32:33 +02:00
|
|
|
s_a, a_name = _session_votes()
|
|
|
|
|
s_b, _ = _session_votes()
|
|
|
|
|
post_uid = _make_post_votes(_uid_votes(a_name))
|
|
|
|
|
r = s_b.post(f"{BASE_URL}/votes/post/{post_uid}", data={"value": "1"}, headers=AJAX_votes)
|
2026-06-05 20:34:03 +02:00
|
|
|
assert r.json() == {"net": 1, "up": 1, "down": 0, "value": 1}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_repeated_vote_toggles_off(app_server):
|
2026-06-13 16:32:33 +02:00
|
|
|
s_a, a_name = _session_votes()
|
|
|
|
|
s_b, _ = _session_votes()
|
|
|
|
|
post_uid = _make_post_votes(_uid_votes(a_name))
|
|
|
|
|
s_b.post(f"{BASE_URL}/votes/post/{post_uid}", data={"value": "1"}, headers=AJAX_votes)
|
|
|
|
|
r = s_b.post(f"{BASE_URL}/votes/post/{post_uid}", data={"value": "1"}, headers=AJAX_votes)
|
2026-06-05 20:34:03 +02:00
|
|
|
assert r.json()["net"] == 0
|
|
|
|
|
assert r.json()["value"] == 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_switch_upvote_to_downvote(app_server):
|
2026-06-13 16:32:33 +02:00
|
|
|
s_a, a_name = _session_votes()
|
|
|
|
|
s_b, _ = _session_votes()
|
|
|
|
|
post_uid = _make_post_votes(_uid_votes(a_name))
|
|
|
|
|
s_b.post(f"{BASE_URL}/votes/post/{post_uid}", data={"value": "1"}, headers=AJAX_votes)
|
2026-06-09 18:48:08 +02:00
|
|
|
r = s_b.post(
|
2026-06-13 16:32:33 +02:00
|
|
|
f"{BASE_URL}/votes/post/{post_uid}", data={"value": "-1"}, headers=AJAX_votes
|
2026-06-09 18:48:08 +02:00
|
|
|
)
|
2026-06-05 20:34:03 +02:00
|
|
|
assert r.json()["net"] == -1
|
|
|
|
|
assert r.json()["value"] == -1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_upvote_notifies_owner_and_awards_xp(app_server):
|
2026-06-13 16:32:33 +02:00
|
|
|
s_a, a_name = _session_votes()
|
|
|
|
|
s_b, _ = _session_votes()
|
|
|
|
|
a_uid = _uid_votes(a_name)
|
|
|
|
|
post_uid = _make_post_votes(a_uid)
|
2026-06-05 20:34:03 +02:00
|
|
|
before = get_table("users").find_one(uid=a_uid).get("xp", 0) or 0
|
2026-06-13 16:32:33 +02:00
|
|
|
s_b.post(f"{BASE_URL}/votes/post/{post_uid}", data={"value": "1"}, headers=AJAX_votes)
|
2026-06-05 20:34:03 +02:00
|
|
|
assert get_table("notifications").count(user_uid=a_uid, type="vote") == 1
|
|
|
|
|
after = get_table("users").find_one(uid=a_uid).get("xp", 0) or 0
|
|
|
|
|
assert after - before == 5
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_self_vote_does_not_notify(app_server):
|
2026-06-13 16:32:33 +02:00
|
|
|
s_a, a_name = _session_votes()
|
|
|
|
|
a_uid = _uid_votes(a_name)
|
|
|
|
|
post_uid = _make_post_votes(a_uid)
|
2026-06-05 20:34:03 +02:00
|
|
|
before = get_table("notifications").count(user_uid=a_uid, type="vote")
|
2026-06-13 16:32:33 +02:00
|
|
|
s_a.post(f"{BASE_URL}/votes/post/{post_uid}", data={"value": "1"}, headers=AJAX_votes)
|
2026-06-05 20:34:03 +02:00
|
|
|
after = get_table("notifications").count(user_uid=a_uid, type="vote")
|
|
|
|
|
assert after == before
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_non_ajax_vote_redirects_to_referer(app_server):
|
2026-06-13 16:32:33 +02:00
|
|
|
s_a, a_name = _session_votes()
|
|
|
|
|
s_b, _ = _session_votes()
|
|
|
|
|
post_uid = _make_post_votes(_uid_votes(a_name))
|
2026-06-05 20:34:03 +02:00
|
|
|
r = s_b.post(
|
|
|
|
|
f"{BASE_URL}/votes/post/{post_uid}",
|
|
|
|
|
data={"value": "1"},
|
2026-06-22 18:41:53 +02:00
|
|
|
headers={"Referer": f"{BASE_URL}/gists"},
|
2026-06-05 20:34:03 +02:00
|
|
|
allow_redirects=False,
|
|
|
|
|
)
|
|
|
|
|
assert r.status_code == 302
|
2026-06-22 18:41:53 +02:00
|
|
|
assert r.headers["location"] == "/gists"
|