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_download_result_040(session040, requests_mock, tmp_path): requests_mock.get(API_URL + "/jobs/jj/results", json={"links": [ { "href": API_URL + "/dl/jjr1.tiff" }, ]}) requests_mock.get(API_URL + "/dl/jjr1.tiff", content=TIFF_CONTENT) job = RESTJob("jj", connection=session040) assert job.list_results() == { 'links': [{ 'href': 'https://oeo.test/dl/jjr1.tiff' }] } target = as_path(tmp_path / "result.tiff") res = job.download_result(target) assert res == target with target.open("rb") as f: assert f.read() == TIFF_CONTENT
def test_download_result(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) assert job.list_results() == { 'assets': { '1.tiff': { 'href': 'https://oeo.test/dl/jjr1.tiff' } } } target = as_path(tmp_path / "result.tiff") res = job.download_result(target) assert res == target with target.open("rb") as f: assert f.read() == TIFF_CONTENT
def test_download_result_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) assert job.list_results() == { 'assets': { '1.tiff': { 'href': 'https://oeo.test/dl/jjr1.tiff' } } } target = as_path(tmp_path / "folder") target.mkdir() res = job.download_result(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