Optimization
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user