Skip to content

Commit

Permalink
added tests for datacube.execute
Browse files Browse the repository at this point in the history
github issue #499
  • Loading branch information
VictorVerhaert committed Jan 29, 2024
1 parent fabeaae commit ac0ec28
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/rest/datacube/test_datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import numpy as np
import pytest
from requests import JSONDecodeError
import shapely
import shapely.geometry

Expand Down Expand Up @@ -546,6 +547,33 @@ def test_download_pathlib(connection, requests_mock, tmp_path):
assert path.read_bytes() == b"tiffdata"


def test_execute_json_decode(connection, requests_mock):
requests_mock.get(API_URL + "/collections/S2", json={})
requests_mock.post(API_URL + "/result", content=b'{"foo": "bar"}')
result = connection.load_collection("S2").execute(auto_decode=True)
assert result == {"foo": "bar"}


def test_execute_decode_error(connection, requests_mock):
requests_mock.get(API_URL + "/collections/S2", json={})
requests_mock.post(API_URL + "/result", content=b"tiffdata")
with pytest.raises(JSONDecodeError):
connection.load_collection("S2").execute(auto_decode=True)


def test_execute_json_raw(connection, requests_mock):
requests_mock.get(API_URL + "/collections/S2", json={})
requests_mock.post(API_URL + "/result", content=b'{"foo": "bar"}')
result = connection.load_collection("S2").execute(auto_decode=False)
assert result.content == b'{"foo": "bar"}'


def test_execute_tiff_raw(connection, requests_mock):
requests_mock.get(API_URL + "/collections/S2", json={})
requests_mock.post(API_URL + "/result", content=b"tiffdata")
result = connection.load_collection("S2").execute(auto_decode=False)
assert result.content == b"tiffdata"

@pytest.mark.parametrize(["filename", "expected_format"], [
("result.tiff", "GTiff"),
("result.tif", "GTiff"),
Expand Down

0 comments on commit ac0ec28

Please sign in to comment.