Update program detail fragment.

LEARNER-3755
This commit is contained in:
Waheed Ahmed
2018-01-11 17:11:56 +05:00
parent 6215945b6f
commit c68b50d964
9 changed files with 108 additions and 30 deletions

View File

@@ -3,6 +3,7 @@
import datetime
import json
import uuid
from copy import deepcopy
import ddt
import httpretty
@@ -823,7 +824,7 @@ class TestProgramDataExtender(ModuleStoreTestCase):
"""Tests of the program data extender utility class."""
maxDiff = None
sku = 'abc123'
checkout_path = '/basket'
checkout_path = '/basket/add'
instructors = {
'instructors': [
{
@@ -852,7 +853,11 @@ class TestProgramDataExtender(ModuleStoreTestCase):
def _assert_supplemented(self, actual, **kwargs):
"""DRY helper used to verify that program data is extended correctly."""
self.course_run.update(
program = deepcopy(self.program)
course_run = deepcopy(self.course_run)
course = deepcopy(self.catalog_course)
course_run.update(
dict(
{
'certificate_url': None,
@@ -868,10 +873,10 @@ class TestProgramDataExtender(ModuleStoreTestCase):
)
)
self.catalog_course['course_runs'] = [self.course_run]
self.program['courses'] = [self.catalog_course]
course['course_runs'] = [course_run]
program['courses'] = [course]
self.assertEqual(actual, self.program)
self.assertEqual(actual, program)
@ddt.data(-1, 0, 1)
def test_is_enrollment_open(self, days_offset):
@@ -887,15 +892,13 @@ class TestProgramDataExtender(ModuleStoreTestCase):
self._assert_supplemented(data)
@ddt.data(
(False, None, False),
(True, MODES.audit, True),
(True, MODES.verified, False),
)
@ddt.unpack
@mock.patch(UTILS_MODULE + '.CourseMode.mode_for_course')
def test_student_enrollment_status(self, is_enrolled, enrolled_mode, is_upgrade_required, mock_get_mode):
"""Verify that program data is supplemented with the student's enrollment status."""
expected_upgrade_url = '{root}/{path}?sku={sku}'.format(
expected_upgrade_url = '{root}/{path}/?sku={sku}'.format(
root=ECOMMERCE_URL_ROOT,
path=self.checkout_path.strip('/'),
sku=self.sku,
@@ -1275,6 +1278,14 @@ class TestProgramDataExtender(ModuleStoreTestCase):
self.assertTrue(data['is_learner_eligible_for_one_click_purchase'])
self.assertEqual(set(data['skus']), expected_skus)
def test_course_url_with_mobile_only(self):
"""
Verify that correct course url is returned for mobile.
"""
data = ProgramDataExtender(self.program, self.user, mobile_only=True).extend()
expected_course_url = 'edxapp://enrolled_course_info?course_id={}'.format(self.course.id)
self._assert_supplemented(data, course_url=expected_course_url)
@skip_unless_lms
@mock.patch(UTILS_MODULE + '.get_credentials')

View File

@@ -82,6 +82,7 @@ class ProgramProgressMeter(object):
def __init__(self, site, user, enrollments=None, uuid=None, mobile_only=False):
self.site = site
self.user = user
self.mobile_only = mobile_only
self.enrollments = enrollments or list(CourseEnrollment.enrollments_for_user(self.user))
self.enrollments.sort(key=lambda e: e.created, reverse=True)
@@ -106,7 +107,7 @@ class ProgramProgressMeter(object):
if uuid:
self.programs = [get_programs(self.site, uuid=uuid)]
else:
self.programs = attach_program_detail_url(get_programs(self.site), mobile_only)
self.programs = attach_program_detail_url(get_programs(self.site), self.mobile_only)
def invert_programs(self):
"""Intersect programs and enrollments.
@@ -407,9 +408,11 @@ class ProgramDataExtender(object):
program_data (dict): Representation of a program.
user (User): The user whose enrollments to inspect.
"""
def __init__(self, program_data, user):
def __init__(self, program_data, user, mobile_only=False):
self.data = program_data
self.user = user
self.mobile_only = mobile_only
self.data.update({'is_mobile_only': self.mobile_only})
self.course_run_key = None
self.course_overview = None
@@ -452,7 +455,10 @@ class ProgramDataExtender(object):
) if certificate_uuid else None
def _attach_course_run_course_url(self, run_mode):
run_mode['course_url'] = reverse('course_root', args=[self.course_run_key])
if self.mobile_only:
run_mode['course_url'] = 'edxapp://enrolled_course_info?course_id={}'.format(run_mode.get('key'))
else:
run_mode['course_url'] = reverse('course_root', args=[self.course_run_key])
def _attach_course_run_enrollment_open_date(self, run_mode):
run_mode['enrollment_open_date'] = strftime_localized(self.enrollment_start, 'SHORT_DATE')
@@ -498,6 +504,9 @@ class ProgramDataExtender(object):
def _attach_course_run_may_certify(self, run_mode):
run_mode['may_certify'] = self.course_overview.may_certify()
def _attach_course_run_is_mobile_only(self, run_mode):
run_mode['is_mobile_only'] = self.mobile_only
def _filter_out_courses_with_entitlements(self, courses):
"""
Removes courses for which the current user already holds an applicable entitlement.
@@ -670,7 +679,6 @@ def get_certificates(user, extended_program):
return certificates
# pylint: disable=missing-docstring
class ProgramMarketingDataExtender(ProgramDataExtender):
"""
Utility for extending program data meant for the program marketing page which lives in the