Django - Testing Django Applications
You want to test a Django view that calls an external payment API. Which approach correctly mocks the external call and verifies the view handles a failure response gracefully?
from unittest.mock import patch
from django.test import Client
@patch('payments.api.call_payment')
def test_payment_failure(mock_call):
mock_call.return_value = {'status': 'error', 'code': 500}
client = Client()
response = client.post('/pay/')
print(response.status_code)
What should you add to the test to check the view's behavior?