def view_programs(request): """View programs in which the user is engaged.""" show_program_listing = ProgramsApiConfig.current().show_program_listing if not show_program_listing: raise Http404 meter = utils.ProgramProgressMeter(request.user) programs = meter.engaged_programs # TODO: Pull 'xseries' string from configuration model. marketing_root = urljoin(settings.MKTG_URLS.get('ROOT'), 'xseries').strip('/') for program in programs: program['display_category'] = utils.get_display_category(program) program['marketing_url'] = '{root}/{slug}'.format( root=marketing_root, slug=program['marketing_slug'] ) context = { 'programs': programs, 'progress': meter.progress, 'xseries_url': marketing_root if ProgramsApiConfig.current().show_xseries_ad else None, 'nav_hidden': True, 'show_program_listing': show_program_listing, 'credentials': get_programs_credentials(request.user, category='xseries'), 'disable_courseware_js': True, 'uses_pattern_library': True } return render_to_response('learner_dashboard/programs.html', context)
def test_get_display_category_success(self): self.create_programs_config() self.mock_programs_api() actual_programs = utils.get_programs(self.user) for program in actual_programs: expected = 'XSeries' self.assertEqual(expected, utils.get_display_category(program))
def test_get_engaged_programs(self): """ Verify that correct programs are returned in the correct order when the user has multiple enrollments. """ self.create_programs_config() self.mock_programs_api() enrollments = self._create_enrollments(*self.COURSE_KEYS) actual = get_engaged_programs(self.user, enrollments) programs = self.PROGRAMS_API_RESPONSE['results'] for program in programs: program['display_category'] = get_display_category(program) # get_engaged_programs iterates across a list returned by the programs # API to create flattened lists keyed by course ID. These lists are # joined in order of enrollment creation time when constructing the # list of engaged programs. As such, two programs sharing an enrollment # should be returned in the same order found in the API response. In this # case, the most recently created enrollment is for a run mode present in # the last two test programs. expected = [ programs[1], programs[2], programs[0], ] self.assertEqual(expected, actual)
def view_programs(request): """View programs in which the user is engaged.""" programs_config = ProgramsApiConfig.current() if not programs_config.show_program_listing: raise Http404 meter = utils.ProgramProgressMeter(request.user) programs = meter.engaged_programs # TODO: Pull 'xseries' string from configuration model. marketing_root = urljoin(settings.MKTG_URLS.get('ROOT'), 'xseries').rstrip('/') for program in programs: program['detail_url'] = utils.get_program_detail_url( program, marketing_root) program['display_category'] = utils.get_display_category(program) context = { 'programs': programs, 'progress': meter.progress, 'xseries_url': marketing_root if programs_config.show_xseries_ad else None, 'nav_hidden': True, 'show_program_listing': programs_config.show_program_listing, 'credentials': get_programs_credentials(request.user, category='xseries'), 'disable_courseware_js': True, 'uses_pattern_library': True } return render_to_response('learner_dashboard/programs.html', context)
def test_get_display_category_success(self): self.create_programs_config() self.mock_programs_api() actual_programs = utils.get_programs(self.user) for program in actual_programs: expected = 'XSeries' self.assertEqual(expected, utils.get_display_category(program))
def view_programs(request): """View programs in which the user is engaged.""" programs_config = ProgramsApiConfig.current() if not programs_config.show_program_listing: raise Http404 meter = utils.ProgramProgressMeter(request.user) programs = meter.engaged_programs # TODO: Pull 'xseries' string from configuration model. marketing_root = urljoin(settings.MKTG_URLS.get("ROOT"), "xseries").rstrip("/") for program in programs: program["detail_url"] = utils.get_program_detail_url(program, marketing_root) program["display_category"] = utils.get_display_category(program) context = { "programs": programs, "progress": meter.progress, "xseries_url": marketing_root if programs_config.show_xseries_ad else None, "nav_hidden": True, "show_program_listing": programs_config.show_program_listing, "credentials": get_programs_credentials(request.user, category="xseries"), "disable_courseware_js": True, "uses_pattern_library": True, } return render_to_response("learner_dashboard/programs.html", context)
def view_programs(request): """View programs in which the user is engaged.""" show_program_listing = ProgramsApiConfig.current().show_program_listing if not show_program_listing: raise Http404 enrollments = list(get_course_enrollments(request.user, None, [])) meter = ProgramProgressMeter(request.user, enrollments) programs = meter.engaged_programs # TODO: Pull 'xseries' string from configuration model. marketing_root = urljoin(settings.MKTG_URLS.get('ROOT'), 'xseries').strip('/') for program in programs: program['display_category'] = get_display_category(program) program['marketing_url'] = '{root}/{slug}'.format( root=marketing_root, slug=program['marketing_slug'] ) context = { 'programs': programs, 'progress': meter.progress, 'xseries_url': marketing_root if ProgramsApiConfig.current().show_xseries_ad else None, 'nav_hidden': True, 'show_program_listing': show_program_listing, 'credentials': get_programs_credentials(request.user, category='xseries'), 'disable_courseware_js': True, 'uses_pattern_library': True } return render_to_response('learner_dashboard/programs.html', context)
def view_programs(request): """View programs in which the user is engaged.""" show_program_listing = ProgramsApiConfig.current().show_program_listing if not show_program_listing: raise Http404 enrollments = list(get_course_enrollments(request.user, None, [])) meter = ProgramProgressMeter(request.user, enrollments) programs = meter.engaged_programs # TODO: Pull 'xseries' string from configuration model. marketing_root = urljoin(settings.MKTG_URLS.get('ROOT'), 'xseries').strip('/') for program in programs: program['display_category'] = get_display_category(program) program['marketing_url'] = '{root}/{slug}'.format( root=marketing_root, slug=program['marketing_slug'] ) return render_to_response('learner_dashboard/programs.html', { 'programs': programs, 'progress': meter.progress, 'xseries_url': marketing_root if ProgramsApiConfig.current().show_xseries_ad else None, 'nav_hidden': True, 'show_program_listing': show_program_listing, 'credentials': _get_xseries_credentials(request.user) })
def test_get_programs_for_dashboard(self): """Verify programs data can be retrieved and parsed correctly.""" self.create_programs_config() self.mock_programs_api() actual = get_programs_for_dashboard(self.user, self.COURSE_KEYS) expected = {} for program in self.PROGRAMS_API_RESPONSE['results']: program['display_category'] = get_display_category(program) for course_code in program['course_codes']: for run in course_code['run_modes']: course_key = run['course_key'] expected.setdefault(course_key, []).append(program) self.assertEqual(actual, expected)
def test_get_engaged_programs_shared_enrollment(self): """ Verify that correct programs are returned when the user has a single enrollment appearing in multiple programs. """ self.create_programs_config() self.mock_programs_api() enrollments = self._create_enrollments(self.COURSE_KEYS[-1]) actual = get_engaged_programs(self.user, enrollments) programs = self.PROGRAMS_API_RESPONSE['results'] for program in programs: program['display_category'] = get_display_category(program) expected = programs[-2:] self.assertEqual(expected, actual)
def test_programs_listed(self): """ Verify that the response contains accurate programs data when programs are engaged. """ self.create_programs_config() self.mock_programs_api(self.data) CourseEnrollmentFactory(user=self.user, course_id=self.course.id) # pylint: disable=no-member response = self.client.get(self.url) actual = self.load_serialized_data(response, 'programsData') actual = sorted(actual, key=self.program_sort_key) for index, actual_program in enumerate(actual): expected_program = self.data[index] self.assert_dict_contains_subset(actual_program, expected_program) self.assertEqual(actual_program['display_category'], get_display_category(expected_program))
def test_programs_listed(self): """ Verify that the response contains accurate programs data when programs are engaged. """ self.create_programs_config() self.mock_programs_api(self.data) CourseEnrollmentFactory(user=self.user, course_id=self.course.id) # pylint: disable=no-member response = self.client.get(self.url) actual = self.load_serialized_data(response, 'programsData') actual = sorted(actual, key=self.program_sort_key) for index, actual_program in enumerate(actual): expected_program = self.data[index] self.assert_dict_contains_subset(actual_program, expected_program) self.assertEqual( actual_program['display_category'], get_display_category(expected_program) )
def test_get_display_category_none(self): self.assertEqual('', utils.get_display_category(None)) self.assertEqual('', utils.get_display_category({"id": "test"}))
def test_get_display_category_none(self): self.assertEqual('', utils.get_display_category(None)) self.assertEqual('', utils.get_display_category({"id": "test"}))