diff --git a/common/djangoapps/student/tests/tests.py b/common/djangoapps/student/tests/tests.py index 9afc044f575014cbbac80d41df81c7e31c98da5e..1f1baa700281fa6d611dca02b75e52342af64c17 100644 --- a/common/djangoapps/student/tests/tests.py +++ b/common/djangoapps/student/tests/tests.py @@ -54,7 +54,7 @@ class CourseEndingTest(TestCase): def test_cert_info(self): user = Mock(username="fred") survey_url = "http://a_survey.com" - course = Mock(end_of_course_survey_url=survey_url) + course = Mock(end_of_course_survey_url=survey_url, certificates_show_before_end=False) self.assertEqual(_cert_info(user, course, None), {'status': 'processing', @@ -133,6 +133,22 @@ class CourseEndingTest(TestCase): 'mode': 'honor' }) + # test when the status is true, we get the correct results out + course2.certificates_show_before_end = True + cert_status = {'status': 'unavailable'} + self.assertIsNone(_cert_info(user, course2, cert_status)) + + cert_status = {'status': 'notpassing', 'grade': '67', + 'download_url': download_url, 'mode': 'honor'} + self.assertEqual(_cert_info(user, course2, cert_status), + {'status': 'notpassing', + 'show_disabled_download_button': False, + 'show_download_url': False, + 'show_survey_button': False, + 'grade': '67', + 'mode': 'honor' + }) + @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) class DashboardTest(TestCase): diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index d5a2fc23143b1bfcba3048880439b49b0a5d0062..ec049b0b6501c05cdc2dd66896c5c065a2a9a0b1 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -285,6 +285,9 @@ def _cert_info(user, course, cert_status): if cert_status is None: return default_info + if cert_status['status'] == 'unavailable' and course.certificates_show_before_end: + return None + status = template_state.get(cert_status['status'], default_status) d = {'status': status,