Пример #1
0
    def test_user_passes_test_composition(self):
        """
        Test that the user_passes_test decorator can be applied multiple times
        (#9474).
        """
        def test1(user):
            user.decorators_applied.append('test1')
            return True

        def test2(user):
            user.decorators_applied.append('test2')
            return True

        def callback(request):
            return request.user.decorators_applied

        callback = user_passes_test(test1)(callback)
        callback = user_passes_test(test2)(callback)

        class DummyUser(object): pass
        class DummyRequest(object): pass

        request = DummyRequest()
        request.user = DummyUser()
        request.user.decorators_applied = []
        response = callback(request)

        self.assertEqual(response, ['test2', 'test1'])
Пример #2
0
    require_POST,
    require_safe,
    condition(lambda r: None, lambda r: None),

    # djangocg.views.decorators.vary
    vary_on_headers('Accept-language'),
    vary_on_cookie,

    # djangocg.views.decorators.cache
    cache_page(60*15),
    cache_control(private=True),
    never_cache,

    # djangocg.contrib.auth.decorators
    # Apply user_passes_test twice to check #9474
    user_passes_test(lambda u:True),
    login_required,
    permission_required('change_world'),

    # djangocg.contrib.admin.views.decorators
    staff_member_required,

    # djangocg.utils.functional
    lambda f: memoize(f, {}, 1),
    allow_lazy,
    lazy,
)

fully_decorated = full_decorator(fully_decorated)

class DecoratorsTest(TestCase):