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 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.""" 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 program_listing(request): """View a list of 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 marketing_url = urljoin(settings.MKTG_URLS.get('ROOT'), programs_config.marketing_path).rstrip('/') for program in programs: program['detail_url'] = utils.get_program_detail_url(program, marketing_url) context = { 'credentials': get_programs_credentials(request.user), 'disable_courseware_js': True, 'marketing_url': marketing_url, 'nav_hidden': True, 'programs': programs, 'progress': meter.progress, 'show_program_listing': programs_config.show_program_listing, '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 test_get_programs_credentials(self): """ Verify that the program credentials data required for display can be retrieved. """ # create credentials and program configuration self.create_credentials_config() # Mocking the API responses from programs and credentials primary_uuid, alternate_uuid = str(uuid.uuid4()), str(uuid.uuid4()) credentials_api_response = { "next": None, "results": [ factories.UserCredential( username='******', credential=factories.ProgramCredential(program_uuid=primary_uuid) ), factories.UserCredential( username='******', credential=factories.ProgramCredential(program_uuid=alternate_uuid) ) ] } self.mock_credentials_api(self.user, data=credentials_api_response, reset_url=False) programs = [ ProgramFactory(uuid=primary_uuid), ProgramFactory(uuid=alternate_uuid) ] with mock.patch("openedx.core.djangoapps.credentials.utils.get_programs") as mock_get_programs: mock_get_programs.return_value = programs actual = get_programs_credentials(self.user) expected = self.expected_credentials_display_data(programs) # Checking result is as expected self.assertEqual(len(actual), 2) self.assertEqual(actual, expected)
def program_listing(request): """View a list of programs in which the user is engaged.""" programs_config = ProgramsApiConfig.current() if not programs_config.show_program_listing: raise Http404 meter = ProgramProgressMeter(request.user) engaged_programs = [ munge_catalog_program(program) for program in meter.engaged_programs ] progress = [ munge_progress_map(progress_map) for progress_map in meter.progress ] context = { 'credentials': get_programs_credentials(request.user), 'disable_courseware_js': True, 'marketing_url': get_program_marketing_url(programs_config), 'nav_hidden': True, 'programs': engaged_programs, 'progress': progress, 'show_program_listing': programs_config.show_program_listing, 'uses_pattern_library': True, } return render_to_response('learner_dashboard/programs.html', context)
def program_listing(request): """View a list of 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 marketing_url = urljoin(settings.MKTG_URLS.get('ROOT'), programs_config.marketing_path).rstrip('/') for program in programs: program['detail_url'] = utils.get_program_detail_url( program, marketing_url) context = { 'credentials': get_programs_credentials(request.user), 'disable_courseware_js': True, 'marketing_url': marketing_url, 'nav_hidden': True, 'programs': programs, 'progress': meter.progress, 'show_program_listing': programs_config.show_program_listing, 'uses_pattern_library': True, } return render_to_response('learner_dashboard/programs.html', context)
def test_get_programs_credentials_category(self): """ Verify behaviour when program category is provided.""" # create credentials and program configuration self.create_credentials_config() self.create_programs_config() # Mocking the API responses from programs and credentials self.mock_programs_api() self.mock_credentials_api(self.user, reset_url=False) actual = get_programs_credentials(self.user, category='dummy_category') expected = self.expected_credentials_display_data() self.assertEqual(len(actual), 0) actual = get_programs_credentials(self.user, category='xseries') self.assertEqual(len(actual), 2) self.assertEqual(actual, expected)
def test_get_programs_credentials_category(self): """ Verify behaviour when program category is provided.""" # create credentials and program configuration self.create_credentials_config() self.create_programs_config() # Mocking the API responses from programs and credentials self.mock_programs_api() self.mock_credentials_api(self.user, reset_url=False) actual = get_programs_credentials(self.user, category='dummy_category') expected = self.expected_credentials_display_data() self.assertEqual(len(actual), 0) actual = get_programs_credentials(self.user, category='xseries') self.assertEqual(len(actual), 2) self.assertEqual(actual, expected)
def test_get_programs_credentials(self): """ Verify that the program credentials data required for display can be retrieved. """ # create credentials and program configuration self.create_credentials_config() self.create_programs_config() # Mocking the API responses from programs and credentials self.mock_programs_api() self.mock_credentials_api(self.user, reset_url=False) actual = get_programs_credentials(self.user, category='xseries') expected = self.expected_credentials_display_data() # Checking result is as expected self.assertEqual(len(actual), 2) self.assertEqual(actual, expected)
def test_get_programs_credentials(self): """ Verify that the program credentials data required for display can be retrieved. """ # create credentials and program configuration self.create_credentials_config() self.create_programs_config() # Mocking the API responses from programs and credentials self.mock_programs_api() self.mock_credentials_api(self.user, reset_url=False) actual = get_programs_credentials(self.user) expected = self.expected_credentials_display_data() # Checking result is as expected self.assertEqual(len(actual), 2) self.assertEqual(actual, expected)
def program_listing(request): """View a list of 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) context = { 'credentials': get_programs_credentials(request.user), 'disable_courseware_js': True, 'marketing_url': utils.get_program_marketing_url(programs_config), 'nav_hidden': True, 'programs': meter.engaged_programs(), 'progress': meter.progress, 'show_program_listing': programs_config.show_program_listing, 'uses_pattern_library': False, } return render_to_response('learner_dashboard/programs.html', context)
def program_listing(request): """View a list of 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) context = { "credentials": get_programs_credentials(request.user), "disable_courseware_js": True, "marketing_url": utils.get_program_marketing_url(programs_config), "nav_hidden": True, "programs": meter.engaged_programs(), "progress": meter.progress, "show_program_listing": programs_config.show_program_listing, "uses_pattern_library": True, } return render_to_response("learner_dashboard/programs.html", context)
def test_get_programs_credentials(self): """ Verify that the program credentials data required for display can be retrieved. """ # create credentials and program configuration self.create_credentials_config() # Mocking the API responses from programs and credentials primary_uuid, alternate_uuid = str(uuid.uuid4()), str(uuid.uuid4()) credentials_api_response = { "next": None, "results": [ factories.UserCredential( username='******', credential=factories.ProgramCredential( program_uuid=primary_uuid)), factories.UserCredential( username='******', credential=factories.ProgramCredential( program_uuid=alternate_uuid)) ] } self.mock_credentials_api(self.user, data=credentials_api_response, reset_url=False) programs = [ ProgramFactory(uuid=primary_uuid), ProgramFactory(uuid=alternate_uuid) ] with mock.patch( "openedx.core.djangoapps.credentials.utils.get_programs" ) as mock_get_programs: mock_get_programs.return_value = programs actual = get_programs_credentials(self.user) expected = self.expected_credentials_display_data(programs) # Checking result is as expected self.assertEqual(len(actual), 2) self.assertEqual(actual, expected)
def program_listing(request): """View a list of programs in which the user is engaged.""" programs_config = ProgramsApiConfig.current() if not programs_config.show_program_listing: raise Http404 use_catalog = waffle.switch_is_active('get_programs_from_catalog') meter = utils.ProgramProgressMeter(request.user, use_catalog=use_catalog) context = { 'credentials': get_programs_credentials(request.user), 'disable_courseware_js': True, 'marketing_url': utils.get_program_marketing_url(programs_config), 'nav_hidden': True, 'programs': meter.engaged_programs(), 'progress': meter.progress, 'show_program_listing': programs_config.show_program_listing, 'uses_pattern_library': True, } return render_to_response('learner_dashboard/programs.html', context)