From 9394ee31de28556af0eac876c411d52dd8f9ba29 Mon Sep 17 00:00:00 2001 From: Jenna Ritvanen Date: Mon, 20 Nov 2023 09:23:34 +0200 Subject: [PATCH] Add test for missing config --- georest/tests/test_geoserver.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/georest/tests/test_geoserver.py b/georest/tests/test_geoserver.py index 7703098..33b2679 100644 --- a/georest/tests/test_geoserver.py +++ b/georest/tests/test_geoserver.py @@ -8,7 +8,7 @@ """Unittests for Geoserver REST methods.""" from copy import deepcopy -from unittest import mock +from unittest import mock, TestCase @mock.patch("georest.Catalog") @@ -298,6 +298,16 @@ def test_get_layer_coverage(): "layer_name_template": "{productname}_{area}", } +ADD_FILE_TO_MOSAIC_FAIL_CONFIG = { + "host": "http://host/", + "user": "user", + "passwd": "passwd", + "workspace": "satellite", + "geoserver_target_dir": "/mnt/data", + "keep_subpath": False, + "file_pattern": "{area}_{productname}.tif", +} + @mock.patch("georest.utils.file_in_granules") @mock.patch("georest.connect_to_gs_catalog") @@ -385,6 +395,25 @@ def test_add_file_to_mosaic_failed_request(connect_to_gs_catalog): add_file_to_mosaic(config, fname_in) +@mock.patch("georest.connect_to_gs_catalog") +def test_add_file_to_mosaic_missing_config(connect_to_gs_catalog): + """Test that a failed file addition is handled.""" + + from georest import add_file_to_mosaic + + config = deepcopy(ADD_FILE_TO_MOSAIC_FAIL_CONFIG) + + add_granule = mock.MagicMock() + cat = mock.MagicMock(add_granule=add_granule) + connect_to_gs_catalog.return_value = cat + + fname_in = "/path/to/europe_airmass.tif" + + # Check that failed request is handled + with TestCase().assertRaises(ValueError): + add_file_to_mosaic(config, fname_in) + + @mock.patch("georest.requests") @mock.patch("georest.utils.file_in_granules") @mock.patch("georest.connect_to_gs_catalog")