[test] webpush_api endpoints (#2534)

* test: webpush_api endpoints

* fix: SQL quote for `user`
This commit is contained in:
Vlad Stan
2024-05-23 23:23:32 +02:00
committed by GitHub
parent ae60b4517c
commit 93965bc5b6
3 changed files with 98 additions and 6 deletions
+7 -5
View File
@@ -1287,7 +1287,7 @@ async def create_webpush_subscription(
) -> WebPushSubscription:
await db.execute(
"""
INSERT INTO webpush_subscriptions (endpoint, user, data, host)
INSERT INTO webpush_subscriptions (endpoint, "user", data, host)
VALUES (?, ?, ?, ?)
""",
(
@@ -1302,17 +1302,19 @@ async def create_webpush_subscription(
return subscription
async def delete_webpush_subscription(endpoint: str, user: str) -> None:
await db.execute(
async def delete_webpush_subscription(endpoint: str, user: str) -> int:
resp = await db.execute(
"""DELETE FROM webpush_subscriptions WHERE endpoint = ? AND "user" = ?""",
(
endpoint,
user,
),
)
return resp.rowcount
async def delete_webpush_subscriptions(endpoint: str) -> None:
await db.execute(
async def delete_webpush_subscriptions(endpoint: str) -> int:
resp = await db.execute(
"DELETE FROM webpush_subscriptions WHERE endpoint = ?", (endpoint,)
)
return resp.rowcount
+2 -1
View File
@@ -67,7 +67,8 @@ async def api_delete_webpush_subscription(
endpoint = unquote(
base64.b64decode(str(request.query_params.get("endpoint"))).decode("utf-8")
)
await delete_webpush_subscription(endpoint, wallet.wallet.user)
count = await delete_webpush_subscription(endpoint, wallet.wallet.user)
return {"count": count}
except Exception as exc:
logger.debug(exc)
raise HTTPException(