def test_no_term(self, mocker, fake_message): fake_message.text = '/kbbi' mock_reply_to = mocker.patch('tululbot.commands.bot.reply_to', autospec=True) kbbi(fake_message) mock_reply_to.assert_called_once_with(fake_message, 'Cari apa lu?', force_reply=True)
def test_kbbi(self, mocker, fake_message): fake_message.text = '/kbbi foo bar' fake_rv = [ { 'class': 'nomina', 'def_text': 'baz quux', 'sample': 'baz baz quux quux' }, { 'class': 'adjektiva', 'def_text': 'quux baz', 'sample': None } ] mocker.patch('tululbot.commands.lookup_kbbi_definition', return_value=fake_rv, autospec=True) mock_reply_to = mocker.patch('tululbot.commands.bot.reply_to', autospec=True) kbbi(fake_message) expected_text = ('1. baz quux (_nomina_)\n' '_baz baz quux quux_\n' '\n' '2. quux baz (_adjektiva_)\n') mock_reply_to.assert_called_once_with(fake_message, expected_text, parse_mode='Markdown')
def test_term_only(self, mocker, fake_message): fake_message.text = 'foo bar' mock_lookup = mocker.patch('tululbot.commands.lookup_kbbi_definition', autospec=True) mocker.patch('tululbot.commands.bot.reply_to', autospec=True) kbbi(fake_message) mock_lookup.assert_called_once_with(fake_message.text)
def test_conn_error(self, mocker, fake_message): fake_message.text = '/kbbi asdf asdf' mocker.patch('tululbot.commands.lookup_kbbi_definition', side_effect=ConnectionError, autospec=True) mock_reply_to = mocker.patch('tululbot.commands.bot.reply_to', autospec=True) kbbi(fake_message) mock_reply_to.assert_called_once_with(fake_message, "Koneksi lagi bapuk nih :'(")
def test_http_error(self, mocker, fake_message): fake_message.text = '/kbbi asdf asdf' mocker.patch('tululbot.commands.lookup_kbbi_definition', side_effect=HTTPError, autospec=True) mock_reply_to = mocker.patch('tululbot.commands.bot.reply_to', autospec=True) kbbi(fake_message) mock_reply_to.assert_called_once_with(fake_message, 'Aduh ada error nich')
def test_no_defs(self, mocker, fake_message): fake_message.text = '/kbbi foo bar' mocker.patch('tululbot.commands.lookup_kbbi_definition', return_value=[], autospec=True) mock_reply_to = mocker.patch('tululbot.commands.bot.reply_to', autospec=True) kbbi(fake_message) mock_reply_to.assert_called_once_with(fake_message, 'Gak ada bray')