|
|
@@ -2,8 +2,9 @@
|
|
|
|
|
|
Administrators see them; other signed-in users only when
|
|
|
``announcements_all_users`` is on. With authentication off, the person running
|
|
|
-Bambuddy sees them. Anyone else gets an empty list, which hides the sidebar entry
|
|
|
-and the banner the same way "nothing published" does.
|
|
|
+Bambuddy sees them. Anyone else gets ``visible: false`` and an empty list. Those
|
|
|
+who may see them get ``visible: true`` even with nothing published, because the
|
|
|
+sidebar entry is there for them either way.
|
|
|
"""
|
|
|
|
|
|
import json
|
|
|
@@ -36,6 +37,16 @@ async def _setting(db, key: str, value: str) -> None:
|
|
|
await db.commit()
|
|
|
|
|
|
|
|
|
+async def _get(client: AsyncClient, headers: dict | None = None) -> dict:
|
|
|
+ r = await client.get(URL, headers=headers)
|
|
|
+ assert r.status_code == 200, r.text
|
|
|
+ return r.json()
|
|
|
+
|
|
|
+
|
|
|
+async def _items(client: AsyncClient, headers: dict | None = None) -> list[dict]:
|
|
|
+ return (await _get(client, headers))["announcements"]
|
|
|
+
|
|
|
+
|
|
|
async def _admin(client: AsyncClient, username: str) -> dict:
|
|
|
await client.post(
|
|
|
"/api/v1/auth/setup",
|
|
|
@@ -66,9 +77,9 @@ class TestAuthOff:
|
|
|
@pytest.mark.asyncio
|
|
|
async def test_listed_with_every_language_and_unread(self, async_client: AsyncClient, db_session):
|
|
|
await _seed(db_session, "a1")
|
|
|
- r = await async_client.get(URL)
|
|
|
- assert r.status_code == 200
|
|
|
- [item] = r.json()
|
|
|
+ body = await _get(async_client)
|
|
|
+ assert body["visible"] is True
|
|
|
+ [item] = body["announcements"]
|
|
|
assert item["id"] == "a1" and item["level"] == "important" and item["read"] is False
|
|
|
assert set(item["texts"]) == {"en", "de"}
|
|
|
|
|
|
@@ -76,7 +87,13 @@ class TestAuthOff:
|
|
|
async def test_read_sticks(self, async_client: AsyncClient, db_session):
|
|
|
await _seed(db_session, "a1")
|
|
|
assert (await async_client.post(f"{URL}/a1/read")).status_code == 204
|
|
|
- assert (await async_client.get(URL)).json()[0]["read"] is True
|
|
|
+ assert (await _items(async_client))[0]["read"] is True
|
|
|
+
|
|
|
+ @pytest.mark.asyncio
|
|
|
+ async def test_visible_with_nothing_published(self, async_client: AsyncClient):
|
|
|
+ # The sidebar entry stays for whoever may see announcements, so an empty
|
|
|
+ # inbox has to say "visible", not look like "not for you".
|
|
|
+ assert await _get(async_client) == {"visible": True, "announcements": []}
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
async def test_unknown_id_is_404(self, async_client: AsyncClient):
|
|
|
@@ -86,7 +103,7 @@ class TestAuthOff:
|
|
|
async def test_switched_off_shows_nothing(self, async_client: AsyncClient, db_session):
|
|
|
await _seed(db_session, "a1")
|
|
|
await _setting(db_session, "announcements_enabled", "false")
|
|
|
- assert (await async_client.get(URL)).json() == []
|
|
|
+ assert await _get(async_client) == {"visible": False, "announcements": []}
|
|
|
assert (await async_client.post(f"{URL}/a1/read")).status_code == 404
|
|
|
|
|
|
|
|
|
@@ -102,8 +119,10 @@ class TestAuthOn:
|
|
|
await _seed(db_session, "a1")
|
|
|
admin = await _admin(async_client, "annadmin1")
|
|
|
user = await _user(async_client, admin, "annuser1")
|
|
|
- assert [i["id"] for i in (await async_client.get(URL, headers=admin)).json()] == ["a1"]
|
|
|
- assert (await async_client.get(URL, headers=user)).json() == []
|
|
|
+ admin_view = await _get(async_client, admin)
|
|
|
+ assert admin_view["visible"] is True
|
|
|
+ assert [i["id"] for i in admin_view["announcements"]] == ["a1"]
|
|
|
+ assert await _get(async_client, user) == {"visible": False, "announcements": []}
|
|
|
assert (await async_client.post(f"{URL}/a1/read", headers=user)).status_code == 404
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
@@ -114,8 +133,17 @@ class TestAuthOn:
|
|
|
await _setting(db_session, "announcements_all_users", "true")
|
|
|
|
|
|
assert (await async_client.post(f"{URL}/a1/read", headers=user)).status_code == 204
|
|
|
- assert (await async_client.get(URL, headers=user)).json()[0]["read"] is True
|
|
|
- assert (await async_client.get(URL, headers=admin)).json()[0]["read"] is False
|
|
|
+ user_view = await _get(async_client, user)
|
|
|
+ assert user_view["visible"] is True
|
|
|
+ assert user_view["announcements"][0]["read"] is True
|
|
|
+ assert (await _items(async_client, admin))[0]["read"] is False
|
|
|
+
|
|
|
+ @pytest.mark.asyncio
|
|
|
+ async def test_admin_entry_visible_with_nothing_published(self, async_client: AsyncClient):
|
|
|
+ admin = await _admin(async_client, "annadmin3")
|
|
|
+ user = await _user(async_client, admin, "annuser3")
|
|
|
+ assert await _get(async_client, admin) == {"visible": True, "announcements": []}
|
|
|
+ assert (await _get(async_client, user))["visible"] is False
|
|
|
|
|
|
|
|
|
@pytest.mark.integration
|