From 5d5dc9b0df6964a6642e8b63def49f4caea55605 Mon Sep 17 00:00:00 2001 From: Martin Raspaud Date: Thu, 2 May 2024 08:58:00 +0200 Subject: [PATCH] Test publishing --- src/pytroll_watchers/dhus_watcher.py | 1 + tests/test_dhus.py | 37 +++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/pytroll_watchers/dhus_watcher.py b/src/pytroll_watchers/dhus_watcher.py index c6e9973..f21057d 100644 --- a/src/pytroll_watchers/dhus_watcher.py +++ b/src/pytroll_watchers/dhus_watcher.py @@ -117,6 +117,7 @@ def generate_download_links(server, filter_params): mda["checksum"] = dict(algorithm=entry["Checksum"]["Algorithm"], hash=entry["Checksum"]["Value"]) mda["size"] = int(entry["ContentLength"]) + mda["uid"] = attributes["Filename"] yield path, mda def _construct_attributes_dict(entry): diff --git a/tests/test_dhus.py b/tests/test_dhus.py index 83315c0..4dae53b 100644 --- a/tests/test_dhus.py +++ b/tests/test_dhus.py @@ -6,7 +6,14 @@ import responses import responses._recorder from freezegun import freeze_time -from pytroll_watchers.dhus_watcher import file_generator, generate_download_links, generate_download_links_since +from posttroll.message import Message +from posttroll.testing import patched_publisher +from pytroll_watchers.dhus_watcher import ( + file_generator, + file_publisher, + generate_download_links, + generate_download_links_since, +) server = "https://colhub.met.no" @@ -65,3 +72,31 @@ def test_file_generator(): assert path.as_uri() == "https://colhub.met.no/odata/v1/Products('a6b214dd-fe39-4f50-aa94-f84d8510cedc')/$value" assert mda["start_time"] == dt.datetime(2024, 4, 29, 6, 54, 18, 105000, tzinfo=dt.timezone.utc) assert "ingestion_date" not in mda + assert mda["uid"] == "S1A_IW_GRDH_1SDV_20240429T065418_20240429T065443_053645_0683C0_8D1D.SAFE" + + +@freeze_time(dt.datetime(2024, 4, 29, 8, 33, tzinfo=dt.timezone.utc)) +@responses.activate +def test_publish_paths(): + """Test publishing paths.""" + responses._add_from_file(file_path="tests/dhus_responses.yaml") + + filter_params = ["substringof('IW_GRDH',Name)"] + + publisher_settings = dict(nameservers=False, port=1979) + message_settings = dict(subject="/segment/olci/l1b/", atype="file", aliases=dict(sensor={"SAR": "SAR-C"})) + + with patched_publisher() as messages: + fs_config = dict(server=server, + filter_params=filter_params, + polling_interval=dict(minutes=0), + start_from=dict(hours=1)) + + + file_publisher(fs_config=fs_config, + publisher_config=publisher_settings, + message_config=message_settings) + message = Message(rawstr=messages[3]) + + assert message.data["uid"] == "S1A_IW_GRDH_1SDV_20240429T065418_20240429T065443_053645_0683C0_8D1D.SAFE" + assert message.data["sensor"] == "SAR-C"