X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Ftests%2Funit%2Fcollector%2Ftest_collector_service.py;h=d3cd395413be423f989f56b7603221123b312a04;hb=94948de24a6ff7d03cce2168be5a83c0ed97196d;hp=fc2146cc34fe3079bd5bc0cd59d4aca1d0d9b0aa;hpb=9a773323e8cec18fb0f2fa204b0cea4e2370c5dd;p=osm%2FMON.git diff --git a/osm_mon/tests/unit/collector/test_collector_service.py b/osm_mon/tests/unit/collector/test_collector_service.py index fc2146c..d3cd395 100644 --- a/osm_mon/tests/unit/collector/test_collector_service.py +++ b/osm_mon/tests/unit/collector/test_collector_service.py @@ -27,6 +27,7 @@ from osm_mon.collector.vnf_collectors.openstack import OpenstackCollector from osm_mon.collector.vnf_collectors.vio import VIOCollector from osm_mon.core.common_db import CommonDbClient from osm_mon.core.config import Config +from osm_mon.collector.service import init_session @mock.patch.object(CommonDbClient, "__init__", lambda *args, **kwargs: None) @@ -34,41 +35,54 @@ class CollectorServiceTest(TestCase): def setUp(self): super().setUp() self.config = Config() + mock_vim_session = mock.MagicMock() + init_session(mock_vim_session) @mock.patch.object(OpenstackCollector, "__init__", lambda *args, **kwargs: None) @mock.patch.object(OpenstackCollector, "collect") @mock.patch.object(CommonDbClient, "get_vim_account") def test_init_vim_collector_and_collect_openstack(self, _get_vim_account, collect): - _get_vim_account.return_value = {'vim_type': 'openstack'} + _get_vim_account.return_value = {"vim_type": "openstack"} collector = CollectorService(self.config) - collector._collect_vim_metrics(self.config, {}, 'test_vim_account_id') + collector._collect_vim_metrics(self.config, {}, "test_vim_account_id") collect.assert_called_once_with({}) @mock.patch.object(OpenstackCollector, "collect") @mock.patch.object(CommonDbClient, "get_vim_account") - def test_init_vim_collector_and_collect_unknown(self, _get_vim_account, openstack_collect): - _get_vim_account.return_value = {'vim_type': 'unknown'} + def test_init_vim_collector_and_collect_unknown( + self, _get_vim_account, openstack_collect + ): + _get_vim_account.return_value = {"vim_type": "unknown"} collector = CollectorService(self.config) - collector._collect_vim_metrics(self.config, {}, 'test_vim_account_id') + collector._collect_vim_metrics(self.config, {}, "test_vim_account_id") openstack_collect.assert_not_called() @mock.patch.object(OpenstackCollector, "__init__", lambda *args, **kwargs: None) @mock.patch.object(OpenstackCollector, "collect") @mock.patch.object(CommonDbClient, "get_vim_account") - def test_init_vim_collector_and_collect_vio_with_openstack_collector(self, _get_vim_account, openstack_collect): - _get_vim_account.return_value = {'vim_type': 'openstack', 'config': {'vim_type': 'VIO'}} + def test_init_vim_collector_and_collect_vio_with_openstack_collector( + self, _get_vim_account, openstack_collect + ): + _get_vim_account.return_value = { + "vim_type": "openstack", + "config": {"vim_type": "VIO"}, + } collector = CollectorService(self.config) - collector._collect_vim_metrics(self.config, {}, 'test_vim_account_id') + collector._collect_vim_metrics(self.config, {}, "test_vim_account_id") openstack_collect.assert_called_once_with({}) @mock.patch.object(VIOCollector, "__init__", lambda *args, **kwargs: None) @mock.patch.object(VIOCollector, "collect") @mock.patch.object(CommonDbClient, "get_vim_account") - def test_init_vim_collector_and_collect_vio_with_vrops_collector(self, _get_vim_account, vio_collect): - _get_vim_account.return_value = {'vim_type': 'openstack', - 'config': {'vim_type': 'VIO', 'vrops_site': 'https://vrops'}} + def test_init_vim_collector_and_collect_vio_with_vrops_collector( + self, _get_vim_account, vio_collect + ): + _get_vim_account.return_value = { + "vim_type": "openstack", + "config": {"vim_type": "VIO", "vrops_site": "https://vrops"}, + } collector = CollectorService(self.config) - collector._collect_vim_metrics(self.config, {}, 'test_vim_account_id') + collector._collect_vim_metrics(self.config, {}, "test_vim_account_id") vio_collect.assert_called_once_with({}) @mock.patch("osm_mon.collector.service.VCACollector", autospec=True)