def test_multiple_choice(self):
        question = factories.Question(
            question_type=Question.QuestionType.MULTIPLE_CHOICE,
            answer_type=Question.AnswerType.TEXT,
        )
        a1 = factories.TextAnswer(question=question,
                                  content__text='One',
                                  is_correct=True)
        a2 = factories.TextAnswer(question=question, content__text='Two')
        a3 = factories.TextAnswer(question=question, content__text='Three')
        a4 = factories.TextAnswer(question=question, content__text='Four')
        wrong_responses = [
            UserResponse.objects.create(
                profile=profile_factories.User().profile,
                question=question,
                content=a,
            ) for a in [a2, a3, a4]
        ]
        right_response = UserResponse.objects.create(
            profile=profile_factories.User().profile,
            question=question,
            content=a1,
        )
        for r in wrong_responses:
            self.assertFalse(r.check_response())
            self.assertFalse(r.is_correct)
            self.assertIsNotNone(r.answered_on)

        self.assertTrue(right_response.check_response())
        self.assertTrue(right_response.is_correct)
        self.assertIsNotNone(right_response.answered_on)
 def test_transfer_lesson_progress_some_actions(self):
     mock_session = {'lessons': {}}
     lessons = factories.Lesson.create_batch(2)
     for l in lessons:
         questions = factories.Question.create_batch(2)
         responses = [{
             'question': q.pk,
             'content_type': 14,
             'content': {
                 'text': 'Random Text'
             },
             'is_correct': True,
             'answered_on': timezone.now().isoformat()
         } for q in questions]
         mock_session['lessons'][str(l.pk)] = {
             'score': 0,
             'status': 0,
             'completed_on': None,
             'responses': responses,
         }
     self.assertFalse(LessonProgress.objects.exists())
     self.assertFalse(UserResponse.objects.exists())
     request = Mock(session=mock_session)
     user = profile_factories.User()
     transfer_lesson_progress(request, user)
     self.assertEqual(LessonProgress.objects.count(), 2)
     self.assertEqual(UserResponse.objects.count(), 4)
Exemple #3
0
 def test_lesson_locking_completion_authed_user(self):
     mock_request = Mock()
     mock_request.user = profile_factories.User()
     self.profile = mock_request.user.profile
     service = ProgressService(mock_request, current_lesson=self.lesson)
     lesson = factories.Lesson(module=self.lesson.module)
     second_service = ProgressService(mock_request, current_lesson=lesson)
     self._run_completion_test(service, second_service, lesson)
 def test_transfer_lesson_progress_nothing_done(self):
     mock_session = {}
     self.assertFalse(LessonProgress.objects.exists())
     self.assertFalse(UserResponse.objects.exists())
     request = Mock(session=mock_session)
     user = profile_factories.User()
     transfer_lesson_progress(request, user)
     self.assertFalse(LessonProgress.objects.exists())
     self.assertFalse(UserResponse.objects.exists())
Exemple #5
0
 def test_get_next_question_authed_user(self):
     mock_request = Mock()
     mock_request.user = profile_factories.User()
     self.profile = mock_request.user.profile
     service = ProgressService(mock_request, current_lesson=self.lesson)
     service.unlock_lesson(self.lesson)
     self._run_service_test(service)
     # we responded to each question twice
     self.assertEqual(UserResponse.objects.count(), len(self.questions) * 2)
 def test_single_answer(self):
     question = factories.Question(
         question_type=Question.QuestionType.SINGLE_ANSWER,
         answer_type=Question.AnswerType.VECTOR,
     )
     factories.VectorAnswer(question=question, content__angle=90)
     wrong = factories.Vector(angle=10)
     right = factories.Vector(angle=90)
     wrong_response = UserResponse.objects.create(
         profile=profile_factories.User().profile,
         question=question,
         content=wrong)
     self.assertFalse(wrong_response.check_response())
     self.assertFalse(wrong_response.is_correct)
     self.assertIsNotNone(wrong_response.answered_on)
     right_response = UserResponse.objects.create(
         profile=profile_factories.User().profile,
         question=question,
         content=right)
     self.assertTrue(right_response.check_response())
     self.assertTrue(right_response.is_correct)
     self.assertIsNotNone(right_response.answered_on)
