我使用默认的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