コード例 #1
0
    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'))
コード例 #2
0
    def test_function_views(self):

        if django.VERSION >= (1, 3):
            # class decorator cannot handle
            self.assertRaises(AttributeError, c, view_func)
            # method decorator can handle
            method_view = m(view_func)
            method_view(self.request, self.queryset, object_id=1)

        # function decorator can handle
        function_view = f(view_func)
        function_view(self.request, self.queryset, object_id=1)
コード例 #3
0
    def test_function_views(self):

        if django.VERSION >= (1, 3):
            # class decorator cannot handle
            self.assertRaises(AttributeError, c, view_func)
            # method decorator can handle
            method_view = m(view_func)
            method_view(self.request, self.queryset, object_id=1)

        # function decorator can handle
        function_view = f(view_func)
        function_view(self.request, self.queryset, object_id=1)
コード例 #4
0
    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'))
コード例 #5
0
    def test_method_views(self):
        view_method = View.dispatch

        # class decorator cannot handle
        self.assertRaises(AttributeError, c, View.dispatch)

        # method decorator can handle
        method_view = m(View.dispatch)
        method_view(View(), self.request, pk=1)

        # function decorators cannot handle
        function_view = f(View.dispatch)
        self.assertRaises(AttributeError, function_view,
                          View(), self.request, pk=1)
コード例 #6
0
    def test_method_views(self):
        view_method = View.dispatch

        # class decorator cannot handle
        self.assertRaises(AttributeError, c, View.dispatch)

        # method decorator can handle
        method_view = m(View.dispatch)
        method_view(View(), self.request, pk=1)

        # function decorators cannot handle
        function_view = f(View.dispatch)
        self.assertRaises(AttributeError,
                          function_view,
                          View(),
                          self.request,
                          pk=1)
コード例 #7
0
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):
    def dispatch(self, request, *args, **kwargs):
コード例 #8
0
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.
    BaseView = object