Skip to content

Commit 15cea7b

Browse files
committed
Paginate announcement cleanup, add multi-page test, fix total count
Cleanup in conftest and _cleanup_announcements now loops until no test announcements remain, handling the case where >7 exist across pages. New test_multi_page_cleanup creates 9 announcements (exceeding the server page size of 7) and verifies cleanup catches all of them. Fix PROGRESS.md total: 411 not 412.
1 parent f9adb8d commit 15cea7b

3 files changed

Lines changed: 46 additions & 12 deletions

File tree

PROGRESS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@
6565
| State || 2 |
6666
| Shares | 5 | 40 |
6767
| System Tags | 6 | 22 |
68-
| **Total** | **50** | **412** |
68+
| **Total** | **50** | **411** |

tests/integration/conftest.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,16 @@ async def _cleanup(client: NextcloudClient) -> None:
156156
with contextlib.suppress(Exception):
157157
await client.ocs_put("apps/user_status/api/v1/user_status/status", data={"statusType": "online"})
158158
with contextlib.suppress(Exception):
159-
announcements = await client.ocs_get("apps/announcementcenter/api/v1/announcements")
160-
for ann in announcements:
161-
subject = str(ann.get("subject", ""))
162-
if subject.startswith("mcp-test-ann"):
163-
with contextlib.suppress(Exception):
164-
await client.ocs_delete(f"apps/announcementcenter/api/v1/announcements/{ann['id']}")
159+
while True:
160+
announcements = await client.ocs_get("apps/announcementcenter/api/v1/announcements")
161+
if not announcements:
162+
break
163+
deleted = False
164+
for ann in announcements:
165+
subject = str(ann.get("subject", ""))
166+
if subject.startswith("mcp-test-ann"):
167+
with contextlib.suppress(Exception):
168+
await client.ocs_delete(f"apps/announcementcenter/api/v1/announcements/{ann['id']}")
169+
deleted = True
170+
if not deleted:
171+
break

tests/integration/test_announcements.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Integration tests for Announcement Center tools against a real Nextcloud instance."""
22

3+
import contextlib
34
import json
45
from typing import Any
56

@@ -25,11 +26,17 @@ async def _create_announcement(nc_mcp: McpTestHelper, suffix: str = "") -> dict[
2526

2627

2728
async def _cleanup_announcements(nc_mcp: McpTestHelper) -> None:
28-
"""Delete all test announcements."""
29-
result = await nc_mcp.call("list_announcements")
30-
for a in json.loads(result)["data"]:
31-
if str(a.get("subject", "")).startswith(UNIQUE):
32-
await nc_mcp.call("delete_announcement", announcement_id=a["id"])
29+
"""Delete all test announcements, paginating through all pages."""
30+
while True:
31+
result = await nc_mcp.call("list_announcements")
32+
data = json.loads(result)["data"]
33+
deleted = False
34+
for a in data:
35+
if str(a.get("subject", "")).startswith(UNIQUE):
36+
await nc_mcp.call("delete_announcement", announcement_id=a["id"])
37+
deleted = True
38+
if not deleted:
39+
break
3340

3441

3542
class TestListAnnouncements:
@@ -97,6 +104,26 @@ async def test_pagination_offset(self, nc_mcp: McpTestHelper) -> None:
97104
await nc_mcp.call("delete_announcement", announcement_id=a1["id"])
98105
await nc_mcp.call("delete_announcement", announcement_id=a2["id"])
99106

107+
@pytest.mark.asyncio
108+
async def test_multi_page_cleanup(self, nc_mcp: McpTestHelper) -> None:
109+
"""Create >7 announcements (server page size) and verify paginated cleanup catches all."""
110+
await _cleanup_announcements(nc_mcp)
111+
created_ids: list[int] = []
112+
try:
113+
for i in range(9):
114+
ann = await _create_announcement(nc_mcp, f"bulk{i}")
115+
created_ids.append(ann["id"])
116+
first_page = json.loads(await nc_mcp.call("list_announcements"))
117+
assert first_page["pagination"]["has_more"] is True
118+
await _cleanup_announcements(nc_mcp)
119+
result = await nc_mcp.call("list_announcements")
120+
remaining = [a for a in json.loads(result)["data"] if str(a.get("subject", "")).startswith(UNIQUE)]
121+
assert len(remaining) == 0, f"Leftover test announcements: {[a['subject'] for a in remaining]}"
122+
finally:
123+
for ann_id in created_ids:
124+
with contextlib.suppress(Exception):
125+
await nc_mcp.call("delete_announcement", announcement_id=ann_id)
126+
100127
@pytest.mark.asyncio
101128
async def test_pagination_info(self, nc_mcp: McpTestHelper) -> None:
102129
created = await _create_announcement(nc_mcp, "paginfo")

0 commit comments

Comments
 (0)