Esempio n. 1
0
    def test_add_optional_to_administration_role(self):
        role = PermafrostRole(name="Bobs Administration Group", category="administration")
        role.save()
        role.permissions_add(self.perm_delete_permafrostrole)
        role.users_add(self.administrationuser)      # Add user to the Group
        perms = list(self.administrationuser.get_all_permissions())
        perms.sort()

        self.assertListEqual([perm.name for perm in role.group.permissions.all()], ['Can add Role', 'Can change Role', 'Can delete Role', 'Can view Role'])   # Make sure the required permission is present in the group
        self.assertEqual(role.group.name, "1_administration_bobs-administration-group")        # Checks that the user is created
        self.assertListEqual(perms, ['permafrost.add_permafrostrole', 'permafrost.change_permafrostrole', 'permafrost.delete_permafrostrole', 'permafrost.view_permafrostrole'])
Esempio n. 2
0
    def test_clear_permissions_on_staff_role(self):
        role = PermafrostRole(name="Bobs Staff Group", category="staff")
        role.save()
        role.permissions_add(self.perm_view_permafrostrole)
        role.permissions_clear()
        role.users_add(self.staffuser)      # Add user to the Group
        perms = list(self.staffuser.get_all_permissions())

        self.assertEqual([perm.name for perm in role.group.permissions.all()], ['Can view Role'])   # Make sure the required permission is present in the group
        self.assertEqual(role.group.name, "1_staff_bobs-staff-group")        # Checks that the user is created
        self.assertListEqual(perms, ['permafrost.view_permafrostrole'])
Esempio n. 3
0
    def test_add_not_allowed_to_user_role(self):
        '''
        Test that a permission that is not optional or required can be added
        '''
        role = PermafrostRole(name="Bobs Super Group", category="user")
        role.save()
        role.permissions_add(self.perm_delete_permafrostrole)
        role.users_add(self.user)
        perms = list(self.user.get_all_permissions())

        self.assertEqual(list(role.group.permissions.all()), [])            # Check the permissions on the group
        self.assertEqual(role.group.name, "1_user_bobs-super-group")        # Checks that the user is created
        self.assertListEqual(perms, [])
Esempio n. 4
0
    def test_add_optional_to_user_role(self):
        '''
        Test that the optional role can be added
        '''
        role = PermafrostRole(name="Bobs Super Group", category="user")
        role.save()
        role.permissions_add(self.perm_view_permafrostrole)
        role.users_add(self.user)
        perms = list(self.user.get_all_permissions())

        self.assertListEqual(list(role.group.permissions.all()), [self.perm_view_permafrostrole])            # Check the permissions on the group
        self.assertEqual(role.group.name, "1_user_bobs-super-group")        # Checks that the user is created
        self.assertListEqual(perms, ["permafrost.view_permafrostrole"])
Esempio n. 5
0
    def test_add_not_allowed_to_staff_role(self):
        '''
        Test that a permission that is not optional or required can be added
        '''
        role = PermafrostRole(name="Bobs Staff Group", category="staff")
        role.save()
        role.permissions_add(self.perm_delete_permafrostrole)
        role.users_add(self.staffuser)
        perms = list(self.staffuser.get_all_permissions())

        self.assertEqual([perm.name for perm in role.group.permissions.all()], ['Can view Role'])   # Make sure the required permission is present in the group
        self.assertEqual(role.group.name, "1_staff_bobs-staff-group")        # Checks that the user is created
        self.assertListEqual(perms, ['permafrost.view_permafrostrole'])
Esempio n. 6
0
    def test_add_optional_to_staff_role(self):
        '''
        Test that the optional role can be added
        '''
        role = PermafrostRole(name="Bobs Staff Group", category="staff")
        role.save()
        role.permissions_add(self.perm_change_permafrostrole)
        role.users_add(self.staffuser)      # Add user to the Group
        perms = list(self.staffuser.get_all_permissions())
        perms.sort()

        self.assertListEqual(list(role.group.permissions.all()), [self.perm_change_permafrostrole, self.perm_view_permafrostrole])            # Check the permissions on the group
        self.assertEqual(role.group.name, "1_staff_bobs-staff-group")        # Checks that the user is created
        self.assertListEqual(perms, ['permafrost.change_permafrostrole', 'permafrost.view_permafrostrole'])
Esempio n. 7
0
    def test_clear_permissions_on_user_role(self):
        '''
        Test that clearning permissions restores them to just the required.
        '''
        role = PermafrostRole(name="Bobs Super Group", category="user")
        role.save()
        role.permissions_add(self.perm_view_permafrostrole)
        role.permissions_clear()
        role.users_add(self.user)
        perms = list(self.user.get_all_permissions())

        self.assertEqual(list(role.group.permissions.all()), [])            # Check the permissions on the group
        self.assertEqual(role.group.name, "1_user_bobs-super-group")        # Checks that the user is created
        self.assertListEqual(perms, [])