From 0d62895be42fdee393a0b8bb0ecf4ce4269f6246 Mon Sep 17 00:00:00 2001
From: Diana Huang <dkh@edx.org>
Date: Thu, 7 Aug 2014 14:58:04 -0400
Subject: [PATCH] Modify certificates_show_before_end_date behavior

Hide the certificate notification box when there's
no certificate information, even when the flag
certificates_show_before_end_date is turned on.

ECOM-11
---
 common/djangoapps/student/tests/tests.py | 18 +++++++++++++++++-
 common/djangoapps/student/views.py       |  3 +++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/common/djangoapps/student/tests/tests.py b/common/djangoapps/student/tests/tests.py
index 9afc044f575..1f1baa70028 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 d5a2fc23143..ec049b0b650 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,
-- 
GitLab