Add feature to use Real name on journals

This commit is contained in:
2026-09-01 18:29:18 +03:00
parent 65bebd19c5
commit 8ad292c793
11 changed files with 89 additions and 13 deletions
+35 -1
View File
@@ -37,7 +37,7 @@ class EmailVerificationTestCase(unittest.TestCase):
with patch("app.smtplib.SMTP") as smtp:
response = self.client.post(
"/register",
data={"username": "newmember", "email": "new@example.com", "password": "secure-password"},
data={"username": "newmember", "real_name": "New Member", "email": "new@example.com", "password": "secure-password"},
)
self.assertEqual(response.status_code, 302)
@@ -85,6 +85,40 @@ class EmailVerificationTestCase(unittest.TestCase):
with application.app.app_context():
self.assertEqual(application.get_db().execute("SELECT email FROM users WHERE id = ?", (user_id,)).fetchone()[0], "new@example.com")
def test_profile_name_is_used_for_byline_with_handle_fallback(self):
with application.app.app_context():
db = application.get_db()
named_author = db.execute(
"""INSERT INTO users (username, email, email_verified, password_hash, created_at, is_approved, role, mfa_enabled)
VALUES (?, ?, 1, ?, ?, 1, 'member', 1)""",
("named", "named@example.com", generate_password_hash("secure-password"), "2026-09-01T00:00:00+00:00"),
).lastrowid
legacy_author = db.execute(
"""INSERT INTO users (username, email, email_verified, password_hash, created_at, is_approved, role, mfa_enabled)
VALUES (?, ?, 1, ?, ?, 1, 'member', 1)""",
("legacy", "legacy@example.com", generate_password_hash("secure-password"), "2026-09-01T00:00:00+00:00"),
).lastrowid
db.execute(
"""INSERT INTO posts (title, slug, excerpt, body, category, author_id, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)""",
("Named post", "named-post", "Named excerpt", "Named body", "Code", named_author, "2026-09-01T00:00:00+00:00", "2026-09-01T00:00:00+00:00"),
)
db.execute(
"""INSERT INTO posts (title, slug, excerpt, body, category, author_id, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)""",
("Legacy post", "legacy-post", "Legacy excerpt", "Legacy body", "Code", legacy_author, "2026-09-01T00:00:00+00:00", "2026-09-01T00:00:00+00:00"),
)
db.commit()
with self.client.session_transaction() as session:
session["user_id"] = named_author
session["mfa_verified"] = True
response = self.client.post("/account/profile", data={"real_name": "Ada Lovelace"})
self.assertEqual(response.status_code, 302)
self.assertIn(b"BY Ada Lovelace", self.client.get("/").data)
self.assertIn(b"WRITTEN BY Ada Lovelace", self.client.get("/post/named-post").data)
self.assertIn(b"BY legacy", self.client.get("/").data)
if __name__ == "__main__":
unittest.main()