Files
devplacepy/tests/api/profile/notifsettings.py
T
retoor 8a48e3ef85 Keep composers usable, group actions and notifications, and drop the tool-count cap
Comment and post layouts stay full width on small screens. Secondary actions live in the More menu. Notifications can be grouped and throttled, and Enter can submit when that profile setting is on. Emulated-tool models accept large catalogs, with reserved names aliased on the wire and the catalog cached per owner. A dropped service-worker navigation is retried once. The test server waits 120s to finish importing before it is stopped.
2026-11-12 15:29:27 +01:00

110 lines
3.2 KiB
Python

# retoor <retoor@molodetz.nl>
import time
import requests
from tests.conftest import BASE_URL
_counter = [0]
JSON = {"Accept": "application/json"}
def _signup():
_counter[0] += 1
name = f"nset{int(time.time() * 1000)}{_counter[0]}"
session = requests.Session()
session.post(
f"{BASE_URL}/auth/signup",
data={
"username": name,
"email": f"{name}@t.dev",
"password": "secret123",
"confirm_password": "secret123",
"birth_date": "1990-01-01",
"accept_terms": "1",
},
allow_redirects=True,
)
return session, name
def _toggle(session, name, kind, value):
return session.post(
f"{BASE_URL}/profile/{name}/notifications/{kind}",
data={"value": "true" if value else "false"},
headers=JSON,
)
def test_owner_toggles_grouping_and_throttling(app_server):
session, name = _signup()
for kind, field in (("grouping", "notif_grouping_enabled"), ("throttling", "notif_throttle_enabled")):
resp = _toggle(session, name, kind, False)
assert resp.status_code == 200, resp.text[:200]
assert resp.json()["data"][field] is False
resp = _toggle(session, name, kind, True)
assert resp.status_code == 200, resp.text[:200]
assert resp.json()["data"][field] is True
def test_other_user_cannot_toggle(app_server):
_, target = _signup()
attacker, _ = _signup()
for kind in ("grouping", "throttling"):
resp = attacker.post(
f"{BASE_URL}/profile/{target}/notifications/{kind}",
data={"value": "false"},
headers=JSON,
allow_redirects=False,
)
assert resp.status_code == 403
def test_admin_can_toggle(app_server, seeded_db):
_, target = _signup()
admin = requests.Session()
admin.post(
f"{BASE_URL}/auth/login",
data={"email": seeded_db["alice"]["email"], "password": seeded_db["alice"]["password"]},
allow_redirects=True,
)
resp = admin.post(
f"{BASE_URL}/profile/{target}/notifications/grouping",
data={"value": "false"},
headers=JSON,
)
assert resp.status_code == 200, resp.text[:200]
assert resp.json()["data"]["notif_grouping_enabled"] is False
def test_owner_toggles_enter_to_submit(app_server):
session, name = _signup()
resp = session.post(
f"{BASE_URL}/profile/{name}/enter-to-submit",
data={"value": "false"},
headers=JSON,
)
assert resp.status_code == 200, resp.text[:200]
assert resp.json()["data"]["enter_to_submit"] is False
page = session.get(f"{BASE_URL}/profile/{name}", headers=JSON)
assert page.json()["enter_to_submit"] is False
resp = session.post(
f"{BASE_URL}/profile/{name}/enter-to-submit",
data={"value": "true"},
headers=JSON,
)
assert resp.json()["data"]["enter_to_submit"] is True
def test_other_user_cannot_toggle_enter_to_submit(app_server):
_, target = _signup()
attacker, _ = _signup()
resp = attacker.post(
f"{BASE_URL}/profile/{target}/enter-to-submit",
data={"value": "false"},
headers=JSON,
allow_redirects=False,
)
assert resp.status_code == 403