# Path: django_core/views/mixins/auth.py
# class StaffRequiredViewMixin(LoginRequiredViewMixin):
#     """Require a logged in Staff member."""
# 
#     def dispatch(self, request, *args, **kwargs):
#         if not request.user.is_staff:
#             raise PermissionDenied
# 
#         return super(StaffRequiredViewMixin, self).dispatch(request,
#                                                             *args,
#                                                             **kwargs)
# 
# Path: django_core/views/mixins/auth.py
# class SuperuserRequiredViewMixin(LoginRequiredViewMixin):
#     """Require a logged in user to be a superuser."""
# 
#     def dispatch(self, request, *args, **kwargs):
#         if not request.user.is_superuser:
#             raise PermissionDenied
# 
#         return super(SuperuserRequiredViewMixin, self).dispatch(request,
#                                                                 *args,
#                                                                 **kwargs)


import uuid
from django.contrib.auth import get_user_model
from django.core.exceptions import PermissionDenied
from django.core.handlers.wsgi import WSGIHandler
from django.test import Client
from django.test import TestCase
from django_core.views import StaffRequiredViewMixin
from django_core.views import SuperuserRequiredViewMixin
from mock import patch
from __future__ import unicode_literals




class AuthMixinTests(TestCase):
    """Test case for authorization mixins."""

    def setUp(self):
        super(AuthMixinTests, self).setUpClass()
        self.username = uuid.uuid4().hex
        self.password = uuid.uuid4().hex
        self.user = get_user_model().objects.create_user(
            username=self.username,
            password=self.password
        )
        self.client = Client()

    def tearDown(self):
        super(AuthMixinTests, self).tearDownClass()
        self.user.delete()

    def test_staff_required_mixin_not_staff(self):
        """Test for mixin requiring a staff user when user isn't staff."""
        self.client.login(username=self.username, password=self.password)

        with self.assertRaises(PermissionDenied):
            request = WSGIHandler()
            request.user = self.user


# Path: django_core/views/mixins/auth.py
# class StaffRequiredViewMixin(LoginRequiredViewMixin):
#     """Require a logged in Staff member."""
# 
#     def dispatch(self, request, *args, **kwargs):
#         if not request.user.is_staff:
#             raise PermissionDenied
# 
#         return super(StaffRequiredViewMixin, self).dispatch(request,
#                                                             *args,
#                                                             **kwargs)
# 
# Path: django_core/views/mixins/auth.py
# class SuperuserRequiredViewMixin(LoginRequiredViewMixin):
#     """Require a logged in user to be a superuser."""
# 
#     def dispatch(self, request, *args, **kwargs):
#         if not request.user.is_superuser:
#             raise PermissionDenied
# 
#         return super(SuperuserRequiredViewMixin, self).dispatch(request,
#                                                                 *args,
#                                                                 **kwargs)


# Path: tests/test_auth_mixins.py
import uuid
from django.contrib.auth import get_user_model
from django.core.exceptions import PermissionDenied
from django.core.handlers.wsgi import WSGIHandler
from django.test import Client
from django.test import TestCase
from django_core.views import StaffRequiredViewMixin
from django_core.views import SuperuserRequiredViewMixin
from mock import patch

from __future__ import unicode_literals




class AuthMixinTests(TestCase):
    """Test case for authorization mixins."""

    def setUp(self):
        super(AuthMixinTests, self).setUpClass()
        self.username = uuid.uuid4().hex
        self.password = uuid.uuid4().hex
        self.user = get_user_model().objects.create_user(
            username=self.username,
            password=self.password
        )
        self.client = Client()

    def tearDown(self):
        super(AuthMixinTests, self).tearDownClass()
        self.user.delete()

    def test_staff_required_mixin_not_staff(self):
        """Test for mixin requiring a staff user when user isn't staff."""
        self.client.login(username=self.username, password=self.password)

        with self.assertRaises(PermissionDenied):
            request = WSGIHandler()
            request.user = self.user


            mixin = StaffRequiredViewMixin()