

def test_json_response():

    class HTTPError(Exception):
        pass
    response = Mock()
    response.json.return_value = {
        'a': 1,
        'b': {
            'c': 2,
            'd': 3,
        },
    }
    response.raise_for_status.side_effect = [None, HTTPError()]
    mock = Mock()
    mock.url = 'http://example.com'
    mock.http_client.request.return_value = response
    json = JSONResponseProperty(method='POST')
    rv = json.provide_value(mock)
    assert (rv == {
        'a': 1,
        'b': {
            'c': 2,
            'd': 3,
        },
    })
    response.raise_for_status.assert_called_once_with()
    mock.http_client.request.assert_called_once_with(method='POST', url='http://example.com')
    with raises(HTTPError):
        json.provide_value(mock)

dataset/ETHPy150Open douban/brownant/tests/test_pipeline/test_network.py test_json_response/original