Automate testing a function using MagicMock to mock a dependency
Preconditions (2)
Step 1: Create a function 'get_data' that calls an external API function 'fetch_api_data'.
Step 2: Mock 'fetch_api_data' using MagicMock to return a fixed dictionary {'key': 'value'}.
Step 3: Call 'get_data' and verify it returns the mocked dictionary.
Step 4: Verify that 'fetch_api_data' was called exactly once during the test.
✅ Expected Result: The test passes confirming 'get_data' returns the mocked data and 'fetch_api_data' was called once.