Optimization

This commit is contained in:
2026-09-03 08:47:57 +02:00
parent 7d32ef17dd
commit 81d6aa68b6
8 changed files with 1234 additions and 35 deletions
+58
View File
@@ -640,6 +640,64 @@ def test_admin_edits_other_user(alice):
reset_notification_prefs(target["uid"])
def _await_notification_enabled(uid, notification_type, channel, expected):
import time as _time
deadline = _time.time() + 5.0
current = notification_enabled(uid, notification_type, channel)
while current != expected and _time.time() < deadline:
_time.sleep(0.2)
current = notification_enabled(uid, notification_type, channel)
return current
def test_owner_reset_via_http_clears_custom_prefs(bob):
_, user = bob
target = _user_notification_prefs(user["username"])
set_notification_pref(target["uid"], "mention", "push", False)
try:
assert _await_notification_enabled(target["uid"], "mention", "push", False) is False
from devplacepy.database import get_table, refresh_snapshot
audit_table = get_table("audit_log")
before = audit_table.count(
event_key="profile.notification.reset", target_uid=target["uid"]
)
response = requests.post(
f"{BASE_URL}/profile/{target['username']}/notifications/reset",
headers={"Accept": "application/json", "X-API-KEY": target["api_key"]},
allow_redirects=False,
)
assert response.status_code == 200
body = response.json()
assert body["ok"] is True
assert body["redirect"] == f"/profile/{target['username']}?tab=notifications"
assert _await_notification_enabled(target["uid"], "mention", "push", True) is True
refresh_snapshot()
after = audit_table.count(
event_key="profile.notification.reset", target_uid=target["uid"]
)
assert after == before + 1
finally:
reset_notification_prefs(target["uid"])
def test_non_owner_non_admin_reset_forbidden(bob):
_, user = bob
member = _user_notification_prefs(user["username"])
target = _user_notification_prefs("alice_test")
response = requests.post(
f"{BASE_URL}/profile/{target['username']}/notifications/reset",
headers={"Accept": "application/json", "X-API-KEY": member["api_key"]},
allow_redirects=False,
)
assert response.status_code == 403
def test_profile_search_returns_results(alice):
page, _ = alice
resp = page.request.get(f"{BASE_URL}/profile/search?q=bob")