Example #1
0
    def test_when_message_has_no_add_command_should_try_to_save_data(
            self, save_user_data):
        user = '******'
        message = 'dodaj Anna Maria Smutna 22-111 Ma twarz'
        expected_save_user_data_args = (user,
                                        'Anna Maria Smutna 22-111 Ma twarz')

        addinghandler.handle_message_content(user, message)
        args, _ = save_user_data.call_args

        assert_true(save_user_data.called)
        assert_equal(args, expected_save_user_data_args)
Example #2
0
    def test_when_there_is_error_with_saving_user_data_should_return_error_text(
            self, save_user_data):
        save_user_data.side_effect = Exception

        answer = addinghandler.handle_message_content('user', 'dodaj mnie!')

        assert_equal(answer, strings.error_text)
Example #3
0
    def test_when_command_has_different_letter_case_should_also_recognize_it(
            self, message, save_user_data):
        user = '******'

        answer = addinghandler.handle_message_content(user, message)

        assert_not_equal(answer, strings.help_text)
Example #4
0
def handle(message):
    if not messageparser.is_directed(message):
        return None

    sender = messageparser.get_sender_from(message)
    answer = None

    if messageparser.is_directed_private(message):
        logger.info('Directed private message: ' + message)

        message_content = messageparser.get_content_from(message)
        answer = messagecontenthandler.handle_message_content(
            sender, message_content)

    if messageparser.is_directed_public(message):
        logger.debug('Directed public message: ' + message)
        logger.debug('Sending warning')
        answer = strings.public_message_warn

    return _create_private_message(sender, answer)
Example #5
0
    def test_when_successfully_saved_user_data_should_return_data_saved_text(
            self, save_user_data):
        answer = addinghandler.handle_message_content('user', 'dodaj mnie!')

        assert_equal(answer, strings.data_saved)
Example #6
0
    def test_when_message_has_no_add_command_should_not_try_to_save_data(
            self, save_user_data):
        addinghandler.handle_message_content('user', 'nie dodawaj, odejmuj!')

        assert_false(save_user_data.called)
Example #7
0
    def test_when_message_has_no_add_command_should_return_help_text(self):
        answer = addinghandler.handle_message_content('user',
                                                      'nie dodawaj, odejmuj!')

        assert_equal(answer, strings.help_text)
Example #8
0
 def test_handle_message_content_should_not_throw(self):
     addinghandler.handle_message_content('user', 'content')