def test_to_super(self): UserFactory() UserFactory(is_staff=True) user2 = UserFactory(is_superuser=True) ACLRuleFactory(slug='page', permissions=['change_page'], apply_to=ACLRule.TO_SUPERUSERS) users = ACLRule.get_users_for(['change_page'], 'page') self.assertEqual(set(users), {user2})
def test_simple_user_for_multiples_perms(self): user1 = UserFactory() user2 = UserFactory() ACLRuleFactory( slug='page', permissions=['view_page'], users=[user1, user2]) ACLRuleFactory(slug='page', permissions=['change_page'], users=[user1]) users = ACLRule.get_users_for(['view_page', 'change_page'], 'page') self.assertEqual(set(users), {user1})
def test_to_staff(self): UserFactory() user2 = UserFactory(is_staff=True) ACLRuleFactory(slug='page', permissions=['view_page'], apply_to=ACLRule.TO_STAFF) users = ACLRule.get_users_for(['view_page'], 'page') self.assertEqual(set(users), {user2})
def test_any_logged_user(self): user1 = UserFactory() ACLRuleFactory(slug='page', permissions=['view_page'], apply_to=ACLRule.TO_LOGGED) users = ACLRule.get_users_for(['view_page'], 'page') self.assertNotIn(AnonymousUser(), users) self.assertIn(user1, users)
def test_is_distinct(self): user = UserFactory() group1_users = [user] group1 = GroupFactory(users=group1_users) ACLRuleFactory(slug='page', permissions=['view_page'], groups=[group1], users=[user]) users = ACLRule.get_users_for('view_page', 'page') self.assertEqual(users.count(), 1) self.assertEqual(set(users), set(group1_users))
def test_mixing_group_and_users(self): user = UserFactory() group1_users = [UserFactory(), UserFactory()] group2_users = [UserFactory(), UserFactory()] group1 = GroupFactory(users=group1_users) group2 = GroupFactory(users=group2_users) ACLRuleFactory(slug='page', permissions=['view_page'], groups=[group1, group2], users=[user]) users = ACLRule.get_users_for('view_page', 'page') self.assertEqual(set(users), set(group1_users + group2_users + [user]))
def test_simple_user_for_multiples_perms(self): user1 = UserFactory() user2 = UserFactory() ACLRuleFactory(slug='page', permissions=['view_page'], users=[user1, user2]) ACLRuleFactory(slug='page', permissions=['view_page', 'change_page'], users=[user1]) users = ACLRule.get_users_for(['view_page', 'change_page'], 'page') self.assertEqual(set(users), {user1})
def test_simple_user(self): user = UserFactory() ACLRuleFactory(slug='page', permissions=['view_page'], users=[user]) users = ACLRule.get_users_for('view_page', 'page') self.assertEqual(set(users), {user})
def test_simple_group(self): group_users = [UserFactory(), UserFactory()] group = GroupFactory(users=group_users) ACLRuleFactory(slug='page', permissions=['view_page'], groups=[group]) users = ACLRule.get_users_for('view_page', 'page') self.assertEqual(set(users), set(group_users))