Пример #1
0
    def test_answers(self) -> None:
        quiz_payload = read_bot_fixture_data('trivia_quiz',
                                             'test_new_question')['response']
        with patch('random.shuffle'):
            quiz = get_quiz_from_payload(quiz_payload)

        # Test initial storage
        self.assertEqual(quiz['question'],
                         'Which class of animals are newts members of?')
        self.assertEqual(quiz['correct_letter'], 'A')
        self.assertEqual(quiz['answers']['D'], 'Mammals')
        self.assertEqual(quiz['answered_options'], [])
        self.assertEqual(quiz['pending'], True)

        # test incorrect answer
        with patch('zulip_bots.bots.trivia_quiz.trivia_quiz.get_quiz_from_id',
                   return_value=json.dumps(quiz)):
            self._test('answer Q001 B',
                       '**WRONG!** B is not correct :disappointed:')

        # test correct answer
        with patch('zulip_bots.bots.trivia_quiz.trivia_quiz.get_quiz_from_id',
                   return_value=json.dumps(quiz)):
            with patch('zulip_bots.bots.trivia_quiz.trivia_quiz.start_new_quiz'
                       ) as mock_new_quiz:
                self._test('answer Q001 A', '**CORRECT!** Amphibian :tada:')
Пример #2
0
 def get_test_quiz(self) -> Tuple[Dict[str, Any], Any]:
     bot_handler = StubBotHandler()
     quiz_payload = read_bot_fixture_data('trivia_quiz',
                                          'test_new_question')['response']
     with patch('random.shuffle'):
         quiz = get_quiz_from_payload(quiz_payload)
     return quiz, bot_handler
Пример #3
0
def mock_salesforce_query(test_name: str, bot_name: str) -> Iterator[None]:
    response_data = read_bot_fixture_data(bot_name, test_name)
    sf_response = response_data.get('response')

    with patch('simple_salesforce.api.Salesforce.query') as mock_query:
        mock_query.return_value = sf_response
        yield
Пример #4
0
def mock_salesforce_query(test_name: str, bot_name: str) -> Iterator[None]:
    response_data = read_bot_fixture_data(bot_name, test_name)
    sf_response = response_data.get('response')

    with patch('simple_salesforce.api.Salesforce.query') as mock_query:
        mock_query.return_value = sf_response
        yield
def mock_dialogflow(test_name: str, bot_name: str) -> Any:
    response_data = read_bot_fixture_data(bot_name, test_name)
    df_request = response_data.get('request')
    df_response = response_data.get('response')

    with patch('apiai.ApiAI.text_request') as mock_text_request:
        request = MockTextRequest()
        request.response = df_response
        mock_text_request.return_value = request
        yield
def mock_dialogflow(test_name: str, bot_name: str) -> Any:
    response_data = read_bot_fixture_data(bot_name, test_name)
    try:
        df_request = response_data['request']
        df_response = response_data['response']
    except KeyError:
        print("ERROR: 'request' or 'response' field not found in fixture.")
        raise

    with patch('apiai.ApiAI.text_request') as mock_text_request:
        request = MockTextRequest()
        request.response = df_response
        mock_text_request.return_value = request
        yield
Пример #7
0
def mock_dialogflow(test_name: str, bot_name: str) -> Iterator[None]:
    response_data = read_bot_fixture_data(bot_name, test_name)
    try:
        df_request = response_data['request']
        df_response = response_data['response']
    except KeyError:
        print("ERROR: 'request' or 'response' field not found in fixture.")
        raise

    with patch('apiai.ApiAI.text_request') as mock_text_request:
        request = MockTextRequest()
        request.response = df_response
        mock_text_request.return_value = request
        yield
Пример #8
0
    def test_answers(self) -> None:
        quiz_payload = read_bot_fixture_data('trivia_quiz', 'test_new_question')['response']
        with patch('random.shuffle'):
            quiz = get_quiz_from_payload(quiz_payload)

        # Test initial storage
        self.assertEqual(quiz['question'], 'Which class of animals are newts members of?')
        self.assertEqual(quiz['correct_letter'], 'A')
        self.assertEqual(quiz['answers']['D'], 'Mammals')
        self.assertEqual(quiz['answered_options'], [])
        self.assertEqual(quiz['pending'], True)

        # test incorrect answer
        with patch('zulip_bots.bots.trivia_quiz.trivia_quiz.get_quiz_from_id',
                   return_value=json.dumps(quiz)):
            self._test('answer Q001 B', '**WRONG!** B is not correct :disappointed:')

        # test correct answer
        with patch('zulip_bots.bots.trivia_quiz.trivia_quiz.get_quiz_from_id',
                   return_value=json.dumps(quiz)):
            with patch('zulip_bots.bots.trivia_quiz.trivia_quiz.start_new_quiz') as mock_new_quiz:
                self._test('answer Q001 A', '**CORRECT!** Amphibian :tada:')
Пример #9
0
 def get_test_quiz(self) -> Tuple[Dict[str, Any], Any]:
     bot_handler = StubBotHandler()
     quiz_payload = read_bot_fixture_data('trivia_quiz', 'test_new_question')['response']
     with patch('random.shuffle'):
         quiz = get_quiz_from_payload(quiz_payload)
     return quiz, bot_handler