I am writing a Django class view that is supposed to run a few database checks, then create an object and send some information via SMS. The class is as follows:
class MyClass(GenericAPIView):
def send_info(content, number):
send_sms(content, number)
def post(self, request, *args, **kwargs):
#... Do a bunch of stuff
send_info(content, number)
return Response(status=200, data="Request processed")
Now I would like to test the view, of course I can't check whether and which the SMS is received.
I do have a developement variable in settings.py
that make sure for the moment that the info is just printed on screen, but I would like to use the unittest.mock
library to write a test that simply checks whether send_info()
is called, so that I won't be bother checking what info is passed (which is random).
How would I go about it?
Aucun commentaire:
Enregistrer un commentaire