UPDATE
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
from decimal import Decimal
|
||||
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from location_data.openeo_service import (
|
||||
build_empty_metric_payload,
|
||||
linear_to_db,
|
||||
merge_metric_results,
|
||||
parse_aggregate_spatial_response,
|
||||
)
|
||||
|
||||
|
||||
class OpenEOServiceParsingTests(SimpleTestCase):
|
||||
def test_parse_feature_collection_results(self):
|
||||
payload = {
|
||||
"type": "FeatureCollection",
|
||||
"features": [
|
||||
{
|
||||
"type": "Feature",
|
||||
"id": "cell-1",
|
||||
"properties": {"mean": 0.61},
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"id": "cell-2",
|
||||
"properties": {"mean": 0.47},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
result = parse_aggregate_spatial_response(payload, "ndvi")
|
||||
|
||||
self.assertEqual(result["cell-1"]["ndvi"], 0.61)
|
||||
self.assertEqual(result["cell-2"]["ndvi"], 0.47)
|
||||
|
||||
def test_parse_mapping_results(self):
|
||||
payload = {
|
||||
"cell-1": {"mean": 12.4},
|
||||
"cell-2": {"mean": 15.1},
|
||||
}
|
||||
|
||||
result = parse_aggregate_spatial_response(payload, "lst_c")
|
||||
|
||||
self.assertEqual(result["cell-1"]["lst_c"], 12.4)
|
||||
self.assertEqual(result["cell-2"]["lst_c"], 15.1)
|
||||
|
||||
def test_linear_to_db(self):
|
||||
self.assertEqual(linear_to_db(10.0), 10.0)
|
||||
self.assertEqual(linear_to_db(Decimal("1.0")), 0.0)
|
||||
self.assertIsNone(linear_to_db(0))
|
||||
self.assertIsNone(linear_to_db(-1))
|
||||
|
||||
def test_merge_metric_results(self):
|
||||
target = {"cell-1": build_empty_metric_payload()}
|
||||
|
||||
merge_metric_results(
|
||||
target,
|
||||
{
|
||||
"cell-1": {"ndvi": 0.5},
|
||||
"cell-2": {"ndwi": 0.2},
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(target["cell-1"]["ndvi"], 0.5)
|
||||
self.assertEqual(target["cell-2"]["ndwi"], 0.2)
|
||||
self.assertIn("soil_vv_db", target["cell-2"])
|
||||
Reference in New Issue
Block a user