def test_on_event(self): event = VkBotMessageEvent(raw=self.RAW_EVENT) send_mock = Mock() with patch('bot.vk_api.VkApi'): with patch('bot.VkBotLongPoll'): bot = Bot('', '') bot.api = Mock() bot.api.messages.send = send_mock bot._on_event(event) send_mock.assert_called_once() send_mock.assert_called_once_with( message='Ты отправил -> ' + self.RAW_EVENT['object']['message']['text'], random_id=ANY, peer_id=self.RAW_EVENT['object']['message']['peer_id'])
def test_run(self): """ Тест для функции run() :return: None """ count = 5 obj = {'a': 1} events = [obj] * count # [obj, obj, ...] long_pool_listen_mock = Mock() long_pool_listen_mock.listen = Mock(return_value=events) with patch('bot.vk_api.VkApi'): with patch('bot.VkBotLongPoll', return_value=long_pool_listen_mock): bot = Bot('', '') bot._on_event = Mock() bot.run() bot._on_event.assert_called() bot._on_event.assert_any_call(obj) assert bot._on_event.call_count == count