def test_not_another_exercise(self):
        UserFactory(user_id='user')

        response = index(
            MockRequest(
                text='no',
                user_id='user',
                conversation_token=TOKEN_DO_ANOTHER_EXERCISE,
            ))
        response_text = GoogleTestUtils.get_text_from_google_response(response)

        self.assertIn("Goodbye", response_text)
        self.assertTrue(GoogleTestUtils.google_response_is_tell(response))
    def test_basic_full_conversation(self):
        exercise = ExerciseFactory()
        QuestionFactory(exercise=exercise,
                        question='question one',
                        answer='one')
        QuestionFactory(exercise=exercise,
                        question='question two',
                        answer='two')

        # New user, starting the exercise and getting the first question
        response = _make_request_and_return_text(user_id='user')
        self.assertIn('Welcome', response)
        if 'question one' in response:
            self.assertNotIn('question two', response)
            first_question = 1
        else:
            self.assertIn('question two', response)
            first_question = 2

        # Test getting the answer wrong
        response = _make_request_and_return_text(user_id='user', text='WRONG')
        self.assertIn('incorrect', response)

        # Get the answer right, will get the next question
        answer = 'one' if first_question == 1 else 'two'
        response = _make_request_and_return_text(user_id='user', text=answer)
        expected_question = 'question two' if first_question == 1 else 'question one'
        self.assertIn(expected_question, response)

        # Get the answer right, asks if we want to try another exercise
        answer = 'one' if first_question == 2 else 'two'
        raw_response = index(MockRequest(user_id='user', text=answer))
        response_text = GoogleTestUtils.get_text_from_google_response(
            raw_response)
        self.assertIn('Would you like to try another exercise', response_text)
        conversation_token = (
            GoogleTestUtils.get_conversation_token_from_google_response(
                raw_response))
        self.assertIsNotNone(conversation_token)

        # We don't want to try another, goodebye
        raw_response = index(
            MockRequest(user_id='user',
                        text='no',
                        conversation_token=conversation_token))
        response_text = GoogleTestUtils.get_text_from_google_response(
            raw_response)
        self.assertIn('Goodbye', response_text)
        self.assertTrue(GoogleTestUtils.google_response_is_tell(raw_response))
    def test_do_another_exercise(self):
        UserFactory(user_id='user')
        QuestionFactory(question="What's a pea?")

        response = index(
            MockRequest(
                text='yes',
                user_id='user',
                conversation_token=TOKEN_DO_ANOTHER_EXERCISE,
            ))
        response_text = GoogleTestUtils.get_text_from_google_response(response)

        self.assertIn("let's go", response_text)
        self.assertIn(" What's a pea?", response_text)
        self.assertTrue(GoogleTestUtils.google_response_is_ask(response))
def _make_request_and_return_text(text=None,
                                  user_id=None,
                                  conversation_token=None):
    response = index(
        MockRequest(text=text,
                    user_id=user_id,
                    conversation_token=conversation_token))
    return GoogleTestUtils.get_text_from_google_response(response)
    def test_exercise_completion(self):
        exercise = ExerciseFactory()
        ExerciseStateFactory(
            user=UserFactory(user_id='user'),
            exercise=exercise,
            current_question=QuestionFactory(exercise=exercise,
                                             answer='right'),
            completed=False,
        )

        response = index(MockRequest(text='right', user_id='user'))
        response_text = GoogleTestUtils.get_text_from_google_response(response)

        self.assertIn("finished", response_text)
        self.assertTrue(ExerciseState.objects.get().completed)
        self.assertEqual(
            TOKEN_DO_ANOTHER_EXERCISE,
            GoogleTestUtils.get_conversation_token_from_google_response(
                response))
Exemple #6
0
 def test_health_check_ends_conversation(self):
     response = index(MockRequest(health_check=True))
     assert GoogleTestUtils.google_response_is_tell(response)
Exemple #7
0
 def test_talk_to_ends_conversation(self):
     response = index(MockRequest(text="talk to ultimate quiz"))
     assert GoogleTestUtils.google_response_is_tell(response)
     response_text = GoogleTestUtils.get_text_from_google_response(response)
     assert 'True Sight' in response_text
     assert 'Goodbye' in response_text