Skip to content

Instantly share code, notes, and snippets.

@jmrnilsson
Created February 16, 2016 23:41
Show Gist options
  • Save jmrnilsson/156f9c5a3c504ccc5c8c to your computer and use it in GitHub Desktop.
Save jmrnilsson/156f9c5a3c504ccc5c8c to your computer and use it in GitHub Desktop.
patch.object for requests.json
import requests
from nose.tools import assert_equal
from mock import Mock, patch
from brew import brewery_db as client
from utils import json_load
def response_mock():
return Mock(json=Mock(return_value=json_load('brewery_db.json')))
def test_find_by_id():
with patch.object(requests, 'get', return_value=response_mock()):
actual = client.find_by_id('oeGS1')
assert_equal(actual['data']['name'], 'NAU 91')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment