X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=tests%2Ftest_alarm.py;h=2eec9c969cb3ad1666d5365658bc4082e808731d;hb=refs%2Fchanges%2F34%2F4834%2F1;hp=0fad272c7cf8c8a965e6526983663c036081853a;hpb=81084bc31ea1d5cde6616dd2267ea01f49a1d6d1;p=ric-plt%2Fxapp-frame-py.git diff --git a/tests/test_alarm.py b/tests/test_alarm.py index 0fad272..2eec9c9 100644 --- a/tests/test_alarm.py +++ b/tests/test_alarm.py @@ -15,9 +15,11 @@ # limitations under the License. # ================================================================================== import json +import pytest import time from ricxappframe.alarm import alarm -from ricxappframe.alarm.alarm import AlarmAction, AlarmDetail, AlarmManager, AlarmSeverity +from ricxappframe.alarm.alarm import AlarmAction, AlarmDetail, AlarmManager, AlarmSeverity, ALARM_MGR_SERVICE_NAME_ENV, ALARM_MGR_SERVICE_PORT_ENV +from ricxappframe.alarm.exceptions import InitFailed from ricxappframe.rmr import rmr MRC_SEND = None @@ -45,9 +47,10 @@ def teardown_module(): test alarm module teardown """ rmr.rmr_close(MRC_SEND) + rmr.rmr_close(MRC_RCV) -def test_alarm_set_get(): +def test_alarm_set_get(monkeypatch): """ test set functions """ @@ -65,6 +68,19 @@ def test_alarm_set_get(): assert det[alarm.KEY_IDENTIFYING_INFO] == "4" assert det[alarm.KEY_ADDITIONAL_INFO] == "5" + # missing environment variables + with pytest.raises(InitFailed): + alarm.AlarmManager(MRC_SEND, "missing", "envvars") + + # invalid environment variables + monkeypatch.setenv(ALARM_MGR_SERVICE_NAME_ENV, "0") + monkeypatch.setenv(ALARM_MGR_SERVICE_PORT_ENV, "a") + with pytest.raises(InitFailed): + alarm.AlarmManager(MRC_SEND, "bogus", "envvars") + + # good environment variables + monkeypatch.setenv(ALARM_MGR_SERVICE_NAME_ENV, "127.0.0.1") # do NOT use localhost + monkeypatch.setenv(ALARM_MGR_SERVICE_PORT_ENV, "4567") # any int is ok here mgr = alarm.AlarmManager(MRC_SEND, "moid2", "appid2") assert mgr is not None assert mgr.managed_object_id == "moid2" @@ -86,10 +102,12 @@ def _receive_alarm_msg(action: AlarmAction): assert data[alarm.KEY_ALARM_ACTION] == action.name -def test_alarm_manager(): +def test_alarm_manager(monkeypatch): """ test send functions and ensure a message arrives """ + monkeypatch.setenv(ALARM_MGR_SERVICE_NAME_ENV, "127.0.0.1") # do NOT use localhost + monkeypatch.setenv(ALARM_MGR_SERVICE_PORT_ENV, "4567") # must match rcv port above mgr = AlarmManager(MRC_SEND, "moid", "appid") assert mgr is not None