def test_get_results_download_files(con100, requests_mock, tmp_path): requests_mock.get(API_URL + "/jobs/jj/results", json={ "assets": { "1.tiff": { "href": API_URL + "/dl/jjr1.tiff", "type": "image/tiff; application=geotiff" }, "2.tiff": { "href": API_URL + "/dl/jjr2.tiff", "type": "image/tiff; application=geotiff" }, } }) requests_mock.get(API_URL + "/dl/jjr1.tiff", content=TIFF_CONTENT) requests_mock.get(API_URL + "/dl/jjr2.tiff", content=TIFF_CONTENT) job = RESTJob("jj", connection=con100) assert job.list_results() == { 'assets': { '1.tiff': { 'href': 'https://oeo.test/dl/jjr1.tiff', 'type': 'image/tiff; application=geotiff' }, '2.tiff': { 'href': 'https://oeo.test/dl/jjr2.tiff', 'type': 'image/tiff; application=geotiff' } } } target = as_path(tmp_path / "folder") target.mkdir() results = job.get_results() assets = job.get_results().get_assets() assert {n: a.metadata for n, a in assets.items()} == { "1.tiff": { "href": API_URL + "/dl/jjr1.tiff", "type": "image/tiff; application=geotiff" }, "2.tiff": { "href": API_URL + "/dl/jjr2.tiff", "type": "image/tiff; application=geotiff" }, } downloads = results.download_files(target) assert set(downloads) == {target / "1.tiff", target / "2.tiff"} assert set(p.name for p in target.iterdir()) == {"1.tiff", "2.tiff"} with (target / "1.tiff").open("rb") as f: assert f.read() == TIFF_CONTENT
def test_get_results_multiple_download_single(con100, requests_mock, tmp_path): requests_mock.get(API_URL + "/jobs/jj/results", json={ "assets": { "1.tiff": { "href": API_URL + "/dl/jjr1.tiff" }, "2.tiff": { "href": API_URL + "/dl/jjr2.tiff" }, } }) job = RESTJob("jj", connection=con100) expected = r"Failed to get single asset \(name None\) from \['1.tiff', '2.tiff'\]" with pytest.raises(OpenEoClientException, match=expected): job.get_results().download_file(tmp_path / "res.tiff")
def test_get_results_download_file(con100, requests_mock, tmp_path): requests_mock.get( API_URL + "/jobs/jj/results", json={"assets": { "1.tiff": { "href": API_URL + "/dl/jjr1.tiff" }, }}) requests_mock.get(API_URL + "/dl/jjr1.tiff", content=TIFF_CONTENT) job = RESTJob("jj", connection=con100) target = as_path(tmp_path / "result.tiff") res = job.get_results().download_file(target) assert res == target with target.open("rb") as f: assert f.read() == TIFF_CONTENT
def test_get_results_download_file_to_folder(con100, requests_mock, tmp_path): requests_mock.get( API_URL + "/jobs/jj/results", json={"assets": { "1.tiff": { "href": API_URL + "/dl/jjr1.tiff" }, }}) requests_mock.get(API_URL + "/dl/jjr1.tiff", content=TIFF_CONTENT) job = RESTJob("jj", connection=con100) target = as_path(tmp_path / "folder") target.mkdir() res = job.get_results().download_file(target) assert res == target / "1.tiff" assert list(p.name for p in target.iterdir()) == ["1.tiff"] with (target / "1.tiff").open("rb") as f: assert f.read() == TIFF_CONTENT
def test_get_results_multiple_download_single_by_name(con100, requests_mock, tmp_path): requests_mock.get(API_URL + "/jobs/jj/results", json={ "assets": { "1.tiff": { "href": API_URL + "/dl/jjr1.tiff" }, "2.tiff": { "href": API_URL + "/dl/jjr2.tiff" }, } }) requests_mock.get(API_URL + "/dl/jjr1.tiff", content=TIFF_CONTENT) job = RESTJob("jj", connection=con100) target = as_path(tmp_path / "res.tiff") path = job.get_results().download_file(target, name="1.tiff") assert path == target assert list(p.name for p in tmp_path.iterdir()) == ["res.tiff"] with path.open("rb") as f: assert f.read() == TIFF_CONTENT