예제 #1
0
    def test_http_error(self, mocker, fake_message):
        fake_message.text = '/slang asdf asdf'
        mocker.patch('tululbot.commands.lookup_slang', side_effect=HTTPError, autospec=True)
        mock_reply_to = mocker.patch('tululbot.commands.bot.reply_to', autospec=True)

        slang(fake_message)

        mock_reply_to.assert_called_once_with(fake_message, 'Aduh ada error nich')
예제 #2
0
    def test_term_only(self, mocker, fake_message):
        fake_message.text = 'foo bar'
        mock_lookup = mocker.patch('tululbot.commands.lookup_slang', autospec=True)
        mocker.patch('tululbot.commands.bot.reply_to', autospec=True)

        slang(fake_message)

        mock_lookup.assert_called_once_with(fake_message.text)
예제 #3
0
    def test_no_term(self, mocker, fake_message):
        fake_message.text = '/slang'
        mock_reply_to = mocker.patch('tululbot.commands.bot.reply_to', autospec=True)

        slang(fake_message)

        mock_reply_to.assert_called_once_with(fake_message, 'Apa yang mau dicari jir?',
                                              force_reply=True)
예제 #4
0
    def test_conn_error(self, mocker, fake_message):
        fake_message.text = '/slang asdf asdf'
        mocker.patch('tululbot.commands.lookup_slang', side_effect=ConnectionError,
                     autospec=True)
        mock_reply_to = mocker.patch('tululbot.commands.bot.reply_to', autospec=True)

        slang(fake_message)

        mock_reply_to.assert_called_once_with(fake_message, "Koneksi lagi bapuk nih :'(")
예제 #5
0
    def test_slang(self, mocker, fake_message):
        slang_term = 'hohoi ahoi'
        fake_message.text = '/slang {}'.format(slang_term)
        slang_lookup_result = 'hahaha'
        mock_reply_to = mocker.patch('tululbot.commands.bot.reply_to', autospec=True)
        mock_lookup_slang = mocker.patch('tululbot.commands.lookup_slang',
                                         return_value=slang_lookup_result,
                                         autospec=True)

        slang(fake_message)

        mock_lookup_slang.assert_called_once_with(slang_term)
        mock_reply_to.assert_called_once_with(fake_message, slang_lookup_result,
                                              parse_mode='Markdown')
예제 #6
0
def test_slang_no_word(fake_message, fake_user, mocker):
    class FakeBot:
        def __init__(self):
            self.user = fake_user
            self.reply_to = MagicMock()

    fake_bot = FakeBot()
    fake_message.text = '/slang'
    mocker.patch('tululbot.commands.bot', new=fake_bot)

    slang(fake_message)

    fake_bot.reply_to.assert_called_once_with(fake_message, 'Apa yang mau dicari jir?',
                                              force_reply=True)
예제 #7
0
def test_slang_with_bot_name(fake_message, fake_user, mocker):
    class FakeBot:
        def __init__(self):
            self.user = fake_user
            self.reply_to = MagicMock()

    fake_bot = FakeBot()
    slang_word = 'hohoi'
    fake_message.text = '/slang@{} {}'.format(fake_bot.user.first_name, slang_word)
    slang_lookup_result = 'hahaha'
    mocker.patch('tululbot.commands.bot', new=fake_bot)
    mock_lookup_slang = mocker.patch('tululbot.commands.lookup_slang',
                                     return_value=slang_lookup_result)

    slang(fake_message)

    mock_lookup_slang.assert_called_once_with(slang_word)
    fake_bot.reply_to.assert_called_once_with(fake_message, slang_lookup_result)