From 36fd58d7a61133e525e2abd6086b510958fd18ae Mon Sep 17 00:00:00 2001 From: moson-mo Date: Sun, 22 Jan 2023 15:54:31 +0100 Subject: [PATCH] fix: show notification box when adding a comment Currently, the "Enable notifications" checkbox is only shown when editing a comment. We should also show it when a new comment is about to be added. Signed-off-by: moson-mo --- templates/partials/packages/comment_form.html | 2 +- test/test_pkgbase_routes.py | 27 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/templates/partials/packages/comment_form.html b/templates/partials/packages/comment_form.html index 5368e784..9222d6e9 100644 --- a/templates/partials/packages/comment_form.html +++ b/templates/partials/packages/comment_form.html @@ -33,7 +33,7 @@ Routes: - {% if comment and not request.user.notified(pkgbase) %} + {% if not request.user.notified(pkgbase) %} diff --git a/test/test_pkgbase_routes.py b/test/test_pkgbase_routes.py index 124eb71f..a5c93451 100644 --- a/test/test_pkgbase_routes.py +++ b/test/test_pkgbase_routes.py @@ -400,18 +400,36 @@ def test_pkgbase_comments( client: TestClient, maintainer: User, user: User, package: Package ): """This test includes tests against the following routes: + - GET /pkgbase/{name} (to check notification checkbox) - POST /pkgbase/{name}/comments - GET /pkgbase/{name} (to check comments) - Tested against a comment created with the POST route - GET /pkgbase/{name}/comments/{id}/form - Tested against a comment created with the POST route """ + cookies = {"AURSID": maintainer.login(Request(), "testPassword")} + pkgbasename = package.PackageBase.Name + + endpoint = f"/pkgbase/{pkgbasename}" + with client as request: + request.cookies = cookies + resp = request.get( + endpoint, + follow_redirects=True, + ) + assert resp.status_code == int(HTTPStatus.OK) + + # Make sure we got our checkbox for enabling notifications + root = parse_root(resp.text) + input = root.find('//input[@id="id_enable_notifications"]') + assert input is not None + + # create notification with db.begin(): user.CommentNotify = 1 db.create(PackageNotification, PackageBase=package.PackageBase, User=user) - cookies = {"AURSID": maintainer.login(Request(), "testPassword")} - pkgbasename = package.PackageBase.Name + # post a comment endpoint = f"/pkgbase/{pkgbasename}/comments" with client as request: request.cookies = cookies @@ -442,6 +460,11 @@ def test_pkgbase_comments( assert bodies[0].text.strip() == "Test comment." comment_id = headers[0].attrib["id"].split("-")[-1] + # Since we've enabled notifications already, + # there should be no checkbox on our page + input = root.find('//input[@id="id_enable_notifications"]') + assert input is None + # Test the non-javascript version of comment editing by # visiting the /pkgbase/{name}/comments/{id}/edit route. with client as request: