Files
member-portal/tests/test_derive_member_sources.py
T
inference-admin ffe62d3c78
ci/woodpecker/push/woodpecker Pipeline was canceled
portal: derive source from OC email visibility instead of trusting a stale flag
oc-incognito disables email matching by design, so a profile that later shows an
email leaves the member silently unmatched. The sweep now flips those to oc and
records oc_email; profiles still hiding an email are untouched. Test covers both.
2026-11-17 05:04:50 +00:00

24 lines
1.3 KiB
Python

import asyncio, os, sys, tempfile
os.environ["DB_PATH"] = os.path.join(tempfile.mkdtemp(), "sources.db")
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import app.main as m
m.DB_PATH = os.environ["DB_PATH"]
conn = m.get_db()
conn.execute("INSERT OR REPLACE INTO members (email, slug, active, source) VALUES (?,?,?,?)",
("a@example.org", "slug-a", 1, "oc-incognito"))
conn.execute("INSERT OR REPLACE INTO members (email, slug, active, source) VALUES (?,?,?,?)",
("b@example.org", "slug-b", 1, "oc-incognito"))
conn.commit(); conn.close()
m.fetch_member_index = lambda: [("a@example.org", "slug-a"), ("other@example.org", "slug-z")]
r = asyncio.run(m.derive_member_sources())
conn = m.get_db()
a = conn.execute("SELECT source, oc_email FROM members WHERE email='a@example.org'").fetchone()
b = conn.execute("SELECT source, oc_email FROM members WHERE email='b@example.org'").fetchone()
conn.close()
print(" flipped:", r["flipped"], "| a:", tuple(a), "| b:", tuple(b))
assert tuple(a) == ("oc", "a@example.org"), "visible email must flip the source and record it"
assert tuple(b) == ("oc-incognito", None), "a profile still hiding its email stays incognito"
print("DERIVE SOURCES OK: flips only where the profile now shows an email")