Skip to content

Commit

Permalink
bots: Increase test coverage for trivia_quiz bot.
Browse files Browse the repository at this point in the history
  • Loading branch information
rheaparekh committed Jun 11, 2018
1 parent eb341c2 commit acbec06
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions zulip_bots/zulip_bots/bots/trivia_quiz/test_trivia_quiz.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import html

from unittest.mock import patch
from typing import Optional
Expand All @@ -9,8 +10,13 @@
read_bot_fixture_data,
)

from zulip_bots.request_test_lib import (
mock_request_exception,
)

from zulip_bots.bots.trivia_quiz.trivia_quiz import (
get_quiz_from_payload,
fix_quotes,
)

class TestTriviaQuizBot(BotTestCase, DefaultTests):
Expand Down Expand Up @@ -40,6 +46,18 @@ def test_bot_new_question(self) -> None:
def test_question_not_available(self) -> None:
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:
invalid_replies = ['answer A',
'answer A Q10',
Expand Down

0 comments on commit acbec06

Please sign in to comment.