From 99f1912d94a45431808e60c1f9821bde7d99f9c9 Mon Sep 17 00:00:00 2001 From: Deimos Date: Thu, 9 Aug 2018 07:28:18 -0600 Subject: [PATCH] Add more comment permissions tests Just a couple more tests for comment permissions that are more essential to be working correctly - replying in locked threads, and viewing removed comments. Also changes the "deleted comments lose all permissions" test slightly to actually check all permissions instead of a hard-coded (and obsolete) set of them. --- tildes/tests/test_comment.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tildes/tests/test_comment.py b/tildes/tests/test_comment.py index f830081..e1128f6 100644 --- a/tildes/tests/test_comment.py +++ b/tildes/tests/test_comment.py @@ -72,13 +72,28 @@ def test_comment_replying_permission(comment): assert Authenticated in principals_allowed_by_permission(comment, 'reply') +def test_comment_reply_locked_thread_permission(comment): + """Ensure that only admins can reply in locked threads.""" + comment.topic.is_locked = True + assert principals_allowed_by_permission(comment, 'reply') == {'admin'} + + def test_deleted_comment_permissions_removed(comment): """Ensure that deleted comments lose all of the permissions.""" comment.is_deleted = True - for permission in ('view', 'edit', 'delete', 'reply'): + + all_permissions = [perm for (_, _, perm) in comment.__acl__()] + for permission in all_permissions: assert not principals_allowed_by_permission(comment, permission) +def test_removed_comment_view_permission(comment): + """Ensure a removed comment can only be viewed by its author and admins.""" + comment.is_removed = True + principals = principals_allowed_by_permission(comment, 'view') + assert principals == {'admin', comment.user_id} + + def test_edit_grace_period(comment): """Ensure last_edited_time isn't set if the edit is inside grace period.""" one_sec = timedelta(seconds=1)