小编Jam*_*a22的帖子

测试Python装饰器?

我正在为Django项目编写一些单元测试,我想知道是否可能(或必要?)来测试我为它编写的一些装饰器.

这是我写的一个装饰器的例子:

class login_required(object):

    def __init__(self, f):
        self.f = f

    def __call__(self, *args):
        request = args[0]
        if request.user and request.user.is_authenticated():
            return self.f(*args)
        return redirect('/login')
Run Code Online (Sandbox Code Playgroud)

python django unit-testing decorator python-unittest

19
推荐指数
1
解决办法
9566
查看次数