Merge pull request #4764 from edx/diana/show-cert-without-end-date
Show Certificates Before End
This commit is contained in:
@@ -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_display_behavior='end')
|
||||
|
||||
self.assertEqual(_cert_info(user, course, None),
|
||||
{'status': 'processing',
|
||||
@@ -133,6 +133,15 @@ class CourseEndingTest(TestCase):
|
||||
'mode': 'honor'
|
||||
})
|
||||
|
||||
# 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'}
|
||||
self.assertIsNone(_cert_info(user, course2, cert_status))
|
||||
|
||||
cert_status = {'status': 'notpassing', 'grade': '67',
|
||||
'download_url': download_url, 'mode': 'honor'}
|
||||
self.assertIsNone(_cert_info(user, course2, cert_status))
|
||||
|
||||
|
||||
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
|
||||
class DashboardTest(TestCase):
|
||||
|
||||
@@ -285,6 +285,11 @@ def _cert_info(user, course, cert_status):
|
||||
if cert_status is None:
|
||||
return default_info
|
||||
|
||||
is_hidden_status = cert_status['status'] in ('unavailable', 'processing', 'generating', 'notpassing')
|
||||
|
||||
if course.certificates_display_behavior == 'early_no_info' and is_hidden_status:
|
||||
return None
|
||||
|
||||
status = template_state.get(cert_status['status'], default_status)
|
||||
|
||||
d = {'status': status,
|
||||
|
||||
@@ -220,8 +220,8 @@ class CourseFields(object):
|
||||
scope=Scope.settings
|
||||
)
|
||||
display_name = String(
|
||||
help=_("Enter the name of the course as it should appear in the edX.org course list."),
|
||||
default="Empty",
|
||||
help=_("Enter the name of the course as it should appear in the edX.org course list."),
|
||||
default="Empty",
|
||||
display_name=_("Course Display Name"),
|
||||
scope=Scope.settings
|
||||
)
|
||||
@@ -453,7 +453,15 @@ class CourseFields(object):
|
||||
display_name=_("Certificates Downloadable Before End"),
|
||||
help=_("Enter true or false. If true, students can download certificates before the course ends, if they've met certificate requirements."),
|
||||
scope=Scope.settings,
|
||||
default=False
|
||||
default=False,
|
||||
deprecated=True
|
||||
)
|
||||
|
||||
certificates_display_behavior = String(
|
||||
display_name=_("Certificates Display Behavior"),
|
||||
help=_("Has three possible states: 'end', 'early_with_info', 'early_no_info'. 'end' is the default behavior, where certificates will only appear after a course has ended. 'early_with_info' will display all certificate information before a course has ended. 'early_no_info' will hide all certificate information unless a student has earned a certificate."),
|
||||
scope=Scope.settings,
|
||||
default="end"
|
||||
)
|
||||
course_image = String(
|
||||
display_name=_("Course About Page Image"),
|
||||
@@ -712,7 +720,8 @@ class CourseDescriptor(CourseFields, SequenceDescriptor):
|
||||
"""
|
||||
Return True if it is acceptable to show the student a certificate download link
|
||||
"""
|
||||
return self.certificates_show_before_end or self.has_ended()
|
||||
show_early = self.certificates_display_behavior in ('early_with_info', 'early_no_info') or self.certificates_show_before_end
|
||||
return show_early or self.has_ended()
|
||||
|
||||
def has_started(self):
|
||||
return datetime.now(UTC()) > self.start
|
||||
|
||||
@@ -49,7 +49,7 @@ class DummySystem(ImportSystem):
|
||||
)
|
||||
|
||||
|
||||
def get_dummy_course(start, announcement=None, is_new=None, advertised_start=None, end=None, certs=False):
|
||||
def get_dummy_course(start, announcement=None, is_new=None, advertised_start=None, end=None, certs='end'):
|
||||
"""Get a dummy course"""
|
||||
|
||||
system = DummySystem(load_error_modules=True)
|
||||
@@ -70,7 +70,7 @@ def get_dummy_course(start, announcement=None, is_new=None, advertised_start=Non
|
||||
{is_new}
|
||||
{advertised_start}
|
||||
{end}
|
||||
certificates_show_before_end="{certs}">
|
||||
certificates_display_behavior="{certs}">
|
||||
<chapter url="hi" url_name="ch" display_name="CH">
|
||||
<html url_name="h" display_name="H">Two houses, ...</html>
|
||||
</chapter>
|
||||
@@ -100,10 +100,12 @@ class HasEndedMayCertifyTestCase(unittest.TestCase):
|
||||
#""".format(org=ORG, course=COURSE)
|
||||
past_end = (datetime.now() - timedelta(days=12)).strftime("%Y-%m-%dT%H:%M:00")
|
||||
future_end = (datetime.now() + timedelta(days=12)).strftime("%Y-%m-%dT%H:%M:00")
|
||||
self.past_show_certs = get_dummy_course("2012-01-01T12:00", end=past_end, certs=True)
|
||||
self.past_noshow_certs = get_dummy_course("2012-01-01T12:00", end=past_end, certs=False)
|
||||
self.future_show_certs = get_dummy_course("2012-01-01T12:00", end=future_end, certs=True)
|
||||
self.future_noshow_certs = get_dummy_course("2012-01-01T12:00", end=future_end, certs=False)
|
||||
self.past_show_certs = get_dummy_course("2012-01-01T12:00", end=past_end, certs='early_with_info')
|
||||
self.past_show_certs_no_info = get_dummy_course("2012-01-01T12:00", end=past_end, certs='early_no_info')
|
||||
self.past_noshow_certs = get_dummy_course("2012-01-01T12:00", end=past_end, certs='end')
|
||||
self.future_show_certs = get_dummy_course("2012-01-01T12:00", end=future_end, certs='early_with_info')
|
||||
self.future_show_certs_no_info = get_dummy_course("2012-01-01T12:00", end=future_end, certs='early_no_info')
|
||||
self.future_noshow_certs = get_dummy_course("2012-01-01T12:00", end=future_end, certs='end')
|
||||
#self.past_show_certs = system.process_xml(sample_xml.format(end=past_end, cert=True))
|
||||
#self.past_noshow_certs = system.process_xml(sample_xml.format(end=past_end, cert=False))
|
||||
#self.future_show_certs = system.process_xml(sample_xml.format(end=future_end, cert=True))
|
||||
@@ -112,15 +114,19 @@ class HasEndedMayCertifyTestCase(unittest.TestCase):
|
||||
def test_has_ended(self):
|
||||
"""Check that has_ended correctly tells us when a course is over."""
|
||||
self.assertTrue(self.past_show_certs.has_ended())
|
||||
self.assertTrue(self.past_show_certs_no_info.has_ended())
|
||||
self.assertTrue(self.past_noshow_certs.has_ended())
|
||||
self.assertFalse(self.future_show_certs.has_ended())
|
||||
self.assertFalse(self.future_show_certs_no_info.has_ended())
|
||||
self.assertFalse(self.future_noshow_certs.has_ended())
|
||||
|
||||
def test_may_certify(self):
|
||||
"""Check that may_certify correctly tells us when a course may wrap."""
|
||||
self.assertTrue(self.past_show_certs.may_certify())
|
||||
self.assertTrue(self.past_noshow_certs.may_certify())
|
||||
self.assertTrue(self.past_show_certs_no_info.may_certify())
|
||||
self.assertTrue(self.future_show_certs.may_certify())
|
||||
self.assertTrue(self.future_show_certs_no_info.may_certify())
|
||||
self.assertFalse(self.future_noshow_certs.may_certify())
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user