Exemple #7
0
    def test_response(self):
        user = profile_factories.User()
        data = {
            'vector': {'x_component': 0, 'y_component': 1}
        }
        last_score = 0
        r = self.app.post_json(self.url.format(self.question.uuid), data, user=user)
        self.assertTrue(r.json['was_correct'])
        self.assertEqual(r.json['score'], last_score + ProgressServiceBase.CORRECT_RESPONSE_VALUE)
        self.assertNotIn('correct_answer', r.json)
        last_score = r.json['score']

        # now incorrect answer
        data['vector']['x_component'] = 1
        r = self.app.post_json(self.url.format(self.question.uuid), data, user=user)
        self.assertFalse(r.json['was_correct'])
        self.assertEqual(r.json['score'], last_score + ProgressServiceBase.INCORRECT_RESPONSE_VALUE)
        self.assertIn('correct_answer', r.json)
Exemple #8
0
    def test_get_next_question(self):
        user = profile_factories.User()
        r = self.app.get(self.url.format(self.lesson.uuid), user=user)
        q = r.json
        self.validate_lesson(q.pop('lesson'), self.lesson)
        self.validate_question(q, self.questions[0])

        # if we call again without providing the previous question uuid, we get
        # the same question back
        r = self.app.get(self.url.format(self.lesson.uuid), user=user)
        q = r.json
        self.validate_lesson(q.pop('lesson'), self.lesson)
        self.validate_question(q, self.questions[0])

        # but if we provide the previous uuid, we progress
        r = self.app.get(
            self.url.format(self.lesson.uuid),
            {'previous_question': self.questions[0].uuid},
            user=user
        )
        q = r.json
        self.validate_lesson(q.pop('lesson'), self.lesson)
        self.validate_question(q, self.questions[1])

        # but if we provide the previous uuid, we progress
        r = self.app.get(
            self.url.format(self.lesson.uuid),
            {'previous_question': self.questions[1].uuid},
            user=user
        )
        q = r.json
        self.validate_lesson(q.pop('lesson'), self.lesson)
        self.validate_question(q, self.questions[2])

        # and now we loop around
        # but if we provide the previous uuid, we progress
        r = self.app.get(
            self.url.format(self.lesson.uuid),
            {'previous_question': self.questions[2].uuid},
            user=user
        )
        q = r.json
        self.validate_lesson(q.pop('lesson'), self.lesson)
        self.validate_question(q, self.questions[0])
Exemple #9
0
    def test_get_module_with_lessons_lock_complete(self):
        user = profile_factories.User()
        # first moudle auto-unlocks
        r = self.app.get(self.url.format(self.module.uuid), {'expand': 'lessons'}, user=user)
        m = r.json
        lessons = m.pop('lessons')
        self.assertEqual(m['status'], 'unlocked')
        self.assertEqual(m['lesson_completed_count'], 0)
        self.assertEqual(lessons[0]['status'], 'unlocked')
        self.assertEqual(lessons[1]['status'], 'locked')
        for lesson_response, lesson in zip(lessons, self.lessons):
            self.validate_lesson(lesson_response, lesson)
        self.validate_module(m, self.module)

        # complete the first lesson
        LessonProgress.objects.filter(
            profile=user.profile,
            lesson=self.lessons[0]
        ).update(status=LessonProgress.Status.COMPLETE, completed_on=timezone.now())
        r = self.app.get(self.url.format(self.module.uuid), {'expand': 'lessons'}, user=user)
        m = r.json
        lessons = m.pop('lessons')
        self.assertEqual(m['status'], 'unlocked')
        self.assertEqual(m['lesson_completed_count'], 1)
        self.assertEqual(lessons[0]['status'], 'complete')
        self.assertEqual(lessons[1]['status'], 'unlocked')

        # complete the second lesson
        LessonProgress.objects.filter(
            profile=user.profile,
            lesson=self.lessons[1]
        ).update(status=LessonProgress.Status.COMPLETE, completed_on=timezone.now())
        r = self.app.get(self.url.format(self.module.uuid), {'expand': 'lessons'}, user=user)
        m = r.json
        lessons = m.pop('lessons')
        self.assertEqual(m['status'], 'complete')
        self.assertEqual(m['lesson_completed_count'], 2)
        self.assertEqual(lessons[0]['status'], 'complete')
        self.assertEqual(lessons[1]['status'], 'complete')
Exemple #10
0
 def test_inserting_new_lesson_authed_user(self):
     mock_request = Mock()
     mock_request.user = profile_factories.User()
     service = ProgressService(mock_request, current_lesson=self.lesson)
     self.run_insertion_test(service)