Complete the code to import the Flask testing client.
from flask import Flask from flask.testing import [1] app = Flask(__name__)
The correct import for Flask's test client is FlaskClient. It allows you to simulate requests to your Flask app during tests.
Complete the code to patch the external API call using unittest.mock.
from unittest.mock import patch @patch('[1]') def test_api_call(mock_get): pass
To mock an external HTTP GET request, you patch requests.get because requests is the library used to make HTTP calls.
Fix the error in the mock setup to return a JSON response.
mock_get.return_value.[1] = lambda: {'status': 'ok'}
The requests.get method returns a response object whose json() method returns the JSON data. So you must mock json as a lambda returning the dict.
Fill both blanks to create a mock response with status code 200 and JSON data.
mock_response = MagicMock() mock_response.[1] = 200 mock_response.[2].return_value = {'message': 'success'}
The HTTP status code is set with status_code. The JSON data is returned by the json() method, so we mock its return_value.
Fill all three blanks to patch 'requests.get', create a mock response, and assert the call was made.
with patch('[1]') as mock_get: mock_get.return_value.[2] = 200 response = requests.get('http://example.com') mock_get.[3]('http://example.com')
You patch requests.get to mock the HTTP call. The mock response's status_code is set to 200. Finally, you assert the mock was called with the expected URL using assert_called_with.