Esempio n. 1
0
def test_answer_should_return_random_dunno_answer_below_prediction_threshold(
    mocked_get_random_dunno_answer,
    mocked_get_question_predictions,
    mocked_get_clean_question_input,
    bot: ChatBot,
):
    """
    Unit: Asserts ChatBot.answer returns a random dunno answer when the prediction is BELOW the threshold.
    """
    mocked_get_clean_question_input.return_value = "some random unknown question?"
    mocked_get_question_predictions.return_value = "what's your name", 45  # kiw
    mocked_get_random_dunno_answer.return_value = (
        "Sorry, I didn't catch that! Repeat please?"
    )

    # based on the what's your name question
    expected_answer = "Sorry, I didn't catch that! Repeat please?"

    assert bot.answer("Some random unknown question?") == expected_answer

    mocked_get_clean_question_input.assert_called_once_with(
        "Some random unknown question?"
    )
    mocked_get_question_predictions.assert_called_once_with(
        "some random unknown question?"
    )
    mocked_get_random_dunno_answer.assert_called_once_with()
Esempio n. 2
0
    def receive(self, text_data):
        """
        Receives the decoded text data from a web socket connection
        as an object that can be JSON loaded.

        Temp --> returns the same msg back to the original client.
        """
        logging.info("Received new message: %s", text_data)

        bot = ChatBot()

        raw_question = text_data
        answer = bot.answer(raw_question)

        logging.info("Returning answer: %s", answer)

        # sends the signal of the beginning of a new msg
        self.send(r"<start/>")

        # sends letter by letter through the socket connection
        for letter in answer:
            # small delay for a nice effect purposes
            time.sleep(self.SEND_DELAY)

            # actual socket sending
            self.send(letter)

        # msg is over
        self.send(r"<end/>")
Esempio n. 3
0
def test_answer_should_return_answer_above_prediction_threshold(
    mocked_get_random_dunno_answer,
    mocked_get_question_predictions,
    mocked_get_clean_question_input,
    bot: ChatBot,
):
    """
    Unit: Asserts ChatBot.answer returns an answer when the prediction is ABOVE the threshold.
    """
    mocked_get_clean_question_input.return_value = "what's ur name?"
    mocked_get_question_predictions.return_value = "what's your name", 97

    # based on the what's your name question
    expected_answer = "Hey! My name's Igor! Nice to meet you ^^!"

    assert bot.answer("What's ur name?") == expected_answer

    mocked_get_clean_question_input.assert_called_once_with("What's ur name?")
    mocked_get_question_predictions.assert_called_once_with("what's ur name?")
    mocked_get_random_dunno_answer.assert_not_called()