如何让Django Rest-Framework在未经身份验证的请求上响应401?

时间:2017-12-01 11:17:10

标签: python django django-rest-framework

我使用默认的django身份验证,我有这个APIView类:

class MatchesViewSet(APIView):                                                          

    ...
    permission_classes = (permissions.IsAuthenticated,)
    ...

    def get(self, request, format=None):
        ...
        return JsonResponse(data)                              

这个测试方法:

class MainTests(TestCase):

    def setUp(self):    
        ...                                       
        self.c = Client()
        ...                                      


    def test_only_for_logged_in_users(self):          
        r = self.c.get("/api/matches")                
        self.assertEqual(r.status_code, 401)          

问题是我收到HTTP_403_FORBIDDEN而我想获得HTTP_401_UNAUTHORIZED

0 个答案:

没有答案