Exemplo n.º 1
0
def test_fetch_json_url(mocker):
    mocker.patch('isimip_data.metadata.utils.urlopen',
                 MockResponse(read_data=json.dumps(test_data)))
    assert fetch_json('http://example.com') == test_data
Exemplo n.º 2
0
def test_fetch_json_path_broken(mocker):
    mocker.patch('isimip_data.metadata.utils.open',
                 mocker.mock_open(read_data='{'))
    assert fetch_json('/path/to/example') is None
Exemplo n.º 3
0
def test_fetch_json_path(mocker):
    mocker.patch('isimip_data.metadata.utils.open',
                 mocker.mock_open(read_data=json.dumps(test_data)))
    assert fetch_json('/path/to/example') == test_data
Exemplo n.º 4
0
def test_fetch_json_path_ioerror(mocker):
    mocked_open = mocker.patch('isimip_data.metadata.utils.open',
                               mocker.mock_open())
    mocked_open.side_effect = IOError
    assert fetch_json('/path/to/example') is None
Exemplo n.º 5
0
def test_fetch_json_url_http_error(mocker):
    mocker.patch('isimip_data.metadata.utils.urlopen',
                 MockResponse(http_error=True))
    assert fetch_json('http://example.com') is None