Files
devplacepy/tests/unit/database/users.py
T
retoor 8e9d3fad98 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

100 lines
2.9 KiB
Python

# retoor <retoor@molodetz.nl>
def test_primary_admin_ignores_accounts_without_a_signup_time(local_db):
from devplacepy.database import get_primary_admin_uid, invalidate_admins_cache
users = local_db["users"]
users.insert(
{
"uid": "pa-real",
"username": "pa-real",
"terms_version": "1",
"role": "Admin",
"created_at": "1990-01-01T00:00:00",
"deleted_at": None,
}
)
users.insert(
{
"uid": "pa-null",
"username": "pa-null",
"terms_version": "1",
"role": "Admin",
"created_at": None,
"deleted_at": None,
}
)
users.insert(
{
"uid": "pa-blank",
"username": "pa-blank",
"terms_version": "1",
"role": "Admin",
"created_at": "",
"deleted_at": None,
}
)
invalidate_admins_cache()
try:
assert get_primary_admin_uid() == "pa-real"
finally:
for uid in ("pa-real", "pa-null", "pa-blank"):
users.delete(uid=uid)
invalidate_admins_cache()
def test_primary_admin_skips_deactivated_and_deleted_founders(local_db):
from devplacepy.database import get_primary_admin_uid, invalidate_admins_cache
users = local_db["users"]
seeded = [
("pa-deleted", "1991-01-01T00:00:00", True, "2020-01-01T00:00:00"),
("pa-inactive", "1992-01-01T00:00:00", False, None),
("pa-usable", "1993-01-01T00:00:00", True, None),
]
for uid, created_at, active, deleted_at in seeded:
users.insert(
{
"uid": uid,
"username": uid,
"terms_version": "1",
"role": "Admin",
"created_at": created_at,
"is_active": active,
"deleted_at": deleted_at,
}
)
invalidate_admins_cache()
try:
assert get_primary_admin_uid() == "pa-usable"
finally:
for uid, _, _, _ in seeded:
users.delete(uid=uid)
invalidate_admins_cache()
def test_account_with_a_null_is_active_counts_as_active(local_db):
from devplacepy.database import is_account_active
assert is_account_active({"is_active": None}) is True
def test_account_without_an_is_active_column_counts_as_active(local_db):
from devplacepy.database import is_account_active
assert is_account_active({}) is True
def test_an_explicitly_disabled_account_is_not_active(local_db):
from devplacepy.database import is_account_active
assert is_account_active({"is_active": False}) is False
assert is_account_active({"is_active": 0}) is False
def test_an_enabled_account_is_active(local_db):
from devplacepy.database import is_account_active
assert is_account_active({"is_active": True}) is True
assert is_account_active({"is_active": 1}) is True