Пример #1
0
 def test_state_transition(self, message, flows):
     chat_mgr = Mock()
     processor = MessageProcessor(chat_mgr, message)
     flows['default'].add_state(State("transition", action=set_called))
     message.entities['intent'] = [{"value": "greeting"}]
     message.entities['_state'] = [{"value": "default.transition:"}]
     processor.process()
     assert hasattr(processor.dialog, 'called')
Пример #2
0
 def test_unsupported(self, message, flows):
     chat_mgr = Mock()
     processor = MessageProcessor(chat_mgr, message)
     flows['greeting'] = Flow("greeting", intent="greeting", unsupported=set_called)
     flows['greeting'].add_state(State("root", action=None))
     message.entities = {}
     processor.current_state_name = "greeting.root"
     processor.process()
     assert hasattr(processor.dialog, 'called')
Пример #3
0
 def test_intent_transition(self, message, flows):
     chat_mgr = Mock()
     processor = MessageProcessor(chat_mgr, message)
     flows['greeting'] = Flow("greeting", intent="greeting")
     flows['greeting'].add_state(State("root", action=set_called))
     message.entities['intent'] = [{"value": "greeting"}]
     assert processor.current_state_name == "default.root"
     processor.process()
     assert hasattr(processor.dialog, 'called')
     assert processor.current_state_name == "greeting.root"
Пример #4
0
 def test_logging(self, monkeypatch, message, flows):
     chat_mgr = Mock()
     logger = Mock()
     flows['default'].add_state(State("transition", action=None))
     message.entities['intent'] = [{"value": "greeting"}]
     message.entities['_state'] = [{"value": "default.transition:"}]
     processor = MessageProcessor(chat_mgr, message)
     start_state = processor.current_state_name
     processor.logging_service = logger
     processor.process()
     end_state = processor.current_state_name
     assert logger.log_user_message_start.called_once_with(message, start_state)
     assert logger.log_user_message_end.called_once_with(message, end_state)
Пример #5
0
    def _process(self, message):
        # Import here to be able to mock the message processor class
        # TODO: Could be implemented using a MessageProcessorFactory instead
        from botshot.core.message_processor import MessageProcessor
        try:
            logging.info("Processing user message: %s", message)
            processor = MessageProcessor(self, message=message, interceptors=self.interceptors)
            processor.process()
        except Exception as e:
            logging.exception("ERROR: Exception while processing message")
            # TODO: Save error message (ChatMessage.type = ERROR)

        message.conversation.save()
        if message.user is not None:
            message.user.save()
        if self.save_messages:
            message.save()
Пример #6
0
 def setUp(self, monkeypatch):
     self.message = ChatMessage()
     self.message.type = ChatMessage.MESSAGE
     self.message.text = "Hello, world!"
     self.message.conversation = ChatConversation()
     self.message.time = time.time()
     self.message.user = ChatUser()
     self.message.is_user = True
     self.message.message_id = 105
     self.dialog = MessageProcessor(chat_manager=None, message=self.message)
Пример #7
0
 def test_defaults(self, message, flows, monkeypatch):
     chat_mgr = Mock()
     processor = MessageProcessor(chat_mgr, message)
     assert processor.get_flow()
     assert processor.get_flow().name == 'default'
     assert processor.get_state()
     assert processor.get_state().name == 'root'
     assert processor.current_state_name == 'default.root'
Пример #8
0
 def test_counter_increment(self, flows, message):
     proc = MessageProcessor(ChatManager(), message)
     assert proc.context.counter == 0
     proc.process()
     assert proc.context.counter == 1