def test_connect(self): with patch('chatbot.bot.VkApi'), \ patch('chatbot.bot.VkBotLongPoll'), \ patch('chatbot.bot.logging'): bot = ChatBot('', '') bot.connect() self.assertIsNotNone(bot.vk) self.assertIsNotNone(bot.api) self.assertIsNotNone(bot.bot_longpoll)
def test_run(self): long_poll_listen_mock = Mock() long_poll_listen_mock.listen = self.listen message_handling_mock = Mock() with patch('chatbot.bot.VkApi'), \ patch('chatbot.bot.VkBotLongPoll', return_value=long_poll_listen_mock), \ patch('chatbot.bot.logging'): bot = ChatBot('', '') bot.message_handling = message_handling_mock bot.run() message_handling_mock.assert_called_once()
def test_message_response(self): event = Mock() event.type = self.ROW_EVENT['type'] event.message = Mock() event.message.from_id = self.ROW_EVENT['object']['message']['from_id'] event.message.text = self.ROW_EVENT['object']['message']['text'] send_message_mock = Mock() with patch('chatbot.bot.VkBotEventType'), patch('chatbot.bot.logging'): bot = ChatBot('', '') bot.send_message = send_message_mock bot.get_message_response(event=event) send_message_mock.assert_called_once_with(message_text='Привет!', user_id=8023886)
def test_message_handling(self): event = Mock() event.type = self.ROW_EVENT['type'] event.message = Mock() event.message.from_id = self.ROW_EVENT['object']['message']['from_id'] event.message.text = self.ROW_EVENT['object']['message']['text'] get_message_response_mock = Mock() with patch('chatbot.bot.VkBotEventType') as VkBotEventType, \ patch('chatbot.bot.ChatBotDataBase'), \ patch('chatbot.bot.logging'): VkBotEventType.MESSAGE_NEW = 'message_new' bot = ChatBot('', '') bot.get_message_response = get_message_response_mock bot.message_handling(event) get_message_response_mock.assert_called_once_with(event=event)
vocab = Vocabulary.load(str(MODEL_PATH / "v0.21" / "vocab")) file_retrieval = FileRetrievalExt( str(MODEL_PATH / "v0.2" / "file_retrieval" / "test"), str(MODEL_PATH / "v0.2" / "file_retrieval" / "policy_filev3.utf8.csv")) cbot = ChatBot(intent_model=intent_model, intent_rule=intent_rule, vocab=vocab, label=label, ner=ner, intent2skills={ "未知": SafeResponse(), "留言": LeaveMessage(), "帮助": Help(), "闲聊": Tuling(), "文件检索": file_retrieval, "数据查询": DataInquiry(), "公司咨询": CompanyInfo(), "业务咨询": BusinessInfo(), "chatbot": BotQA(), "表扬": Praise(), "批评": Criticize(), "打招呼": SayHi(), "再见": GoodBye(), "感谢": Thanks(), }) # 初始化机器人,扫码登陆 # bot = Bot() # my_friend = bot.friends() # my_groups = bot.groups()
def test_smoke(self): ChatBot('', '')