Added tests to validate that the API contract is maintained by comparing actual vs mock API responses

master
androiddrew 7 years ago
parent 753b9ffc96
commit ec0ebbc169

@ -67,3 +67,22 @@ def testing_getting_uncompleted_todos_when_todos_is_none():
uncompleted_todos = get_uncompleted_todos() uncompleted_todos = get_uncompleted_todos()
assert mock_get_todos.called assert mock_get_todos.called
assert uncompleted_todos == [] assert uncompleted_todos == []
def test_integration_contract():
actual = get_todos()
actual_keys = actual.json().pop().keys()
with patch('apitesting.services.requests.get') as mock_get:
mock_get.return_value.ok = True
mock_get.return_value.json.return_value = [{
'userId': 1,
'id': 1,
'title': 'Make the bed',
'completed': False
}]
mocked = get_todos()
mocked_keys = mocked.json().pop().keys()
assert set(actual_keys) == set(mocked_keys)

Loading…
Cancel
Save