90 lines
3.1 KiB
Python
Raw Normal View History

# retoor <retoor@molodetz.nl>
import requests
from playwright.sync_api import expect
from tests.conftest import BASE_URL
from devplacepy.database import (
get_notification_default,
get_notification_prefs,
get_table,
notification_enabled,
reset_notification_prefs,
set_notification_default,
set_notification_pref,
)
from devplacepy.utils import create_notification, generate_uid
def _user_notification_prefs(username):
return get_table("users").find_one(username=username)
def _pref(prefs, key):
return next(p for p in prefs if p["key"] == key)
def test_admin_default_endpoint(alice):
_, admin_user = alice
admin = _user_notification_prefs(admin_user["username"])
try:
response = requests.post(
f"{BASE_URL}/admin/notifications",
data={"notification_type": "level", "channel": "push", "value": "false"},
headers={"Accept": "application/json", "X-API-KEY": admin["api_key"]},
allow_redirects=False,
)
assert response.status_code == 200
assert get_notification_default("level", "push") is False
finally:
set_notification_default("level", "push", True)
def test_member_cannot_set_default(bob):
_, user = bob
member = _user_notification_prefs(user["username"])
response = requests.post(
f"{BASE_URL}/admin/notifications",
data={"notification_type": "level", "channel": "push", "value": "false"},
headers={"Accept": "application/json", "X-API-KEY": member["api_key"]},
allow_redirects=False,
)
assert response.status_code in (302, 303, 403)
assert get_notification_default("level", "push") is True
test(sveta): Write test: admin page renders participation notification defaults row Outcome: done Changed: tests/e2e/admin/notifications.py:53-90 Verified by: `python3 -m py_compile tests/e2e/admin/notifications.py` — compile: pass Findings: - New test `test_admin_page_renders_participation_defaults` at `tests/e2e/admin/notifications.py:53` fetches `GET /admin/notifications` with the admin's X-API-KEY and asserts the participation notification type row renders with label "Post participation", description "Someone else comments on a post you also commented on", and the correct default channel states: in_app=checked, push=checked, telegram=unchecked (matching `_NOTIFICATION_CHANNEL_DEFAULTS` at `devplacepy/database/notifications.py:34`) - `NOTIFICATION_TYPES` at `devplacepy/database/notifications.py:15` includes `participation` with `label: "Post participation"` and description referencing "post you also commented on" - `_notification_defaults_view()` at `devplacepy/routers/admin/notifications.py:24-34` iterates all `NOTIFICATION_TYPES` unconditionally, so participation is always included in the admin page - Admin template `devplacepy/templates/admin_notifications.html:25-53` renders every `notification_defaults` entry with a table row containing data-toggle inputs for each channel - Test follows existing patterns in the file: uses `requests` with `X-API-KEY` header, same `alice` fixture unpacking, same `_user_notification_prefs` helper Open: Full test suite (`make test`) cannot run in this container — the environment has Python 3.11.2 but the project `require Typosaurus-Run: 33c1c53eb8d34b528ee5beab574476fb Typosaurus-Node: 950b129728bf4645b401c9210089f9f5 Typosaurus-Agent: @sveta Refs: #132
2026-07-27 11:33:31 +02:00
def test_admin_page_renders_participation_defaults(alice):
_, admin_user = alice
admin = _user_notification_prefs(admin_user["username"])
response = requests.get(
f"{BASE_URL}/admin/notifications",
headers={"X-API-KEY": admin["api_key"]},
allow_redirects=False,
)
assert response.status_code == 200
html = response.text
assert "Post participation" in html, (
"Admin notifications page should contain 'Post participation' label"
)
assert "Someone else comments on a post you also commented on" in html, (
"Admin notifications page should contain participation description"
)
assert 'data-type="participation" data-channel="in_app"' in html, (
"Participation in_app row should exist"
)
assert 'data-type="participation" data-channel="in_app" checked' in html, (
"Participation in_app default should be checked (on)"
)
assert 'data-type="participation" data-channel="push"' in html, (
"Participation push row should exist"
)
assert 'data-type="participation" data-channel="push" checked' in html, (
"Participation push default should be checked (on)"
)
assert 'data-type="participation" data-channel="telegram"' in html, (
"Participation telegram row should exist"
)
assert (
'data-type="participation" data-channel="telegram" checked' not in html
), "Participation telegram default should NOT be checked (off)"