bots: Increase test coverage for trivia_quiz bot.

This commit is contained in:
Rhea Parekh 2018-06-11 21:26:46 +05:30 committed by showell
parent 7e8deac8e0
commit f25772d1dc

View file

@ -1,4 +1,5 @@
import json import json
import html
from unittest.mock import patch from unittest.mock import patch
from typing import Optional from typing import Optional
@ -9,8 +10,13 @@ from zulip_bots.test_lib import (
read_bot_fixture_data, read_bot_fixture_data,
) )
from zulip_bots.request_test_lib import (
mock_request_exception,
)
from zulip_bots.bots.trivia_quiz.trivia_quiz import ( from zulip_bots.bots.trivia_quiz.trivia_quiz import (
get_quiz_from_payload, get_quiz_from_payload,
fix_quotes,
) )
class TestTriviaQuizBot(BotTestCase, DefaultTests): class TestTriviaQuizBot(BotTestCase, DefaultTests):
@ -40,6 +46,18 @@ class TestTriviaQuizBot(BotTestCase, DefaultTests):
def test_question_not_available(self) -> None: def test_question_not_available(self) -> None:
self._test('new', 'Uh-Oh! Trivia service is down.', 'test_status_code') self._test('new', 'Uh-Oh! Trivia service is down.', 'test_status_code')
with mock_request_exception():
self.verify_reply('new', 'Uh-Oh! Trivia service is down.')
def test_fix_quotes(self) -> None:
self.assertEqual(fix_quotes('test & test'), html.unescape('test & test'))
print('f')
with patch('html.unescape') as mock_html_unescape:
mock_html_unescape.side_effect = Exception
with self.assertRaises(Exception) as exception:
fix_quotes('test')
self.assertEqual(str(exception.exception), "Please use python3.4 or later for this bot.")
def test_invalid_answer(self) -> None: def test_invalid_answer(self) -> None:
invalid_replies = ['answer A', invalid_replies = ['answer A',
'answer A Q10', 'answer A Q10',