def test_raise_make_request(urlopen): error = http.HTTPError( 'http://example.com/', 404, 'Not Found', None, None ) error.read = lambda: b'o' urlopen.side_effect = error resp, content = make_request('http://example.com') assert resp.code == 404 assert b'o' in content
def test_make_request(urlopen): urlopen.return_value = Response( b'{"foo": "bar"}', headers={'status-code': 200} ) resp, content = make_request('http://example.com') assert resp.code == 200 assert b'foo' in content resp, content = make_request('http://example.com/', method='GET', data={'wd': 'flask-oauthlib'}) assert resp.code == 200 assert b'foo' in content resp, content = make_request('http://example.com/', data={'wd': 'flask-oauthlib'}) assert resp.code == 200 assert b'foo' in content