SIENTIAPDE-1325
Enhance Redis activity by formatting set and get operations for improved readability and consistency. Update tests to include metadata in assertions for better verification of Redis interactions.
This commit is contained in:
@@ -155,7 +155,9 @@ class Redis(SientiaMonitoring):
|
|||||||
self.info(f'Last collected timestamp to insert: {last_data_timestamp}', metadata=metadata)
|
self.info(f'Last collected timestamp to insert: {last_data_timestamp}', metadata=metadata)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self.redis_repository.set(key, last_data_timestamp, ttl=60 * 60 * 5, metadata=metadata)
|
await self.redis_repository.set(
|
||||||
|
key, last_data_timestamp, ttl=60 * 60 * 5, metadata=metadata
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await self.send_notification_async(
|
await self.send_notification_async(
|
||||||
metadata=metadata,
|
metadata=metadata,
|
||||||
|
|||||||
@@ -93,7 +93,8 @@ async def test_get_last_data_timestamp_none(redis_activity):
|
|||||||
result = await redis_activity.get_last_data_timestamp(test_data)
|
result = await redis_activity.get_last_data_timestamp(test_data)
|
||||||
|
|
||||||
redis_activity.redis_repository.get.assert_called_once_with(
|
redis_activity.redis_repository.get.assert_called_once_with(
|
||||||
'last_data_timestamp:test_pipeline:test_schedule'
|
'last_data_timestamp:test_pipeline:test_schedule',
|
||||||
|
metadata=metadata['metadata'],
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result is None
|
assert result is None
|
||||||
@@ -109,7 +110,8 @@ async def test_get_last_data_timestamp_not_none(redis_activity):
|
|||||||
result = await redis_activity.get_last_data_timestamp(test_data)
|
result = await redis_activity.get_last_data_timestamp(test_data)
|
||||||
|
|
||||||
redis_activity.redis_repository.get.assert_called_once_with(
|
redis_activity.redis_repository.get.assert_called_once_with(
|
||||||
'last_data_timestamp:test_pipeline:test_schedule'
|
'last_data_timestamp:test_pipeline:test_schedule',
|
||||||
|
metadata=metadata['metadata'],
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result == '2023-01-01 12:00:00'
|
assert result == '2023-01-01 12:00:00'
|
||||||
@@ -186,7 +188,10 @@ async def test_put_last_data_timestamp_not_empty_dataframe(redis_activity):
|
|||||||
assert result == '2023-01-01 12:00:01'
|
assert result == '2023-01-01 12:00:01'
|
||||||
|
|
||||||
redis_activity.redis_repository.set.assert_called_once_with(
|
redis_activity.redis_repository.set.assert_called_once_with(
|
||||||
'last_data_timestamp:test_pipeline:test_schedule', '2023-01-01 12:00:01', ttl=18000
|
'last_data_timestamp:test_pipeline:test_schedule',
|
||||||
|
'2023-01-01 12:00:01',
|
||||||
|
ttl=18000,
|
||||||
|
metadata=metadata['metadata'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -270,6 +275,7 @@ async def test_group_and_hold_data_new_key(redis_activity):
|
|||||||
'held_data_test_pipeline_test_schedule',
|
'held_data_test_pipeline_test_schedule',
|
||||||
{'sensor1': 25.5, 'sensor2': 30.0, 'timestamp': '2023-01-01 12:00:00'},
|
{'sensor1': 25.5, 'sensor2': 30.0, 'timestamp': '2023-01-01 12:00:00'},
|
||||||
ttl=3600,
|
ttl=3600,
|
||||||
|
metadata=metadata['metadata'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -334,6 +340,7 @@ async def test_group_and_hold_data_update_existing_fill_missing(redis_activity):
|
|||||||
'timestamp': '2023-01-01 12:00:00',
|
'timestamp': '2023-01-01 12:00:00',
|
||||||
},
|
},
|
||||||
ttl=3600,
|
ttl=3600,
|
||||||
|
metadata=metadata['metadata'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -485,7 +492,10 @@ async def test_store_data_package(redis_activity):
|
|||||||
await redis_activity.store_data_package(test_data)
|
await redis_activity.store_data_package(test_data)
|
||||||
|
|
||||||
redis_activity.redis_repository.set.assert_called_once_with(
|
redis_activity.redis_repository.set.assert_called_once_with(
|
||||||
ANY, {'data': test_data['data'], 'held_data': test_data['held_data']}, ttl=120
|
ANY,
|
||||||
|
{'data': test_data['data'], 'held_data': test_data['held_data']},
|
||||||
|
ttl=120,
|
||||||
|
metadata=metadata['metadata'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user