def test_download_all(tmpdir): api = SentinelAPI(**_api_auth) # From https://scihub.copernicus.eu/apihub/odata/v1/Products?$top=5&$orderby=ContentLength filenames = ["S1A_WV_OCN__2SSH_20150603T092625_20150603T093332_006207_008194_521E", "S1A_WV_OCN__2SSV_20150526T211029_20150526T211737_006097_007E78_134A", "S1A_WV_OCN__2SSV_20150526T081641_20150526T082418_006090_007E3E_104C"] ids = list(api.query_raw(" OR ".join(filenames))) assert len(ids) == len(filenames) # Download normally product_infos, failed_downloads = api.download_all(ids, str(tmpdir)) assert len(failed_downloads) == 0 assert len(product_infos) == len(filenames) for product_id, product_info in product_infos.items(): pypath = py.path.local(product_info['path']) assert pypath.purebasename in filenames assert pypath.check(exists=1, file=1) assert pypath.size() == product_info["size"] # Force one download to fail id, product_info = list(product_infos.items())[0] path = product_info['path'] py.path.local(path).remove() with requests_mock.mock(real_http=True) as rqst: url = "https://scihub.copernicus.eu/apihub/odata/v1/Products('%s')?$format=json" % id json = api.session.get(url).json() json["d"]["Checksum"]["Value"] = "00000000000000000000000000000000" rqst.get(url, json=json) product_infos, failed_downloads = api.download_all( ids, str(tmpdir), max_attempts=1, checksum=True) assert len(failed_downloads) == 1 assert len(product_infos) + len(failed_downloads) == len(filenames) assert id in failed_downloads
def test_get_products_size(products): assert SentinelAPI.get_products_size(products) == 90.94 # load a new very small query api = SentinelAPI(**_api_auth) with my_vcr.use_cassette('test_get_products_size'): products = api.query_raw("S1A_WV_OCN__2SSH_20150603T092625_20150603T093332_006207_008194_521E") assert len(products) > 0 # Rounded to zero assert SentinelAPI.get_products_size(products) == 0
def test_get_products_size(products): assert SentinelAPI.get_products_size(products) == 90.94 # load a new very small query api = SentinelAPI(**_api_auth) with my_vcr.use_cassette('test_get_products_size'): products = api.query_raw( "S1A_WV_OCN__2SSH_20150603T092625_20150603T093332_006207_008194_521E" ) assert len(products) > 0 # Rounded to zero assert SentinelAPI.get_products_size(products) == 0
def test_download_all(tmpdir): api = SentinelAPI(**_api_auth) # From https://scihub.copernicus.eu/apihub/odata/v1/Products?$top=5&$orderby=ContentLength filenames = [ "S1A_WV_OCN__2SSH_20150603T092625_20150603T093332_006207_008194_521E", "S1A_WV_OCN__2SSV_20150526T211029_20150526T211737_006097_007E78_134A", "S1A_WV_OCN__2SSV_20150526T081641_20150526T082418_006090_007E3E_104C" ] ids = list(api.query_raw(" OR ".join(filenames))) assert len(ids) == len(filenames) # Download normally product_infos, failed_downloads = api.download_all(ids, str(tmpdir)) assert len(failed_downloads) == 0 assert len(product_infos) == len(filenames) for product_id, product_info in product_infos.items(): pypath = py.path.local(product_info['path']) assert pypath.purebasename in filenames assert pypath.check(exists=1, file=1) assert pypath.size() == product_info["size"] # Force one download to fail id, product_info = list(product_infos.items())[0] path = product_info['path'] py.path.local(path).remove() with requests_mock.mock(real_http=True) as rqst: url = "https://scihub.copernicus.eu/apihub/odata/v1/Products('%s')?$format=json" % id json = api.session.get(url).json() json["d"]["Checksum"]["Value"] = "00000000000000000000000000000000" rqst.get(url, json=json) product_infos, failed_downloads = api.download_all(ids, str(tmpdir), max_attempts=1, checksum=True) assert len(failed_downloads) == 1 assert len(product_infos) + len(failed_downloads) == len(filenames) assert id in failed_downloads
def test_invalid_query(): api = SentinelAPI(**_api_auth) with pytest.raises(SentinelAPIError) as excinfo: api.query_raw("xxx:yyy") assert excinfo.value.msg is not None