Skip to content

Commit

Permalink
Add support for "dataset" messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mraspaud committed May 29, 2024
1 parent a0425c6 commit b24bc53
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
17 changes: 8 additions & 9 deletions trolldb/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ async def record_messages(config: AppConfig):
)
for m in create_subscriber_from_dict_config(config.subscriber).recv():
msg = Message.decode(str(m))
match msg.type:
case "file":
await collection.insert_one(msg.data)
case "del":
deletion_result = await collection.delete_many({"uri": msg.data["uri"]})
if deletion_result.deleted_count != 1:
logger.error("Recorder found multiple deletions!") # TODO: Log some data related to the msg
case _:
logger.debug(f"Don't know what to do with {msg.type} message.")
if msg.type in ["file", "dataset"]:
await collection.insert_one(msg.data)
elif msg.type == "del":
deletion_result = await collection.delete_many({"uri": msg.data["uri"]})
if deletion_result.deleted_count != 1:
logger.error("Recorder found multiple deletions!") # TODO: Log some data related to the msg

Check warning on line 28 in trolldb/cli.py

View check run for this annotation

Codecov / codecov/patch

trolldb/cli.py#L28

Added line #L28 was not covered by tests
else:
logger.debug(f"Don't know what to do with {msg.type} message.")

Check warning on line 30 in trolldb/cli.py

View check run for this annotation

Codecov / codecov/patch

trolldb/cli.py#L30

Added line #L30 was not covered by tests


async def record_messages_from_config(config_file: FilePath):
Expand Down
22 changes: 22 additions & 0 deletions trolldb/tests/test_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ def file_message(tmp_data_filename):
'"polarization": "hh", "sensor": "sar-c", "format": "GeoTIFF", "pass_direction": "ASCENDING"}')


@pytest.fixture()
def dataset_message(tmp_data_filename):
"""Create a string for a file message."""
return ('pytroll://segment/raster/L2/SAR dataset [email protected] 2019-11-05T13:00:10.366023 v1.01 '
'application/json {"platform_name": "S1B", "scan_mode": "EW", "type": "GRDM", "data_source": "1SDH", '
'"start_time": "2019-11-03T15:39:36.543000", "end_time": "2019-11-03T15:40:40.821000", "orbit_number": '
'18765, "random_string1": "0235EA", "random_string2": "747D", "dataset": [{"uri": '
f'"{str(tmp_data_filename)}", "uid": "20191103_153936-s1b-ew-hh.tiff"}}], '
'"polarization": "hh", "sensor": "sar-c", "format": "GeoTIFF", "pass_direction": "ASCENDING"}')


@pytest.fixture()
def del_message(tmp_data_filename):
"""Create a string for a delete message."""
Expand Down Expand Up @@ -89,3 +100,14 @@ async def test_record_deletes_message(tmp_path, file_message, del_message):
collection = await MongoDB.get_collection("mock_database", "mock_collection")
result = await collection.find_one(dict(scan_mode="EW"))
assert result is None

async def test_record_dataset_messages(tmp_path, dataset_message):
"""Test recording a dataset message and deleting the file."""
config = AppConfig(**make_test_app_config(tmp_path))
with running_prepared_database_context():
with patched_subscriber_recv([dataset_message]):
await record_messages(config)
async with mongodb_context(config.database):
collection = await MongoDB.get_collection("mock_database", "mock_collection")
result = await collection.find_one(dict(scan_mode="EW"))
assert result is not None

0 comments on commit b24bc53

Please sign in to comment.