Skip to content

Commit

Permalink
add first integration tests for indicator and wms no-time collections
Browse files Browse the repository at this point in the history
  • Loading branch information
lubojr committed Jun 28, 2024
1 parent 1b20a99 commit b59813d
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
- name: Lint
run: python -m ruff check --no-cache .
- name: Test
run: python -m pytest -p no:cacheprovider
run: cd tests && python -m pytest -p no:cacheprovider
116 changes: 114 additions & 2 deletions tests/test_generate.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,114 @@
def test_create_test_run():
assert True
import json
import os
import shutil
from datetime import datetime

import pytest
from eodash_catalog.generate_indicators import process_catalog_file
from eodash_catalog.utils import (
Options,
)


@pytest.fixture
def test_options():
outputpath = "build"
# yield instead of return to run code below yield after fixture released from all tests
yield Options(
catalogspath="testing-catalogs",
collectionspath="testing-collections",
indicatorspath="testing-indicators",
outputpath=outputpath,
vd=None,
ni=None,
tn=None,
collections=[],
)
# cleanup output after tests finish
shutil.rmtree(outputpath)


@pytest.fixture()
def catalog_output_folder(process_catalog_fixture, test_options):
# not-used fixture needs to be here to trigger catalog generation
return os.path.join(test_options.outputpath, "testing-catalog-id")


@pytest.fixture
def catalog_location(test_options):
file_path = os.path.join(test_options.catalogspath, "testing.yaml")
return file_path


@pytest.fixture
def process_catalog_fixture(catalog_location, test_options):
process_catalog_file(catalog_location, test_options)


def test_catalog_file_exists(catalog_output_folder):
# test if catalog was created in target location
assert os.path.exists(catalog_output_folder)


def test_collection_no_wms_has_a_single_item(catalog_output_folder):
# test that following collections were created as we expect it
collection_name = "imperviousness_density_2018"
start_date = "1970-01-01T00:00:00Z"
root_collection_path = os.path.join(catalog_output_folder, collection_name)
with open(os.path.join(root_collection_path, "collection.json")) as fp:
collection_json = json.load(fp)
# test that custom bbox is set
assert [-180, -85, 180, 85] in collection_json["extent"]["spatial"]["bbox"]
# test that time interval is 1970-today
assert collection_json["extent"]["temporal"]["interval"][0][0] == start_date
assert (
datetime.today().date()
== datetime.fromisoformat(
collection_json["extent"]["temporal"]["interval"][0][1]
).date()
)
child_collection_path = os.path.join(root_collection_path, collection_name)
child_child_collection_path = os.path.join(child_collection_path, collection_name)
item_dir = os.path.join(child_child_collection_path, "1970")
item_paths = os.listdir(item_dir)
assert len(item_paths) == 1
with open(os.path.join(item_dir, item_paths[0])) as fp:
item_json = json.load(fp)
assert item_json["properties"]["start_datetime"] == start_date
assert item_json["collection"] == collection_name


def test_indicator_groups_collections(catalog_output_folder):
collection_name = "test_indicator_grouping_collections"
root_collection_path = os.path.join(catalog_output_folder, collection_name)
with open(os.path.join(root_collection_path, "collection.json")) as fp:
indicator_json = json.load(fp)
# test that collection has two child links
child_links = [link for link in indicator_json["links"] if link["rel"] == "child"]
assert len(child_links) == 2
# test that summaries are aggregating individual properties of collections
assert len(indicator_json["summaries"]["themes"]) == 2
# test that bbox aggregating works
indicator_bbox = indicator_json["extent"]["spatial"]["bbox"]
assert len(indicator_bbox) == 3
assert [-45.24, 61.13, -35.15, 65.05] in indicator_bbox
assert [-145.24, -61.13, -135.15, -65.05] in indicator_bbox


