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
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
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
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
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