EDUCATOR-526 Update view cert button to only appear after availability

date has passed
This commit is contained in:
Sofiya Semenova
2017-07-31 19:54:11 +00:00
committed by Sofiya Semenova
parent 7bc87a5f56
commit 76f1df6b0e
11 changed files with 99 additions and 23 deletions

View File

@@ -516,6 +516,7 @@ class DashboardTest(ModuleStoreTestCase):
expiration_datetime=datetime.now(pytz.UTC) - timedelta(days=1)
)
self.course.certificate_available_date = datetime.now(pytz.UTC) - timedelta(days=1)
CourseEnrollment.enroll(self.user, self.course.id, mode='honor')
self.course.start = datetime.now(pytz.UTC) - timedelta(days=2)

View File

@@ -93,7 +93,12 @@ def course_start_date_is_default(start, advertised_start):
return advertised_start is None and start == DEFAULT_START_DATE
def may_certify_for_course(certificates_display_behavior, certificates_show_before_end, has_ended):
def may_certify_for_course(
certificates_display_behavior,
certificates_show_before_end,
has_ended,
certificate_available_date
):
"""
Returns whether it is acceptable to show the student a certificate download
link for a course.
@@ -105,12 +110,24 @@ def may_certify_for_course(certificates_display_behavior, certificates_show_befo
certificates_show_before_end (bool): whether user can download the
course's certificates before the course has ended.
has_ended (bool): Whether the course has ended.
certificate_available_date (datetime): the date the certificate is available on for the course.
"""
show_early = (
certificates_display_behavior in ('early_with_info', 'early_no_info')
or certificates_show_before_end
)
return show_early or has_ended
past_availability_date = (
certificate_available_date
and certificate_available_date < datetime.now(utc)
)
if show_early:
return True
if past_availability_date:
return True
if (certificate_available_date is None) and has_ended:
return True
return False
def sorting_score(start, advertised_start, announcement):

View File

@@ -1065,7 +1065,8 @@ class CourseDescriptor(CourseFields, SequenceDescriptor, LicenseMixin):
return course_metadata_utils.may_certify_for_course(
self.certificates_display_behavior,
self.certificates_show_before_end,
self.has_ended()
self.has_ended(),
self.certificate_available_date
)
def has_started(self):

View File

@@ -161,11 +161,14 @@ class CourseMetadataUtilsTestCase(TestCase):
TestScenario((DEFAULT_START_DATE, None), True),
]),
FunctionTest(may_certify_for_course, [
TestScenario(('early_with_info', True, True), True),
TestScenario(('early_no_info', False, False), True),
TestScenario(('end', True, False), True),
TestScenario(('end', False, True), True),
TestScenario(('end', False, False), False),
TestScenario(('early_with_info', True, True, test_datetime), True),
TestScenario(('early_no_info', False, False, test_datetime), True),
TestScenario(('end', True, False, test_datetime), True),
TestScenario(('end', False, True, test_datetime), True),
TestScenario(('end', False, False, _NEXT_WEEK), False),
TestScenario(('end', False, False, _LAST_WEEK), True),
TestScenario(('end', False, False, None), False),
TestScenario(('early_with_info', False, False, None), True),
]),
]