Exemplo n.º 1
0
def test_download_results_040(session040, requests_mock, tmp_path):
    requests_mock.get(API_URL + "/jobs/jj/results",
                      json={
                          "links": [
                              {
                                  "href": API_URL + "/dl/jjr1.tiff",
                                  "type": "image/tiff"
                              },
                              {
                                  "href": API_URL + "/dl/jjr2.tiff",
                                  "type": "image/tiff"
                              },
                          ]
                      })
    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=session040)
    target = as_path(tmp_path / "folder")
    target.mkdir()
    downloads = job.download_results(target)
    assert downloads == {
        target / "jjr1.tiff": {
            "href": API_URL + "/dl/jjr1.tiff",
            "type": "image/tiff"
        },
        target / "jjr2.tiff": {
            "href": API_URL + "/dl/jjr2.tiff",
            "type": "image/tiff"
        },
    }
    assert set(p.name for p in target.iterdir()) == {"jjr1.tiff", "jjr2.tiff"}
    with (target / "jjr1.tiff").open("rb") as f:
        assert f.read() == TIFF_CONTENT
    with (target / "jjr2.tiff").open("rb") as f:
        assert f.read() == TIFF_CONTENT
Exemplo n.º 2
0
def test_download_results(job_with_2_assets: BatchJob, tmp_path):
    job = job_with_2_assets
    target = tmp_path / "folder"
    target.mkdir()
    downloads = job.download_results(target)
    assert downloads == {
        target / "1.tiff": {"href": API_URL + "/dl/jjr1.tiff", "type": "image/tiff; application=geotiff"},
        target / "2.tiff": {"href": API_URL + "/dl/jjr2.tiff", "type": "image/tiff; application=geotiff"},
    }
    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