bots: Use bold formatting judiciously in trivia bot.

This commit is contained in:
Rohitt Vashishtha 2019-01-30 21:59:29 +05:30 committed by showell
parent 49d3f4cfbb
commit be4f9a0c32
2 changed files with 10 additions and 10 deletions

View file

@ -95,13 +95,13 @@ class TestTriviaQuizBot(BotTestCase, DefaultTests):
# test incorrect answer # test incorrect answer
with patch('zulip_bots.bots.trivia_quiz.trivia_quiz.get_quiz_from_id', with patch('zulip_bots.bots.trivia_quiz.trivia_quiz.get_quiz_from_id',
return_value=json.dumps(quiz)): return_value=json.dumps(quiz)):
self._test('answer Q001 B', '**:disappointed: WRONG, Foo Test User!** B is not correct.') self._test('answer Q001 B', ':disappointed: WRONG, Foo Test User! B is not correct.')
# test correct answer # test correct answer
with patch('zulip_bots.bots.trivia_quiz.trivia_quiz.get_quiz_from_id', with patch('zulip_bots.bots.trivia_quiz.trivia_quiz.get_quiz_from_id',
return_value=json.dumps(quiz)): return_value=json.dumps(quiz)):
with patch('zulip_bots.bots.trivia_quiz.trivia_quiz.start_new_quiz') as mock_new_quiz: with patch('zulip_bots.bots.trivia_quiz.trivia_quiz.start_new_quiz') as mock_new_quiz:
self._test('answer Q001 A', '**:tada: Amphibian is correct, Foo Test User!**') self._test('answer Q001 A', ':tada: **Amphibian** is correct, Foo Test User!')
def test_update_quiz(self) -> None: def test_update_quiz(self) -> None:
quiz, bot_handler = self.get_test_quiz() quiz, bot_handler = self.get_test_quiz()
@ -122,12 +122,12 @@ class TestTriviaQuizBot(BotTestCase, DefaultTests):
# test for a correct answer # test for a correct answer
start_new_question, response = handle_answer(quiz, 'A', 'Q001', bot_handler, 'Test user') start_new_question, response = handle_answer(quiz, 'A', 'Q001', bot_handler, 'Test user')
self.assertTrue(start_new_question) self.assertTrue(start_new_question)
self.assertEqual(response, '**:tada: Amphibian is correct, Test user!**') self.assertEqual(response, ':tada: **Amphibian** is correct, Test user!')
# test for an incorrect answer # test for an incorrect answer
start_new_question, response = handle_answer(quiz, 'D', 'Q001', bot_handler, 'Test User') start_new_question, response = handle_answer(quiz, 'D', 'Q001', bot_handler, 'Test User')
self.assertFalse(start_new_question) self.assertFalse(start_new_question)
self.assertEqual(response, '**:disappointed: WRONG, Test User!** D is not correct.') self.assertEqual(response, ':disappointed: WRONG, Test User! D is not correct.')
def test_handle_answer_three_failed_attempts(self) -> None: def test_handle_answer_three_failed_attempts(self) -> None:
quiz, bot_handler = self.get_test_quiz() quiz, bot_handler = self.get_test_quiz()
@ -137,7 +137,7 @@ class TestTriviaQuizBot(BotTestCase, DefaultTests):
# test response and storage after three failed attempts # test response and storage after three failed attempts
start_new_question, response = handle_answer(quiz, 'D', 'Q001', bot_handler, 'Test User') start_new_question, response = handle_answer(quiz, 'D', 'Q001', bot_handler, 'Test User')
self.assertEqual(response, '**:disappointed: WRONG, Test User!** The correct answer is Amphibian.') self.assertEqual(response, ':disappointed: WRONG, Test User! The correct answer is **Amphibian**.')
self.assertTrue(start_new_question) self.assertTrue(start_new_question)
quiz_reset = json.loads(bot_handler.storage.get('Q001')) quiz_reset = json.loads(bot_handler.storage.get('Q001'))
self.assertEqual(quiz_reset['pending'], False) self.assertEqual(quiz_reset['pending'], False)
@ -146,10 +146,10 @@ class TestTriviaQuizBot(BotTestCase, DefaultTests):
incorrect_answers = ['B', 'C', 'D'] incorrect_answers = ['B', 'C', 'D']
for ans in incorrect_answers: for ans in incorrect_answers:
start_new_question, response = handle_answer(quiz, ans, 'Q001', bot_handler, 'Test User') start_new_question, response = handle_answer(quiz, ans, 'Q001', bot_handler, 'Test User')
self.assertEqual(response, '**:disappointed: WRONG, Test User!** The correct answer is Amphibian.') self.assertEqual(response, ':disappointed: WRONG, Test User! The correct answer is **Amphibian**.')
self.assertFalse(start_new_question) self.assertFalse(start_new_question)
start_new_question, response = handle_answer(quiz, 'A', 'Q001', bot_handler, 'Test User') start_new_question, response = handle_answer(quiz, 'A', 'Q001', bot_handler, 'Test User')
self.assertEqual(response, '**:tada: Amphibian is correct, Test User!**') self.assertEqual(response, ':tada: **Amphibian** is correct, Test User!')
self.assertFalse(start_new_question) self.assertFalse(start_new_question)
# test storage after question has ended # test storage after question has ended

View file

@ -204,12 +204,12 @@ def update_quiz(quiz: Dict[str, Any], quiz_id: str, bot_handler: Any) -> None:
def build_response(is_correct: bool, num_answers: int) -> str: def build_response(is_correct: bool, num_answers: int) -> str:
if is_correct: if is_correct:
response = '**:tada: {answer} is correct, {sender_name}!**' response = ':tada: **{answer}** is correct, {sender_name}!'
else: else:
if num_answers >= 3: if num_answers >= 3:
response = '**:disappointed: WRONG, {sender_name}!** The correct answer is {answer}.' response = ':disappointed: WRONG, {sender_name}! The correct answer is **{answer}**.'
else: else:
response = '**:disappointed: WRONG, {sender_name}!** {option} is not correct.' response = ':disappointed: WRONG, {sender_name}! {option} is not correct.'
return response return response
def handle_answer(quiz: Dict[str, Any], option: str, quiz_id: str, def handle_answer(quiz: Dict[str, Any], option: str, quiz_id: str,