Complete the code to import the mock library for testing.
from unittest import [1]
The patch decorator is imported from unittest.mock to create mocks for external services.
Complete the code to patch the external API call in the test function.
@mock.[1]('myapp.services.external_api_call') def test_api_call(mock_api): pass
The @mock.patch decorator replaces the specified function with a mock during the test.
Fix the error in the mock setup to return a specific value from the external service.
mock_api.[1] = {'status': 'ok'}
The return_value attribute sets what the mock returns when called.
Fill both blanks to assert the mock was called exactly once with the expected argument.
mock_api.[1]([2])
Use assert_called_once_with to check the mock was called once with the given argument.
Fill all three blanks to create a mock context manager that returns a mock response with status code 200.
with mock.[1]('myapp.services.get_response') as [2]: [3].return_value.status_code = 200
Use patch as a context manager to replace the function. The mock object is assigned to a variable (here mock_obj) to set its return value.