From 5eb00ac5fef16f01ff84e8b8295ff32d1cf2960e Mon Sep 17 00:00:00 2001
From: gifrerenom <lluis.gifre@cttc.es>
Date: Tue, 14 Nov 2023 15:54:27 +0000
Subject: [PATCH] Monitoring component:

- Fixed unitary tests
---
 src/monitoring/tests/test_unitary.py | 30 ++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/src/monitoring/tests/test_unitary.py b/src/monitoring/tests/test_unitary.py
index 654614205..563709aee 100644
--- a/src/monitoring/tests/test_unitary.py
+++ b/src/monitoring/tests/test_unitary.py
@@ -226,6 +226,18 @@ def ingestion_data(kpi_id_int):
                                   kpi_value)
         sleep(0.1)
 
+##################################################
+# Prepare Environment, should be the first test
+##################################################
+
+def test_prepare_environment(
+    context_client : ContextClient,                 # pylint: disable=redefined-outer-name,unused-argument
+):
+    context_id = json_context_id(DEFAULT_CONTEXT_NAME)
+    context_client.SetContext(Context(**json_context(DEFAULT_CONTEXT_NAME)))
+    context_client.SetTopology(Topology(**json_topology(DEFAULT_TOPOLOGY_NAME, context_id=context_id)))
+
+
 ###########################
 # Tests Implementation
 ###########################
@@ -601,10 +613,6 @@ def test_listen_events(
     events_collector = EventsDeviceCollector(metrics_db.name_mapping)
     events_collector.start()
 
-    context_id = json_context_id(DEFAULT_CONTEXT_NAME)
-    context_client.SetContext(Context(**json_context(DEFAULT_CONTEXT_NAME)))
-    context_client.SetTopology(Topology(**json_topology(DEFAULT_TOPOLOGY_NAME, context_id=context_id)))
-
     LOGGER.info('Adding Device {:s}'.format(DEVICE_DEV1_UUID))
     device_with_connect_rules = copy.deepcopy(DEVICE_DEV1)
     device_with_connect_rules['device_config']['config_rules'].extend(DEVICE_DEV1_CONNECT_RULES)
@@ -629,11 +637,17 @@ def test_listen_events(
     assert len(kpi_id_list) > 0
 
     device_client.DeleteDevice(response)
+    events_collector.stop()
+
+    LOGGER.warning('test_listen_events end')
+
 
+##################################################
+# Cleanup Environment, should be the last test
+##################################################
+def test_cleanup_environment(
+    context_client : ContextClient,                 # pylint: disable=redefined-outer-name,unused-argument
+):
     context_id = json_context_id(DEFAULT_CONTEXT_NAME)
     context_client.RemoveTopology(TopologyId(**json_topology_id(DEFAULT_TOPOLOGY_NAME, context_id=context_id)))
     context_client.RemoveContext(ContextId(**context_id))
-
-    events_collector.stop()
-
-    LOGGER.warning('test_listen_events end')
-- 
GitLab