Skip to content

Instantly share code, notes, and snippets.

@txomon
Created June 15, 2016 20:23
Show Gist options
  • Save txomon/8fee0966e355780743f3e8de48fe43e3 to your computer and use it in GitHub Desktop.
Save txomon/8fee0966e355780743f3e8de48fe43e3 to your computer and use it in GitHub Desktop.
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