X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Ftests%2Funit%2Fcore%2Ftest_common_db_client.py;h=71022267476ff0a9a24fffb710daf2c5da51277e;hb=1b7145f6d0d3c0090b7a33b4972861ad9ed48631;hp=e58414946a0d150b6b17d8d5993a251977fcdd7a;hpb=d0058e879923ad938e19fd0361f1e6e126a2322e;p=osm%2FMON.git diff --git a/osm_mon/tests/unit/core/test_common_db_client.py b/osm_mon/tests/unit/core/test_common_db_client.py index e584149..7102226 100644 --- a/osm_mon/tests/unit/core/test_common_db_client.py +++ b/osm_mon/tests/unit/core/test_common_db_client.py @@ -27,6 +27,7 @@ from osm_common import dbmongo from osm_mon.core.common_db import CommonDbClient from osm_mon.core.config import Config +from osm_mon.core.models import Alarm class CommonDbClientTest(unittest.TestCase): @@ -146,3 +147,37 @@ class CommonDbClientTest(unittest.TestCase): decrypt_vim_password.assert_any_call('vim_password', schema_version, vim_id) self.assertRaises(AssertionError, decrypt_vim_password.assert_any_call, 'vrops_password', schema_version, vim_id) + + @mock.patch.object(dbmongo.DbMongo, "db_connect", mock.Mock()) + @mock.patch.object(dbmongo.DbMongo, "get_list") + def test_get_alarms(self, get_list): + get_list.return_value = [{ + 'uuid': '1', + 'name': 'name', + 'severity': 'severity', + 'threshold': 50, + 'operation': 'operation', + 'statistic': 'statistic', + 'tags': {}, + }] + + common_db_client = CommonDbClient(self.config) + alarms = common_db_client.get_alarms() + self.assertEqual('1', alarms[0].uuid) + + @mock.patch.object(dbmongo.DbMongo, "db_connect", mock.Mock()) + @mock.patch.object(dbmongo.DbMongo, "create") + def test_create_alarm(self, create): + alarm = Alarm('name', 'severity', 50.0, 'operation', 'statistic', 'metric', {}) + alarm.uuid = '1' + common_db_client = CommonDbClient(self.config) + common_db_client.create_alarm(alarm) + create.assert_called_with('alarms', {'tags': {}, 'threshold': 50.0, 'metric': 'metric', 'severity': 'severity', + 'statistic': 'statistic', 'name': 'name', 'uuid': '1'}) + + @mock.patch.object(dbmongo.DbMongo, "db_connect", mock.Mock()) + @mock.patch.object(dbmongo.DbMongo, "del_one") + def test_delete_alarm(self, delete): + common_db_client = CommonDbClient(self.config) + common_db_client.delete_alarm('1') + delete.assert_called_with('alarms', {'uuid': '1'})