tests.py 文件源码

python
阅读 85 收藏 0 点赞 0 评论 0

项目:sdining 作者: Lurance 项目源码 文件源码
def test_method(self):
        post = rf.post('/')
        get = rf.get('/')

        class LimitPostView(RatelimitMixin, View):
            ratelimit_group = 'cbv:method'
            ratelimit_key = 'ip'
            ratelimit_method = ['POST']
            ratelimit_rate = '1/m'

            def post(self, request, *args, **kwargs):
                return request.limited
            get = post

        class LimitGetView(RatelimitMixin, View):
            ratelimit_group = 'cbv:method'
            ratelimit_key = 'ip'
            ratelimit_method = ['POST', 'GET']
            ratelimit_rate = '1/m'

            def post(self, request, *args, **kwargs):
                return request.limited
            get = post

        limit_post = LimitPostView.as_view()
        limit_get = LimitGetView.as_view()

        assert not limit_post(post), 'Do not limit first POST.'
        assert limit_post(post), 'Limit second POST.'
        assert not limit_post(get), 'Do not limit GET.'

        assert limit_get(post), 'Limit first POST.'
        assert limit_get(get), 'Limit first GET.'
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号