diff --git a/qgreenland/test/conftest.py b/qgreenland/test/conftest.py index a67c3003..7c8e273a 100644 --- a/qgreenland/test/conftest.py +++ b/qgreenland/test/conftest.py @@ -27,8 +27,7 @@ "id": "example_online", "title": "Example online", "description": "Example layer description.", - "tags": ["foo", "bar", "baz"], - "in_package": True, + "packaging_tags": ["foo", "bar"], "input": { "dataset": { "id": "baz", @@ -48,8 +47,7 @@ "id": "example_raster", "title": "Example raster", "description": "Example layer description.", - "tags": ["foo", "bar", "baz"], - "in_package": True, + "packaging_tags": ["bar", "baz"], "input": { "dataset": { "id": "example_dataset", diff --git a/qgreenland/test/util/config/test_config_export.py b/qgreenland/test/util/config/test_config_export.py index a9b5f6f4..51af24cd 100644 --- a/qgreenland/test/util/config/test_config_export.py +++ b/qgreenland/test/util/config/test_config_export.py @@ -1,92 +1,10 @@ import csv -import json import tempfile from pathlib import Path from unittest.mock import patch -from qgreenland.test.constants import MOCK_COMPILE_PACKAGE_DIR, MOCK_RELEASE_LAYERS_DIR -from qgreenland.util.config.export import export_config_csv, export_config_manifest - - -@patch( - "qgreenland.util.layer.RELEASE_LAYERS_DIR", - new=MOCK_RELEASE_LAYERS_DIR, -) -def test_export_config_manifest(full_cfg): - common = { - "description": "Example layer description.", - # TODO: Generate this with imported function? This should be tested - # by itself elsewhere, so there's no need to test the expected output - # here too. - "layer_details": """Example layer description. - -=== Original Data Source === -Example Dataset - -Example abstract. - -Citation: -NSIDC 2020 - -Citation URL: -https://nsidc.org""", - "tags": ["foo", "bar", "baz"], - "hierarchy": ["Group", "Subgroup"], - } - with tempfile.NamedTemporaryFile("r") as tf: - export_config_manifest( - full_cfg, - output_path=Path(tf.name), - ) - - actual = json.load(tf) - - assert type(actual["qgr_version"]) is str - assert len(actual["qgr_version"]) >= 6 - del actual["qgr_version"] - - # For now, do not include online layers in the layer manifest. The - # `QGreenland Custom` QGIS Plugin does not currently support online - # layers. Once online layers are supported in the plugin, this commented out - # `online_asset` can be re-added: - # online_asset = { - # 'type': 'online', - # **full_cfg.layers['example_online'].input.asset.dict( - # include={'provider', 'url'}, - # ), - # } - expected = { - "version": "v0.1.0", - "layers": [ - # { - # 'id': 'example_online', - # 'title': 'Example online', - # 'assets': [online_asset], - # **common, - # }, - { - "id": "example_raster", - "title": "Example raster", - "assets": [ - { - "checksum": "a9a103f208179726038fa7178747a0a1", - "file": "example.tif", - "size_bytes": 287, - "type": "data", - }, - { - "checksum": "22b427acc6e4ebf57052115fdd5ac450", - "file": "example.tif.aux.xml", - "size_bytes": 332, - "type": "ancillary", - }, - ], - **common, - }, - ], - } - - assert actual == expected +from qgreenland.test.constants import MOCK_COMPILE_PACKAGE_DIR +from qgreenland.util.config.export import export_config_csv @patch( @@ -109,6 +27,7 @@ def test_export_config_csv(full_cfg): export_config_csv( full_cfg, output_path=Path(tf.name), + package_name="bar", ) actual = list(csv.DictReader(tf)) diff --git a/qgreenland/test/util/test_qgis.py b/qgreenland/test/util/test_qgis.py index 6b573e71..aed8d866 100644 --- a/qgreenland/test/util/test_qgis.py +++ b/qgreenland/test/util/test_qgis.py @@ -9,11 +9,13 @@ import qgreenland.util.qgis.project as prj from qgreenland.test.constants import MOCK_COMPILE_PACKAGE_DIR +mock_package_name = "bar" + @pytest.mark.usefixtures("setup_teardown_qgis_app") class TestQgisApp: def test_make_map_layer_online(self, online_layer_node): - result = qgl.make_map_layer(online_layer_node) + result = qgl.make_map_layer(online_layer_node, package_name=mock_package_name) assert "https://demo.mapserver.org" in result.source() assert result.dataProvider().name() == "wms" @@ -24,7 +26,7 @@ def test_make_map_layer_online(self, online_layer_node): new=MOCK_COMPILE_PACKAGE_DIR, ) def test_make_map_layer_raster(self, raster_layer_node): - result = qgl.make_map_layer(raster_layer_node) + result = qgl.make_map_layer(raster_layer_node, package_name=mock_package_name) # The result is a a raster layer assert isinstance(result, qgc.QgsRasterLayer) @@ -52,7 +54,10 @@ def test_make_map_layer_raster(self, raster_layer_node): new=MOCK_COMPILE_PACKAGE_DIR, ) def test_add_layer_metadata(self, raster_layer_node): - mock_raster_layer = qgl.make_map_layer(raster_layer_node) + mock_raster_layer = qgl.make_map_layer( + raster_layer_node, + package_name=mock_package_name, + ) qgl.add_layer_metadata(mock_raster_layer, raster_layer_node.layer_cfg) @@ -80,7 +85,11 @@ def test_add_layer_metadata(self, raster_layer_node): def test__add_layers_and_groups(self, raster_layer_node): # Test that _add_layers_and_groups works without error project = qgc.QgsProject.instance() - prj._add_layers_and_groups(project, raster_layer_node.root) + prj._add_layers_and_groups( + project, + raster_layer_node.root, + package_name=mock_package_name, + ) added_layers = list(project.mapLayers().values()) assert len(added_layers) == 1 assert added_layers[0].name() == "Example raster" @@ -91,5 +100,9 @@ def test__add_layers_and_groups(self, raster_layer_node): # Test that an exception is raised when parent groups of a layer are not # created first with pytest.raises(exc.QgrQgsLayerTreeGroupError): - prj._add_layers_and_groups(project, raster_layer_node) + prj._add_layers_and_groups( + project, + raster_layer_node, + package_name=mock_package_name, + ) project.clear()