Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! fixup! Issue #404/PR#481 test_data…
Browse files Browse the repository at this point in the history
…cube100 streamlining
  • Loading branch information
soxofaan committed Oct 18, 2023
1 parent 0788181 commit 93b423a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
31 changes: 30 additions & 1 deletion tests/rest/datacube/test_datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,6 @@ def dummy_backend_setup(self, dummy_backend):
# (Validation supported by backend) follow explicit `validate` toggle regardless of auto_validate
({"validation": True}, False, True, True),
({"validation": True}, True, False, False),
# TODO: add case with broken validation
]

@pytest.mark.parametrize(
Expand All @@ -891,6 +890,22 @@ def test_cube_download_validation(self, dummy_backend, connection, validate, val
assert dummy_backend.validation_requests == []
assert caplog.messages == []

@pytest.mark.parametrize("api_capabilities", [{"validation": True}])
def test_cube_download_validation_broken(self, dummy_backend, connection, requests_mock, caplog, tmp_path):
"""Test resilience against broken validation response."""
requests_mock.post(
connection.build_url("/validation"), status_code=500, json={"code": "Internal", "message": "nope!"}
)

cube = connection.load_collection("S2")

output = tmp_path / "result.tiff"
cube.download(outputfile=output, validate=True)
assert output.read_bytes() == b'{"what?": "Result data"}'
assert dummy_backend.get_sync_pg() == self._PG_S2_SAVE

assert caplog.messages == ["Preflight process graph validation failed: [500] Internal: nope!"]

@pytest.mark.parametrize(
["api_capabilities", "auto_validate", "validate", "validation_expected"],
_VALIDATION_PARAMETER_SETS,
Expand Down Expand Up @@ -936,6 +951,20 @@ def test_cube_create_job_validation(
assert dummy_backend.validation_requests == []
assert caplog.messages == []

@pytest.mark.parametrize("api_capabilities", [{"validation": True}])
def test_cube_create_job_validation_broken(self, dummy_backend, connection, requests_mock, caplog, tmp_path):
"""Test resilience against broken validation response."""
requests_mock.post(
connection.build_url("/validation"), status_code=500, json={"code": "Internal", "message": "nope!"}
)

cube = connection.load_collection("S2")
job = cube.create_job(validate=True)
assert job.job_id == "job-000"
assert dummy_backend.get_batch_pg() == self._PG_S2_SAVE

assert caplog.messages == ["Preflight process graph validation failed: [500] Internal: nope!"]

@pytest.mark.parametrize(
["api_capabilities", "auto_validate", "validate", "validation_expected"],
_VALIDATION_PARAMETER_SETS,
Expand Down
14 changes: 13 additions & 1 deletion tests/rest/datacube/test_vectorcube.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,6 @@ def dummy_backend_setup(self, dummy_backend):
# (Validation supported by backend) follow explicit `validate` toggle regardless of auto_validate
({"validation": True}, False, True, True),
({"validation": True}, True, False, False),
# TODO: add case with broken validation
]

@pytest.mark.parametrize(
Expand Down Expand Up @@ -608,6 +607,19 @@ def test_vectorcube_create_job_validation(self, dummy_backend, connection, valid
assert dummy_backend.validation_requests == []
assert caplog.messages == []

def test_vectorcube_create_job_validation_broken(self, dummy_backend, connection, requests_mock, caplog):
"""Test resilience against broken validation response."""
requests_mock.post(
connection.build_url("/validation"), status_code=500, json={"code": "Internal", "message": "nope!"}
)
vector_cube = VectorCube.load_geojson(connection=connection, data={"type": "Point", "coordinates": [1, 2]})

job = vector_cube.create_job(validate=True)
assert job.job_id == "job-000"
assert dummy_backend.get_batch_pg() == self._PG_GEOJSON_SAVE

assert caplog.messages == ["Preflight process graph validation failed: [500] Internal: nope!"]

@pytest.mark.parametrize(
["api_capabilities", "auto_validate", "validate", "validation_expected"],
_VALIDATION_PARAMETER_SETS,
Expand Down

0 comments on commit 93b423a

Please sign in to comment.