Created
June 15, 2016 20:23
-
-
Save txomon/8fee0966e355780743f3e8de48fe43e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
@pytest.fixture(params=[ | |
{ | |
'response': {'a':'b'}, | |
'code': 201, | |
'result': True, | |
}, | |
{ | |
'response': {'error': 'masdfasd'} | |
'code': 403, | |
'result': False, | |
}]) | |
def user(request, mocker): | |
m = mocker.patch('app.http.request') | |
def user_api_mock(method, url, data, headers): | |
assert method == 'DELETE' | |
assert url == '/v1/user/{}'.format(TEST_USER_ID) | |
assert not data | |
return request.param['code'], request.param['response'] | |
m.side_effect = user_api_mock | |
return m | |
def test_user(user): | |
response = function_that_uses_the_mocked_function() | |
if user: | |
assert response.status_code == 201 | |
else: | |
assert response.status_code == 403 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment