Exemple #1
0
    def test_handle_answer_three_failed_attempts(self) -> None:
        quiz, bot_handler = self.get_test_quiz()
        # create test storage for a question which has been incorrectly answered twice
        quiz['answered_options'] = ['C', 'B']
        update_quiz(quiz, 'Q001', bot_handler)

        # test response  and storage after three failed attempts
        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.assertTrue(start_new_question)
        quiz_reset = json.loads(bot_handler.storage.get('Q001'))
        self.assertEqual(quiz_reset['pending'], False)

        # test response after question has ended
        incorrect_answers = ['B', 'C', 'D']
        for ans in incorrect_answers:
            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.assertFalse(start_new_question)
        start_new_question, response = handle_answer(quiz, 'A', 'Q001', bot_handler, 'Test User')
        self.assertEqual(response, ':tada: **Amphibian** is correct, Test User!')
        self.assertFalse(start_new_question)

        # test storage after question has ended
        quiz_reset = json.loads(bot_handler.storage.get('Q001'))
        self.assertEqual(quiz_reset['pending'], False)
    def test_handle_answer_three_failed_attempts(self) -> None:
        quiz, bot_handler = self.get_test_quiz()
        # create test storage for a question which has been incorrectly answered twice
        quiz['answered_options'] = ['C', 'B']
        update_quiz(quiz, 'Q001', bot_handler)

        # test response  and storage after three failed attempts
        start_new_question, response = handle_answer(quiz, 'D', 'Q001', bot_handler)
        self.assertEqual(response, '**WRONG!** :disappointed: The correct answer is Amphibian.')
        self.assertTrue(start_new_question)
        quiz_reset = json.loads(bot_handler.storage.get('Q001'))
        self.assertEqual(quiz_reset['pending'], False)

        # test response after question has ended
        incorrect_answers = ['B', 'C', 'D']
        for ans in incorrect_answers:
            start_new_question, response = handle_answer(quiz, ans, 'Q001', bot_handler)
            self.assertEqual(response, '**WRONG!** :disappointed: The correct answer is Amphibian.')
            self.assertFalse(start_new_question)
        start_new_question, response = handle_answer(quiz, 'A', 'Q001', bot_handler)
        self.assertEqual(response, '**CORRECT!** Amphibian :tada:')
        self.assertFalse(start_new_question)

        # test storage after question has ended
        quiz_reset = json.loads(bot_handler.storage.get('Q001'))
        self.assertEqual(quiz_reset['pending'], False)
Exemple #3
0
    def test_handle_answer(self) -> None:
        quiz, bot_handler = self.get_test_quiz()
        # create test initial storage
        update_quiz(quiz, 'Q001', bot_handler)

        # test for a correct answer
        start_new_question, response = handle_answer(quiz, 'A', 'Q001', bot_handler, 'Test user')
        self.assertTrue(start_new_question)
        self.assertEqual(response, ':tada: **Amphibian** is correct, Test user!')

        # test for an incorrect answer
        start_new_question, response = handle_answer(quiz, 'D', 'Q001', bot_handler, 'Test User')
        self.assertFalse(start_new_question)
        self.assertEqual(response, ':disappointed: WRONG, Test User! D is not correct.')
    def test_handle_answer(self) -> None:
        quiz, bot_handler = self.get_test_quiz()
        # create test initial storage
        update_quiz(quiz, 'Q001', bot_handler)

        # test for a correct answer
        start_new_question, response = handle_answer(quiz, 'A', 'Q001', bot_handler)
        self.assertTrue(start_new_question)
        self.assertEqual(response, '**CORRECT!** Amphibian :tada:')

        # test for an incorrect answer
        start_new_question, response = handle_answer(quiz, 'D', 'Q001', bot_handler)
        self.assertFalse(start_new_question)
        self.assertEqual(response, '**WRONG!** D is not correct :disappointed:')
    def test_handle_answer(self) -> None:
        quiz, bot_handler = self.get_test_quiz()
        # create test initial storage
        update_quiz(quiz, 'Q001', bot_handler)

        # test for a correct answer
        start_new_question, response = handle_answer(quiz, 'A', 'Q001',
                                                     bot_handler)
        self.assertTrue(start_new_question)
        self.assertEqual(response, '**CORRECT!** Amphibian :tada:')

        # test for an incorrect answer
        start_new_question, response = handle_answer(quiz, 'D', 'Q001',
                                                     bot_handler)
        self.assertFalse(start_new_question)
        self.assertEqual(response,
                         '**WRONG!** D is not correct :disappointed:')