Django.fun

how to test django views that use requests module get method?

I know how to write django test code. But I don't know how to test with views that inlcude requests.get code View code is like this.

class CertificateAPIView(APIView):
    permission_classes = [IsAuthenticated, IsOwner]

    def put(self, request):
        imp = request.data.get("imp")
        response = requests.get('another server')
        uid = response.get('uid')
        if uid == None:
            return Response(
                {"detail": ValidationError(_("Certification is failed"))},
                status=status.HTTP_400_BAD_REQUEST,
            )
        ... more condition branch logics.
        return ...  

imp value is automatically created by 'another server' that I am not managing. This code is related with another server response and check condition branch with response. But before getting response with imp vlue, we can't check whether response is error.

Answers: 0