# -*- coding: utf-8 -*-
from django.contrib.auth.decorators import user_passes_test
from django.core.exceptions import PermissionDenied
from django.http import Http404
from django.middleware.csrf import REASON_CSRF_TOKEN_MISSING, _get_failure_view
from django.test import override_settings


def is_superuser(user):
    return user.is_superuser


@user_passes_test(is_superuser)
@override_settings(DEBUG=False)
def error403(request):
    raise PermissionDenied("Test 403 forbidden")


@user_passes_test(is_superuser)
@override_settings(DEBUG=False)
def error404(request):
    raise Http404("Test 404 not found")


@user_passes_test(is_superuser)
@override_settings(DEBUG=False)
def error500(request):
    raise Exception("test 500 server error")  # pylint: disable=broad-exception-raised


@user_passes_test(is_superuser)
@override_settings(DEBUG=False)
def errorcsrf(request):
    return _get_failure_view()(request, REASON_CSRF_TOKEN_MISSING)
