在Django项目中测试注销功能的问题

时间:2019-06-06 11:15:08

标签: python django unit-testing django-rest-framework

当我测试此功能时,响应状态为403。

def test_logout(self):
    request = self.factory.post('http/api/logout/')
    request.user = self.user1
    response = logout(request)
    self.assertEqual(response.status_code, status.HTTP_200_OK)

我的身份验证视图:

def login(request):
serializer = AuthTokenSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
user = serializer.validated_data['user']
token, created = Token.objects.get_or_create(user=user)
return Response({'token': token.key})

def logout(request):
request.auth.delete()
return Response(status=status.HTTP_204_NO_CONTENT)

如何测试注销功能视图?

0 个答案:

没有答案