X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=osm_policy_module%2Ftests%2Funit%2Fcommon%2Ftest_message_bus_client.py;h=8011a04e074ef1531843b8dd12b3e441109ea1f6;hb=d37c54c64eec65c9a3c490a31eef3a02a76cb474;hp=0b97de7e28f68dd1c7c13d901e700f6bd2475838;hpb=a14cf16181c8b39f12c872c486e0b292c0068944;p=osm%2FPOL.git diff --git a/osm_policy_module/tests/unit/common/test_message_bus_client.py b/osm_policy_module/tests/unit/common/test_message_bus_client.py index 0b97de7..8011a04 100644 --- a/osm_policy_module/tests/unit/common/test_message_bus_client.py +++ b/osm_policy_module/tests/unit/common/test_message_bus_client.py @@ -31,43 +31,41 @@ from osm_policy_module.core.config import Config class TestMessageBusClient(TestCase): - def setUp(self): self.config = Config() - self.config.set('message', 'driver', 'kafka') - self.loop = asyncio.new_event_loop() + self.config.set("message", "driver", "kafka") - @mock.patch.object(MsgKafka, 'aioread') + @mock.patch.object(MsgKafka, "aioread") def test_aioread(self, aioread): async def mock_callback(): pass - future = asyncio.Future(loop=self.loop) - future.set_result('mock') + future = asyncio.Future(loop=asyncio.new_event_loop()) + future.set_result("mock") aioread.return_value = future - msg_bus = MessageBusClient(self.config, loop=self.loop) - topic = 'test_topic' - self.loop.run_until_complete(msg_bus.aioread([topic], mock_callback)) - aioread.assert_called_with(['test_topic'], self.loop, aiocallback=mock_callback) + msg_bus = MessageBusClient(self.config) + topic = "test_topic" + asyncio.run(msg_bus.aioread([topic], mock_callback)) + aioread.assert_called_with(["test_topic"], aiocallback=mock_callback) - @mock.patch.object(MsgKafka, 'aiowrite') + @mock.patch.object(MsgKafka, "aiowrite") def test_aiowrite(self, aiowrite): - future = asyncio.Future(loop=self.loop) - future.set_result('mock') + future = asyncio.Future(loop=asyncio.new_event_loop()) + future.set_result("mock") aiowrite.return_value = future - msg_bus = MessageBusClient(self.config, loop=self.loop) - topic = 'test_topic' - key = 'test_key' - msg = {'test': 'test_msg'} - self.loop.run_until_complete(msg_bus.aiowrite(topic, key, msg)) - aiowrite.assert_called_with(topic, key, msg, self.loop) + msg_bus = MessageBusClient(self.config) + topic = "test_topic" + key = "test_key" + msg = {"test": "test_msg"} + asyncio.run(msg_bus.aiowrite(topic, key, msg)) + aiowrite.assert_called_with(topic, key, msg) - @mock.patch.object(MsgKafka, 'aioread') + @mock.patch.object(MsgKafka, "aioread") def test_aioread_once(self, aioread): - future = asyncio.Future(loop=self.loop) - future.set_result('mock') + future = asyncio.Future(loop=asyncio.new_event_loop()) + future.set_result("mock") aioread.return_value = future - msg_bus = MessageBusClient(self.config, loop=self.loop) - topic = 'test_topic' - self.loop.run_until_complete(msg_bus.aioread_once(topic)) - aioread.assert_called_with('test_topic', self.loop) + msg_bus = MessageBusClient(self.config) + topic = "test_topic" + asyncio.run(msg_bus.aioread_once(topic)) + aioread.assert_called_with("test_topic")