Ejemplo n.º 1
0
    def test_when_message_is_directed_private_should_call_message_content_handler_with_rigt_arguments(
            self, handle_message_content):
        message = "someuser >> bot: dodaj Jan Kowalski, Winogronowa 123/3, Pcim Dolny"
        expected_handle_message_content_args = (
            'someuser', 'dodaj Jan Kowalski, Winogronowa 123/3, Pcim Dolny')

        messagehandler.handle(message)
        args, _ = handle_message_content.call_args

        assert_true(handle_message_content.called)
        assert_equal(args, expected_handle_message_content_args)
Ejemplo n.º 2
0
    def test_when_message_is_directed_private_should_return_output_from_message_content_handler_as_private_message(
            self, handle_message_content):
        message = "someuser >> bot: dodaj Jan Kowalski, Winogronowa 123/3, Pcim Dolny"
        handle_message_content.return_value = 'Patataj'
        expected_answer = '>>someuser: Patataj'

        answer = messagehandler.handle(message)

        assert_equal(answer, expected_answer)
Ejemplo n.º 3
0
    def _handle_new_messages(self):
        new_messages = self._get_new_messages()

        for message in new_messages:
            full_text = message['text']
            self.logger.debug(f'Got message:  {full_text}')

            answer = messagehandler.handle(full_text)
            if answer is not None:
                self.logger.debug(f'Sending answer:  {answer}')
                self._send_message(answer)

            time.sleep(1)   # small delay just in case to keep message spam protection happy
Ejemplo n.º 4
0
 def on_message(self, message):
     if message['type'] in (
             'chat', 'normal') and message["from"] == self.blabler_bot_jid:
         answer = messagehandler.handle(message['body'])
         if answer is not None:
             message.reply(answer).send()
Ejemplo n.º 5
0
    def test_when_message_is_directed_private_should_call_message_content_handler(
            self, message, handle_message_content):
        messagehandler.handle(message)

        assert_true(handle_message_content.called)
Ejemplo n.º 6
0
 def test_when_message_is_directed_public_should_return_public_mesage_warn_text(
         self, message):
     expected_answer = ">>someuser: " + strings.public_message_warn
     answer = messagehandler.handle(message)
     assert_equal(answer, expected_answer)
Ejemplo n.º 7
0
 def test_when_message_is_not_directed_handle_should_return_none(
         self, message):
     answer = messagehandler.handle(message)
     assert_equal(answer, None)
Ejemplo n.º 8
0
 def test_handle_should_not_throw(self):
     messagehandler.handle('some message not a massage')