forked from retoor/devplacepy
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.
141 lines
4.0 KiB
Python
141 lines
4.0 KiB
Python
# retoor <retoor@molodetz.nl>
|
|
|
|
import json
|
|
import time
|
|
|
|
import requests
|
|
|
|
from tests.conftest import BASE_URL
|
|
|
|
JSON = {"Accept": "application/json"}
|
|
|
|
_counter = [0]
|
|
|
|
CHOICE = {
|
|
"kind": "single_choice",
|
|
"prompt": "Which journal mode allows concurrent readers?",
|
|
"points": 2,
|
|
"options": "DELETE\nWAL\nMEMORY",
|
|
"correct_indexes": "1",
|
|
}
|
|
|
|
NUMERIC = {
|
|
"kind": "numeric",
|
|
"prompt": "How many bytes are in a kibibyte?",
|
|
"points": 1,
|
|
"numeric_value": "1024",
|
|
"numeric_tolerance": "0",
|
|
}
|
|
|
|
TRUE_FALSE = {
|
|
"kind": "true_false",
|
|
"prompt": "A partial index can carry a WHERE clause.",
|
|
"points": 1,
|
|
"correct_boolean": "1",
|
|
}
|
|
|
|
FREE_TEXT = {
|
|
"kind": "free_text",
|
|
"prompt": "Why does a partial index help here?",
|
|
"points": 3,
|
|
"expected_answer": "It keeps the live query off a one bucket index.",
|
|
"grading_criteria": "Accept any answer that mentions the planner.",
|
|
}
|
|
|
|
DOCUMENT = {
|
|
"title": "Imported quiz",
|
|
"description": "Created from a document.",
|
|
"settings": {"reveal_answers": True, "pass_percent": 60, "allow_review": True},
|
|
"questions": [
|
|
{
|
|
"kind": "single_choice",
|
|
"prompt": "Which journal mode allows concurrent readers?",
|
|
"points": 2,
|
|
"options": [{"label": "DELETE"}, {"label": "WAL", "is_correct": True}],
|
|
},
|
|
{
|
|
"kind": "numeric",
|
|
"prompt": "How many bytes are in a kibibyte?",
|
|
"points": 1,
|
|
"numeric_value": 1024,
|
|
},
|
|
],
|
|
}
|
|
|
|
|
|
def signup(prefix="qz"):
|
|
_counter[0] += 1
|
|
name = f"{prefix}{int(time.time() * 1000)}{_counter[0]}"
|
|
session = requests.Session()
|
|
session.post(
|
|
f"{BASE_URL}/auth/signup",
|
|
data={
|
|
"username": name,
|
|
"email": f"{name}@t.dev",
|
|
"password": "secret123",
|
|
"confirm_password": "secret123",
|
|
"birth_date": "1990-01-01",
|
|
"accept_terms": "1",
|
|
},
|
|
allow_redirects=True,
|
|
)
|
|
return session, name
|
|
|
|
|
|
def create_quiz(session, title="Test quiz", **settings):
|
|
payload = {"title": title, "description": "A quiz."}
|
|
payload.update(settings)
|
|
response = session.post(f"{BASE_URL}/quizzes/create", data=payload, headers=JSON)
|
|
return response.json()["data"]["slug"]
|
|
|
|
|
|
def add_question(session, slug, payload):
|
|
return session.post(f"{BASE_URL}/quizzes/{slug}/questions", data=payload, headers=JSON)
|
|
|
|
|
|
def publish(session, slug):
|
|
return session.post(f"{BASE_URL}/quizzes/{slug}/publish", headers=JSON)
|
|
|
|
|
|
def build_published(session, questions=(CHOICE, NUMERIC), title="Playable quiz", **settings):
|
|
slug = create_quiz(session, title, **settings)
|
|
for question in questions:
|
|
add_question(session, slug, question)
|
|
publish(session, slug)
|
|
return slug
|
|
|
|
|
|
def import_quiz(session, document=None):
|
|
payload = {"document": json.dumps(document or DOCUMENT)}
|
|
response = session.post(f"{BASE_URL}/quizzes/import", data=payload, headers=JSON)
|
|
return response
|
|
|
|
|
|
def start_attempt(session, slug):
|
|
response = session.post(f"{BASE_URL}/quizzes/{slug}/attempts", headers=JSON)
|
|
return response.json()["data"]["uid"]
|
|
|
|
|
|
def attempt_state(session, slug, attempt_uid):
|
|
return session.get(
|
|
f"{BASE_URL}/quizzes/{slug}/attempts/{attempt_uid}", headers=JSON
|
|
).json()
|
|
|
|
|
|
def answer_correctly(session, slug, attempt_uid, question):
|
|
payload = {"question_uid": question["uid"]}
|
|
if question["kind"] == "single_choice":
|
|
correct = next(
|
|
(option["uid"] for option in question["options"] if option.get("is_correct")), None
|
|
)
|
|
payload["option_uids"] = correct or question["options"][1]["uid"]
|
|
elif question["kind"] == "numeric":
|
|
payload["answer_text"] = "1024"
|
|
elif question["kind"] == "true_false":
|
|
payload["answer_text"] = "true"
|
|
else:
|
|
payload["answer_text"] = "the planner picks a bad index for live rows"
|
|
return session.post(
|
|
f"{BASE_URL}/quizzes/{slug}/attempts/{attempt_uid}/answer", data=payload, headers=JSON
|
|
)
|