Skip to content

Commit b8ab509

Browse files
committed
Add test to make sure permission calculation isn't order-dependent
1 parent 2a14383 commit b8ab509

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/unit/apps/forum_permission/test_checker.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,31 @@ def test_knows_that_granted_permissions_should_take_precedence_over_the_same_non
216216
checker = ForumPermissionChecker(user)
217217
# Run & check
218218
assert checker.has_perm('can_read_forum', self.forum)
219+
220+
def test_readable_forums_order_independent(self):
221+
PERM = 'can_read_forum'
222+
# Setup
223+
user = UserFactory.create()
224+
group = GroupFactory.create()
225+
user.groups.add(group)
226+
227+
# All forums are visible to everyone, except one is hidden from this group
228+
public1 = create_forum(name="Public 1")
229+
public2 = create_forum(name="Public 2")
230+
private = create_forum(name="Private")
231+
assign_perm(PERM, ALL_AUTHENTICATED_USERS, None, has_perm=True)
232+
assign_perm(PERM, group, private, has_perm=False)
233+
234+
checker = ForumPermissionChecker(user)
235+
236+
# Test with public forum in the end
237+
perms = checker.get_perms_for_forumlist([public1, public2, private], [PERM, ])
238+
assert PERM in perms[public1]
239+
assert PERM in perms[public2]
240+
assert PERM not in perms[private]
241+
242+
# Test with private forum in the middle
243+
perms = checker.get_perms_for_forumlist([public1, private, public2], [PERM, ])
244+
assert PERM in perms[public1]
245+
assert PERM in perms[public2]
246+
assert PERM not in perms[private]

0 commit comments

Comments
 (0)