def test_class_views(self): # class decorator can handle class_view = c(View) class_view.as_view()(self.request, pk=1) # method decorator cannot handle method_view = m(View) self.assertFalse(hasattr(method_view, 'as_view')) # function decorator cannot handle function_view = f(View) self.assertFalse(hasattr(method_view, 'as_view'))
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 class View(BaseView):
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: # classbase generic view related test will not be run so never mind.