I have a Django view that I want to unit test it but the problem is in some line of the function it calls another function which has a send email function and this send email function has a celery task inside it. I don't know what to do to surpass this function call because when the debugger hits the send email function it stops and does nothing which I think is because of the celery task.
Due to this problem, my unit test can't run completely.
So I would be happy if someone could tell me what to do then. My own solution was to mock the sending email function but it doesn't work. I don't know what to do now.
here is the code example of what happens during the view function.
view_funtion():
...
function_a is called here
function_a():
...
send_email_function is called here
send_email_function():
some code here and initialization of the email template
celery_task.delay()
please let me know if I should add more detail. Thanks.
Update:
this is the unit test function
@patch('path_to_send_email_function')
def test_view_function(self, mock_send_email):
mock_send_email.return_value = None
...
I also use the API request factory which is for the Django rest framework for testing the view. The execution steps are in the body of the test the view function is called and it executes until function_a is called and then send_email_function is called in the body of function_a.