Ejemplo n.º 1
0
    def test_cert_grade(self, persisted_grade, cert_grade):
        """
        Tests that the higher of the persisted grade and the grade
        from the certs table is used on the learner dashboard.
        """
        expected_grade = max(filter(lambda x: x is not None, [persisted_grade, cert_grade]))
        user = UserFactory.create()
        survey_url = "http://a_survey.com"
        course = CourseOverviewFactory.create(
            end_of_course_survey_url=survey_url,
            certificates_display_behavior='end',
        )

        if cert_grade is not None:
            cert_status = {'status': 'generating', 'grade': str(cert_grade), 'mode': 'honor', 'uuid': None}
        else:
            cert_status = {'status': 'generating', 'mode': 'honor', 'uuid': None}

        with patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.read') as patch_persisted_grade:
            patch_persisted_grade.return_value = Mock(percent=persisted_grade)
            self.assertEqual(
                _cert_info(user, course, cert_status),
                {
                    'status': 'generating',
                    'show_survey_button': True,
                    'survey_url': survey_url,
                    'grade': str(expected_grade),
                    'mode': 'honor',
                    'linked_in_url': None,
                    'can_unenroll': False,
                }
            )
Ejemplo n.º 2
0
    def test_cert_grade_no_grades(self):
        """
        Tests that the default cert info is returned
        when the learner has no persisted grade or grade
        in the certs table.
        """
        user = UserFactory.create()
        survey_url = "http://a_survey.com"
        course = CourseOverviewFactory.create(
            end_of_course_survey_url=survey_url,
            certificates_display_behavior='end',
        )
        cert_status = {'status': 'generating', 'mode': 'honor', 'uuid': None}

        with patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.read') as patch_persisted_grade:
            patch_persisted_grade.return_value = None
            assert _cert_info(user, course, cert_status) == {'status': 'processing', 'show_survey_button': False,
                                                             'can_unenroll': True}
Ejemplo n.º 3
0
    def test_cert_info(self):
        user = UserFactory.create()
        survey_url = "http://a_survey.com"
        course = CourseOverviewFactory.create(
            end_of_course_survey_url=survey_url,
            certificates_display_behavior='end',
        )
        cert = GeneratedCertificateFactory.create(
            user=user,
            course_id=course.id,
            status=CertificateStatuses.downloadable,
            mode='honor',
            grade='67',
            download_url='http://s3.edx/cert')

        assert _cert_info(user, course, None) ==\
               {'status': 'processing', 'show_survey_button': False, 'can_unenroll': True}

        cert_status = {'status': 'unavailable', 'mode': 'honor', 'uuid': None}
        assert _cert_info(user, course, cert_status) == {
            'status': 'processing',
            'show_survey_button': False,
            'mode': 'honor',
            'linked_in_url': None,
            'can_unenroll': True
        }

        cert_status = {
            'status': 'generating',
            'grade': '0.67',
            'mode': 'honor',
            'uuid': None
        }
        with patch(
                'lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.read'
        ) as patch_persisted_grade:
            patch_persisted_grade.return_value = Mock(percent=1.0)
            assert _cert_info(user, course, cert_status) == {
                'status': 'generating',
                'show_survey_button': True,
                'survey_url': survey_url,
                'grade': '1.0',
                'mode': 'honor',
                'linked_in_url': None,
                'can_unenroll': False
            }

        cert_status = {
            'status': 'generating',
            'grade': '0.67',
            'mode': 'honor',
            'uuid': None
        }
        assert _cert_info(user, course, cert_status) == {
            'status': 'generating',
            'show_survey_button': True,
            'survey_url': survey_url,
            'grade': '0.67',
            'mode': 'honor',
            'linked_in_url': None,
            'can_unenroll': False
        }

        cert_status = {
            'status': 'downloadable',
            'grade': '0.67',
            'download_url': cert.download_url,
            'mode': 'honor',
            'uuid': 'fakeuuidbutitsfine',
        }
        assert _cert_info(user, course, cert_status) == {
            'status': 'downloadable',
            'download_url': cert.download_url,
            'show_survey_button': True,
            'survey_url': survey_url,
            'grade': '0.67',
            'mode': 'honor',
            'linked_in_url': None,
            'can_unenroll': False
        }

        cert_status = {
            'status': 'notpassing',
            'grade': '0.67',
            'download_url': cert.download_url,
            'mode': 'honor',
            'uuid': 'fakeuuidbutitsfine',
        }
        assert _cert_info(user, course, cert_status) == {
            'status': 'notpassing',
            'show_survey_button': True,
            'survey_url': survey_url,
            'grade': '0.67',
            'mode': 'honor',
            'linked_in_url': None,
            'can_unenroll': True
        }

        # Test a course that doesn't have a survey specified
        course2 = Mock(end_of_course_survey_url=None,
                       id=CourseLocator(org="a", course="b", run="c"))
        cert_status = {
            'status': 'notpassing',
            'grade': '0.67',
            'download_url': cert.download_url,
            'mode': 'honor',
            'uuid': 'fakeuuidbutitsfine'
        }
        assert _cert_info(user, course2, cert_status) == {
            'status': 'notpassing',
            'show_survey_button': False,
            'grade': '0.67',
            'mode': 'honor',
            'linked_in_url': None,
            'can_unenroll': True
        }

        # test when the display is unavailable or notpassing, we get the correct results out
        course2.certificates_display_behavior = 'early_no_info'
        cert_status = {'status': 'unavailable', 'mode': 'honor', 'uuid': None}
        assert _cert_info(user, course2, cert_status) == {
            'status': 'processing',
            'show_survey_button': False,
            'can_unenroll': True
        }

        cert_status = {
            'status': 'notpassing',
            'grade': '0.67',
            'download_url': cert.download_url,
            'mode': 'honor',
            'uuid': 'fakeuuidbutitsfine'
        }
        assert _cert_info(user, course2, cert_status) == {
            'status': 'processing',
            'show_survey_button': False,
            'can_unenroll': True
        }