Commit 87f07386 by Jeff LaJoie

Adds in tests and fixes model code for setting expired_at as well as handles…

Adds in tests and fixes model code for setting expired_at as well as handles edge case for fulfilled and expired
parent a3df1073
......@@ -218,13 +218,13 @@ class CourseEntitlement(TimeStampedModel):
def to_dict(self):
""" Convert entitlement to dictionary representation. """
entitlement_expiration_date, entitlement_expired_at = None, None
entitlement_expired_at = strftime_localized(
self.expired_at_datetime, 'SHORT_DATE') if self.expired_at_datetime else None
if self.get_days_until_expiration() < settings.ENTITLEMENT_EXPIRED_ALERT_PERIOD:
entitlement_expiration_date = strftime_localized(
datetime.now(tz=pytz.UTC) + timedelta(days=self.get_days_until_expiration()),
'SHORT_DATE'
)
entitlement_expired_at = strftime_localized(
self.expired_at_datetime, 'SHORT_DATE') if self.expired_at_datetime else None
return {
'uuid': str(self.uuid),
......
......@@ -237,6 +237,7 @@ class StudentDashboardTests(SharedModuleStoreTestCase, MilestonesTestCaseMixin):
ENABLED_SIGNALS = ['course_published']
TOMORROW = datetime.datetime.now(pytz.utc) + datetime.timedelta(days=1)
THREE_YEARS_AGO = datetime.datetime.now(pytz.utc) - datetime.timedelta(days=(365 * 3))
MOCK_SETTINGS = {
'FEATURES': {
'DISABLE_START_DATES': False,
......@@ -365,6 +366,29 @@ class StudentDashboardTests(SharedModuleStoreTestCase, MilestonesTestCaseMixin):
@patch('student.views.get_course_runs_for_course')
@patch.object(CourseOverview, 'get_from_id')
def test_unfulfilled_expired_entitlement(self, mock_course_overview, mock_course_runs):
"""
When a learner has an unfulfilled entitlement but expired, their course dashboard should have:
- a hidden 'View Course' button
- a message saying that they can no longer select a session
"""
CourseEntitlementFactory(user=self.user, created=self.THREE_YEARS_AGO)
mock_course_overview.return_value = CourseOverviewFactory(start=self.TOMORROW)
mock_course_runs.return_value = [
{
'key': 'course-v1:FAKE+FA1-MA1.X+3T2017',
'enrollment_end': self.TOMORROW,
'pacing_type': 'instructor_paced',
'type': 'verified'
}
]
response = self.client.get(self.path)
self.assertIn('class="enter-course hidden"', response.content)
self.assertIn('You can no longer select a session', response.content)
self.assertNotIn('<div class="course-entitlement-selection-container ">', response.content)
@patch('student.views.get_course_runs_for_course')
@patch.object(CourseOverview, 'get_from_id')
@patch('opaque_keys.edx.keys.CourseKey.from_string')
def test_fulfilled_entitlement(self, mock_course_key, mock_course_overview, mock_course_runs):
"""
......@@ -392,3 +416,32 @@ class StudentDashboardTests(SharedModuleStoreTestCase, MilestonesTestCaseMixin):
response = self.client.get(self.path)
self.assertEqual(response.content.count('<li class="course-item">'), 1)
self.assertIn('<button class="change-session btn-link "', response.content)
@patch('student.views.get_course_runs_for_course')
@patch.object(CourseOverview, 'get_from_id')
@patch('opaque_keys.edx.keys.CourseKey.from_string')
def test_fulfilled_expired_entitlement(self, mock_course_key, mock_course_overview, mock_course_runs):
"""
When a learner has a fulfilled entitlement that is expired, their course dashboard should have:
- exactly one course item, meaning it:
- has an entitlement card
- Message that the learner can no longer change sessions
"""
mocked_course_overview = CourseOverviewFactory(
start=self.TOMORROW, self_paced=True, enrollment_end=self.TOMORROW
)
mock_course_overview.return_value = mocked_course_overview
mock_course_key.return_value = mocked_course_overview.id
course_enrollment = CourseEnrollmentFactory(user=self.user, course_id=unicode(mocked_course_overview.id), created=self.THREE_YEARS_AGO)
mock_course_runs.return_value = [
{
'key': mocked_course_overview.id,
'enrollment_end': mocked_course_overview.enrollment_end,
'pacing_type': 'self_paced',
'type': 'verified'
}
]
CourseEntitlementFactory(user=self.user, enrollment_course_run=course_enrollment, created=self.THREE_YEARS_AGO)
response = self.client.get(self.path)
self.assertEqual(response.content.count('<li class="course-item">'), 1)
self.assertIn('You can no longer change sessions.', response.content)
......@@ -154,13 +154,15 @@ from util.course import get_link_for_about_page, get_encoded_course_sharing_utm_
% endif
% endif
</span>
% if entitlement and entitlement_expiration_date:
% if not is_unfulfilled_entitlement:
% if entitlement and not is_unfulfilled_entitlement and entitlement_expiration_date:
<div class="info-expires-at">
<span class="msg-icon fa fa-info" aria-hidden="true"></span>
% if entitlement_expired_at:
${_('You can no longer change sessions.')}
% else:
${_('You can change sessions until {entitlement_expiration_date}.').format(entitlement_expiration_date=entitlement_expiration_date)}
</div>
% endif
</div>
% endif
</div>
<div class="wrapper-course-actions">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment