TNL-7185: Send data, not rendered HTML to the learning MFE

Specifically, send data versions of course_expired_message and
offer_html.

The rendered HTML is still being sent for now, until the learning
MFE is updated to consume the data objects.
This commit is contained in:
Michael Terry
2020-12-11 09:27:27 -05:00
parent 0c57a02119
commit eef72b5ab7
11 changed files with 354 additions and 136 deletions

View File

@@ -19,6 +19,7 @@ from openedx.core.djangoapps.user_api.preferences.api import set_user_preference
from openedx.core.djangolib.testing.utils import CacheIsolationTestCase
from openedx.features.course_duration_limits.access import (
generate_course_expired_message,
get_access_expiration_data,
get_user_course_duration,
get_user_course_expiration_date
)
@@ -43,6 +44,34 @@ class TestAccess(CacheIsolationTestCase):
# But also that the machine-readable version is in there
self.assertIn('data-datetime="%s"' % date.isoformat(), message)
def test_get_access_expiration_data(self):
enrollment = CourseEnrollmentFactory()
overview = enrollment.course
user = enrollment.user
now = timezone.now()
upgrade_deadline = now + timedelta(days=2)
CourseModeFactory(
course_id=enrollment.course.id,
mode_slug=CourseMode.VERIFIED,
expiration_datetime=upgrade_deadline,
)
CourseModeFactory(
course_id=enrollment.course.id,
mode_slug=CourseMode.AUDIT,
)
expiration_date = get_user_course_expiration_date(user, overview)
self.assertIsNotNone(expiration_date)
data = get_access_expiration_data(user, overview)
self.assertEqual(data, {
'expiration_date': expiration_date,
'masquerading_expired_course': False,
'upgrade_deadline': upgrade_deadline,
'upgrade_url': '/dashboard',
})
@ddt.data(
*itertools.product(
itertools.product([None, -2, -1, 1, 2], repeat=2),