Updates for Python 3.10 and Ubuntu 22.04
[osm/POL.git] / osm_policy_module / tests / unit / alarming / test_alarming_service.py
index af672e6..65025e5 100644 (file)
@@ -38,7 +38,6 @@ from osm_policy_module.core.database import VnfAlarmRepository
 class TestAlarmingService(TestCase):
     def setUp(self):
         self.config = Config()
-        self.loop = asyncio.new_event_loop()
         self.payload = {"notify_details": {"alarm_number": 0}}
         self.headers = {"content-type": "application/json"}
 
@@ -51,9 +50,7 @@ class TestAlarmingService(TestCase):
         get_alarm.return_value = mock_alarm
         service = AlarmingService(self.config)
         if bool(self.config.get("alert", "enhanced_alarms")):
-            self.loop.run_until_complete(
-                service.handle_alarm("test_id", "alarm", self.payload)
-            )
+            asyncio.run(service.handle_alarm("test_id", "alarm", self.payload))
             requests_post.assert_called_once_with(
                 url="http://alarm-url/",
                 data='{"notify_details": {"alarm_number": 1}}',
@@ -62,7 +59,7 @@ class TestAlarmingService(TestCase):
                 timeout=alert_timeout,
             )
         else:
-            self.loop.run_until_complete(service.handle_alarm("test_id", "alarm", {}))
+            asyncio.run(service.handle_alarm("test_id", "alarm", {}))
             requests_post.assert_called_once_with(
                 json="{}", url="http://alarm-url/", timeout=alert_timeout
             )
@@ -76,9 +73,7 @@ class TestAlarmingService(TestCase):
         get_alarm.return_value = mock_alarm
         service = AlarmingService(self.config)
         if bool(self.config.get("alert", "enhanced_alarms")):
-            self.loop.run_until_complete(
-                service.handle_alarm("test_id", "ok", self.payload)
-            )
+            asyncio.run(service.handle_alarm("test_id", "ok", self.payload))
             requests_post.assert_called_once_with(
                 url="http://ok-url/",
                 data='{"notify_details": {"alarm_number": 0}}',
@@ -87,7 +82,7 @@ class TestAlarmingService(TestCase):
                 timeout=alert_timeout,
             )
         else:
-            self.loop.run_until_complete(service.handle_alarm("test_id", "ok", {}))
+            asyncio.run(service.handle_alarm("test_id", "ok", {}))
             requests_post.assert_called_once_with(
                 json="{}", url="http://ok-url/", timeout=alert_timeout
             )
@@ -101,7 +96,7 @@ class TestAlarmingService(TestCase):
         get_alarm.return_value = mock_alarm
         service = AlarmingService(self.config)
         if bool(self.config.get("alert", "enhanced_alarms")):
-            self.loop.run_until_complete(
+            asyncio.run(
                 service.handle_alarm("test_id", "insufficient-data", self.payload)
             )
             requests_post.assert_called_once_with(
@@ -112,9 +107,7 @@ class TestAlarmingService(TestCase):
                 timeout=alert_timeout,
             )
         else:
-            self.loop.run_until_complete(
-                service.handle_alarm("test_id", "insufficient-data", {})
-            )
+            asyncio.run(service.handle_alarm("test_id", "insufficient-data", {}))
             requests_post.assert_called_once_with(
                 json="{}", url="http://insufficient-data-url/", timeout=alert_timeout
             )
@@ -126,7 +119,7 @@ class TestAlarmingService(TestCase):
         mock_alarm = self._build_mock_alarm("test_id")
         get_alarm.return_value = mock_alarm
         service = AlarmingService(self.config)
-        self.loop.run_until_complete(service.handle_alarm("test_id", "unknown", {}))
+        asyncio.run(service.handle_alarm("test_id", "unknown", {}))
         requests_post.assert_not_called()
 
     def _build_mock_alarm(