samedi 11 juillet 2020

Testing a class based Django view which returns a JsonReponse

What is the proper way to test a class based Django view which returns a JsonResponse type. For example, the beginning of my class looks like this:

class MyView(LoginRequiredMixin, View):

    def get(self, request):

        return JsonResponse({
            "status": 200,
            "message": "message to return."
        })

I have similar 'post' and 'delete' functions. The url /myview is connected to this view. When I attempt something like this:

c = Client()
response = c.get('/myview')

'response' is a HttpResponsePermanentRedirect type, and I am unsure how the JSON data can be obtained from that.

Aucun commentaire:

Enregistrer un commentaire