<s> import mock <EOL> import requests <EOL> try : <EOL> from io import BytesIO <EOL> except TypeError : <EOL> from StringIO import StringIO as BytesIO <EOL> import xively <EOL> import fixtures <EOL> def setup_module ( module ) : <EOL> patcher = mock . patch ( '<STR_LIT>' ) <EOL> mock_request = patcher . start ( ) <EOL> mock_request . side_effect = handle_request <EOL> module . _patcher = patcher <EOL> def teardown_module ( module ) : <EOL> module . _patcher . stop ( ) <EOL> responses_by_url = { <EOL> '<STR_LIT>' : fixtures . GET_FEED_JSON , <EOL> '<STR_LIT>' : fixtures . HISTORY_DATASTREAM_JSON , <EOL> } <EOL> def handle_request ( method , url , * args , ** kwargs ) : <EOL> response = requests . Response ( ) <EOL> response . status_code = <NUM_LIT:200> <EOL> relative_url = url . replace ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> if relative_url in responses_by_url : <EOL> response . raw = BytesIO ( responses_by_url [ relative_url ] ) <EOL> return response </s>
