You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
945 B
Python
40 lines
945 B
Python
7 years ago
|
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
|