|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
from unittest.mock import Mock, patch
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from apitesting.services import get_todos
|
|
|
|
|
from apitesting.services import get_todos, get_uncompleted_todos
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_request_response():
|
|
|
|
@ -37,3 +37,33 @@ def testing_getting_todos_when_response_is_not_ok():
|
|
|
|
|
response = get_todos()
|
|
|
|
|
|
|
|
|
|
assert response is None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_getting_uncompleted_todos_when_todos_is_not_none():
|
|
|
|
|
todo1 = {
|
|
|
|
|
'userId': 1,
|
|
|
|
|
'id': 1,
|
|
|
|
|
'title': 'Make the bed',
|
|
|
|
|
'completed': False
|
|
|
|
|
}
|
|
|
|
|
todo2 = {
|
|
|
|
|
'userId': 1,
|
|
|
|
|
'id': 2,
|
|
|
|
|
'title': 'Walk the dog',
|
|
|
|
|
'completed': True
|
|
|
|
|
}
|
|
|
|
|
with patch('apitesting.services.get_todos') as mock_get_todos:
|
|
|
|
|
mock_get_todos.return_value = Mock()
|
|
|
|
|
mock_get_todos.return_value.json.return_value = [todo1, todo2]
|
|
|
|
|
|
|
|
|
|
uncompleted_todos = get_uncompleted_todos()
|
|
|
|
|
|
|
|
|
|
assert mock_get_todos.called
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def testing_getting_uncompleted_todos_when_todos_is_none():
|
|
|
|
|
with patch('apitesting.services.get_todos') as mock_get_todos:
|
|
|
|
|
mock_get_todos.return_value = None
|
|
|
|
|
uncompleted_todos = get_uncompleted_todos()
|
|
|
|
|
assert mock_get_todos.called
|
|
|
|
|
assert uncompleted_todos == []
|
|
|
|
|