from unittest.mock import Mock, patch import pytest from apitesting.services import get_todos def test_request_response(): with patch('apitesting.services.requests.get') as mock_get: mock_get.return_value.ok = True response = get_todos() assert response is not None def test_getting_todos_when_response_is_ok(): todos = [{ 'userId': 1, 'id': 1, 'title': 'Make the bed', 'completed': False }] with patch('apitesting.services.requests.get') as mock_get: mock_get.return_value.ok = True mock_get.return_value.json.return_value = todos response = get_todos() assert response is not None assert response.json() == todos def testing_getting_todos_when_response_is_not_ok(): with patch('apitesting.services.requests.get') as mock_get: mock_get.return_value.ok = False response = get_todos() assert response is None