def test_baselayers_and_overlays_added(catalog_output_folder):
collection_name = "imperviousness_density_2018"
root_collection_path = os.path.join(catalog_output_folder, collection_name)
with open(os.path.join(root_collection_path, "collection.json")) as fp:
collection_json = json.load(fp)
baselayer_links = [
link
for link in collection_json["links"]
if link.get("roles") and "baselayer" in link["roles"]
]
overlay_links = [
link
for link in collection_json["links"]
if link.get("roles") and "overlay" in link["roles"]
]
assert len(baselayer_links) == 1
assert len(overlay_links) == 1
10 changes: 10 additions & 0 deletions tests/testing-catalogs/testing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
id: "testing-catalog-id"
title: "testing catalog for integration tests"
description: "testing catalog"
endpoint: "https://gtif-cerulean.github.io/catalog/cerulean/"
default_base_layers: "testing-layers/baselayers"
default_overlay_layers: "testing-layers/overlays"
assets_endpoint: "https://raw.githubusercontent.com/eurodatacube/eodash-assets/main/"
collections:
- test_wms_no_time
- test_indicator
19 changes: 19 additions & 0 deletions tests/testing-collections/test_tif_demo_1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Name: test_tif_demo_1
Title: test_tif_demo_1
EodashIdentifier: test_tif_demo_1
Description: ''
Themes:
- cryosphere
Tags:
- placeholder
Satellite:
- placeholder
Sensor:
- placeholder
Agency:
- ESA
Image: Polartep_SeaIceDetection_tif_demo/thumbnail.png # existing file
Resources:
- Name: Collection-only
EndPoint: Collection-only
OverwriteBBox: [-45.24, 61.13, -35.15, 65.05]
19 changes: 19 additions & 0 deletions tests/testing-collections/test_tif_demo_2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Name: test_tif_demo_2
Title: test_tif_demo_2
EodashIdentifier: test_tif_demo_2
Description: ''
Themes:
- agriculture
Tags:
- placeholder
Satellite:
- placeholder
Sensor:
- placeholder
Agency:
- ESA
Image: Polartep_SeaIceDetection_tif_demo/thumbnail.png # existing file
Resources:
- Name: Collection-only
EndPoint: Collection-only
OverwriteBBox: [-145.24, -61.13, -135.15, -65.05]
21 changes: 21 additions & 0 deletions tests/testing-collections/test_wms_no_time.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Name: imperviousness_density_2018
Title: Imperviousness Density 2018 WMS
EodashIdentifier: IMD
Description: CLMS Imperviousness Density 2018 10m resolution.
Themes:
- example theme
Tags:
- example tag
DataSource:
Spaceborne:
Satellite:
- example satellite
Sensor:
- example sensorname
Agency:
- EEA
Resources:
- EndPoint: https://image.discomap.eea.europa.eu/arcgis/services/GioLandPublic/HRL_ImperviousnessDensity_2018/ImageServer/WMSServer
Name: WMS
LayerId: 'HRL_ImperviousnessDensity_2018:IMD_MosaicSymbology.rft'
Version: 1.3.0
7 changes: 7 additions & 0 deletions tests/testing-indicators/test_indicator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Name: test_indicator_grouping_collections
Title: test_indicator_grouping_collections
EodashIdentifier: test_indicator_1
Description: 'test_indicator_1_description'
Collections:
- test_tif_demo_1
- test_tif_demo_2
7 changes: 7 additions & 0 deletions tests/testing-layers/baselayers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- id: cloudless-2022
name: EOxCloudless 2022
url: '//s2maps-tiles.eu/wmts/1.0.0/s2cloudless-2022_3857/default/g/{z}/{y}/{x}.jpeg'
media_type: image/jpeg
attribution: '{ EOxCloudless 2022: <a xmlns:dct="http://purl.org/dc/terms/" href="//s2maps.eu" target="_blank" property="dct:title">Sentinel-2 cloudless - s2maps.eu</a> by <a xmlns:cc="http://creativecommons.org/ns#" href="//eox.at" target="_blank" property="cc:attributionName" rel="cc:attributionURL">EOX IT Services GmbH</a> (Contains modified Copernicus Sentinel data 2022) }'
maxNativeZoom: 17
protocol: 'xyz'
7 changes: 7 additions & 0 deletions tests/testing-layers/overlays.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- id: overlay_bright
name: 'Overlay labels'
url: '//s2maps-tiles.eu/wmts/1.0.0/overlay_base_bright_3857/default/g/{z}/{y}/{x}.png'
attribution: '{ Overlay: Data &copy; <a href="http://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors, Made with Natural Earth, Rendering &copy; <a href="//eox.at" target="_blank">EOX</a> }'
visible: true
maxNativeZoom: 14
protocol: 'xyz'

0 comments on commit b59813d

Please sign in to comment.