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'])
def test_clear_permissions_on_administration_role(self): role = PermafrostRole(name="Bobs Administration Group", category="administration") role.save() role.permissions_add(self.perm_view_permafrostrole) role.permissions_clear() 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 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.view_permafrostrole'])
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, [])