def test_permission_required(self): # function functional_view = p(view_func) functional_view(self.request, queryset=self.queryset, object_id=1) # method method_view = p(View.dispatch) method_view(View(), self.request, pk=1) # class class_view = p(View) class_view.as_view()(self.request, pk=1)
from permission.utils.handlers import registry from permission.tests.compatibility import skipIf from permission.tests.compatibility import MagicMock from permission.tests.test_decorators.utils import create_mock_handler from permission.tests.test_decorators.utils import create_mock_request from permission.tests.test_decorators.utils import create_mock_queryset from permission.tests.test_decorators.utils import create_mock_model from permission.tests.test_decorators.utils import create_mock_view_func from permission.tests.test_decorators.utils import create_mock_view_class from permission.decorators.functionbase import permission_required as f from permission.decorators.methodbase import permission_required as m from permission.decorators.classbase import permission_required as c from permission.decorators import permission_required as p p = p('permission.add_article') c = c('permission.add_article') m = m('permission.add_article') f = f('permission.add_article') model = create_mock_model() instance = model() def view_func(request, *args, **kwargs): assert isinstance(request, HttpRequest) try: from django.views.generic import View as BaseView except ImportError: # classbase generic view related test will not be run so never mind. BaseView = object
from django.core.exceptions import PermissionDenied from permission.utils.handlers import registry from permission.decorators.functionbase import permission_required as f from permission.decorators.methodbase import permission_required as m from permission.decorators.classbase import permission_required as c from permission.decorators import permission_required as p from permission.tests.compat import skipIf from permission.tests.compat import MagicMock from permission.tests.test_decorators.utils import create_mock_handler from permission.tests.test_decorators.utils import create_mock_request from permission.tests.test_decorators.utils import create_mock_queryset from permission.tests.test_decorators.utils import create_mock_model from permission.tests.test_decorators.utils import create_mock_view_func from permission.tests.test_decorators.utils import create_mock_view_class p = p('permission.add_article') c = c('permission.add_article') m = m('permission.add_article') f = f('permission.add_article') model = create_mock_model() instance = model() def view_func(request, *args, **kwargs): assert isinstance(request, HttpRequest) try: from django.views.generic import View as BaseView except ImportError: