Esempio n. 1
0
    def test_assign_roles_unique(self):
        """ test if 'unique' attribute works fine """
        assign_role(self.john, Advisor, self.bob)
        assign_role(self.john, Advisor, self.julie)

        # Get the single user that has the role attached.
        self.assertEqual(get_user(Advisor), self.john)

        assign_role(self.mike, Advisor, self.john)

        # Now, multiple users have Advisor.
        # So the method should not be used.
        with self.assertRaises(NotAllowed):
            get_user(Advisor)

        # Trying to assign the multiple roles using a Role with unique=True
        with self.assertRaises(InvalidRoleAssignment):
            assign_roles([self.john, self.mike], Advisor, self.julie)

        # Trying to add the role again using a Role with unique=True
        with self.assertRaises(InvalidRoleAssignment):
            assign_role(self.mike, Advisor, self.bob)

        # Trying to add the role again using a Role with unique=True
        with self.assertRaises(InvalidRoleAssignment):
            assign_role(self.mike, Advisor, self.julie)

        users_list = get_users(Advisor)
        self.assertEqual(list(users_list), [self.john, self.mike])
Esempio n. 2
0
    def test_remove_roles(self):
        """ test if the remove_roles method works fine """
        assign_role(self.john, Teacher, self.bob)
        remove_role(self.john, Teacher, self.bob)

        users_list = get_users(Teacher)
        self.assertEqual(list(users_list), [])

        assign_roles([self.john, self.mike], Teacher, self.bob)
        remove_roles([self.john, self.mike], Teacher)

        users_list = get_users(Teacher)
        self.assertEqual(list(users_list), [])

        assign_role(self.julie, Coordenator)
        self.assertTrue(has_permission(self.julie, 'testapp1.add_user'))
        remove_role(self.julie)
        self.assertFalse(has_permission(self.julie, 'testapp1.add_user'))

        # Remove all roles from the project.
        assign_roles([self.john, self.mike], Teacher, self.bob)
        remove_all(Coordenator)
        remove_all(Teacher)
        self.assertEqual(list(get_users(Coordenator)), [])
        self.assertEqual(list(get_users(Teacher)), [])
Esempio n. 3
0
    def test_assign_roles(self):
        """ test if the assignment methods work fine """
        assign_roles([self.john, self.mike], Teacher, self.bob)

        users_list = get_users(Teacher, self.bob)
        self.assertEqual(list(users_list), [self.john, self.mike])

        with self.assertRaises(NotAllowed):
            assign_role(self.john, Teacher, Chapter)
Esempio n. 4
0
 def assign_roles(self, users_list, role_class):
     return shortcuts.assign_roles(users_list, role_class, self)