'Tests that the higher of the persisted grade and the grade
from the certs table is used on the learner dashboard.'

@ddt.data((0.7, 0.6), (0.6, 0.7), (None, 0.7), (None, 0.0), (0.7, None), (0.0, None), (0.7, 0.0), (0.0, 0.7))
@ddt.unpack
def test_cert_grade(self, persisted_grade, cert_grade):

    expected_grade = max(persisted_grade, cert_grade)
    user = Mock(username='fred', id='1')
    survey_url = 'http://a_survey.com'
    course = Mock(end_of_course_survey_url=survey_url, certificates_display_behavior='end', id=CourseLocator(org='x', course='y', run='z'))
    course_mode = 'honor'
    if (cert_grade is not None):
        cert_status = {'status': 'generating', 'grade': unicode(cert_grade), 'mode': 'honor'}
    else:
        cert_status = {'status': 'generating', 'mode': 'honor'}
    with patch('lms.djangoapps.grades.new.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, course_mode), {'status': 'generating', 'show_disabled_download_button': True, 'show_download_url': False, 'show_survey_button': True, 'survey_url': survey_url, 'grade': unicode(expected_grade), 'mode': 'honor', 'linked_in_url': None, 'can_unenroll': False})
