diff --git a/lms/djangoapps/courseware/tests/test_course_info.py b/lms/djangoapps/courseware/tests/test_course_info.py index 0a2f471015b4efc1fdcf01234c5663512805dbc8..168276894bbdbfd85102ed06d7bd5c2c9a1faa98 100644 --- a/lms/djangoapps/courseware/tests/test_course_info.py +++ b/lms/djangoapps/courseware/tests/test_course_info.py @@ -2,6 +2,7 @@ """ Test the course_info xblock """ +import ddt import mock from django.conf import settings from django.core.urlresolvers import reverse @@ -12,6 +13,7 @@ from ccx_keys.locator import CCXLocator from lms.djangoapps.ccx.tests.factories import CcxFactory from nose.plugins.attrib import attr from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration +from openedx.core.djangoapps.site_configuration.tests.test_util import with_site_configuration_context from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES, override_waffle_flag from openedx.features.course_experience import UNIFIED_COURSE_TAB_FLAG from openedx.features.enterprise_support.tests.mixins.enterprise import EnterpriseTestConsentRequired @@ -216,58 +218,96 @@ class CourseInfoLastAccessedTestCase(LoginEnrollmentTestCase, ModuleStoreTestCas @attr(shard=1) @override_waffle_flag(UNIFIED_COURSE_TAB_FLAG, active=False) +@ddt.ddt class CourseInfoTitleTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase): """ - Tests of the CourseInfo page title. + Tests of the CourseInfo page title site configuration options. """ - def setUp(self): super(CourseInfoTitleTestCase, self).setUp() - self.course = CourseFactory.create() - self.page = ItemFactory.create( - category="course_info", parent_location=self.course.location, - data="OOGIE BLOOGIE", display_name="updates" + self.course = CourseFactory.create( + org="HogwartZ", + number="Potions_3", + display_organization="HogwartsX", + display_coursenumber="Potions101", + display_name="Introduction to Potions" ) - def test_info_title(self): + @ddt.data( + # Default site configuration shows course number, org, and display name as subtitle. + (dict(), + "Welcome to HogwartsX's Potions101!", "Introduction to Potions"), + + # Show org in title + (dict(COURSE_HOMEPAGE_INVERT_TITLE=False, + COURSE_HOMEPAGE_SHOW_SUBTITLE=True, + COURSE_HOMEPAGE_SHOW_ORG=True), + "Welcome to HogwartsX's Potions101!", "Introduction to Potions"), + + # Don't show org in title + (dict(COURSE_HOMEPAGE_INVERT_TITLE=False, + COURSE_HOMEPAGE_SHOW_SUBTITLE=True, + COURSE_HOMEPAGE_SHOW_ORG=False), + "Welcome to Potions101!", "Introduction to Potions"), + + # Hide subtitle and org + (dict(COURSE_HOMEPAGE_INVERT_TITLE=False, + COURSE_HOMEPAGE_SHOW_SUBTITLE=False, + COURSE_HOMEPAGE_SHOW_ORG=False), + "Welcome to Potions101!", None), + + # Show display name as title, hide subtitle and org. + (dict(COURSE_HOMEPAGE_INVERT_TITLE=True, + COURSE_HOMEPAGE_SHOW_SUBTITLE=False, + COURSE_HOMEPAGE_SHOW_ORG=False), + "Welcome to Introduction to Potions!", None), + + # Show display name as title with org, hide subtitle. + (dict(COURSE_HOMEPAGE_INVERT_TITLE=True, + COURSE_HOMEPAGE_SHOW_SUBTITLE=False, + COURSE_HOMEPAGE_SHOW_ORG=True), + "Welcome to HogwartsX's Introduction to Potions!", None), + + # Show display name as title, hide org, and show course number as subtitle. + (dict(COURSE_HOMEPAGE_INVERT_TITLE=True, + COURSE_HOMEPAGE_SHOW_SUBTITLE=True, + COURSE_HOMEPAGE_SHOW_ORG=False), + "Welcome to Introduction to Potions!", 'Potions101'), + + # Show display name as title with org, and show course number as subtitle. + (dict(COURSE_HOMEPAGE_INVERT_TITLE=True, + COURSE_HOMEPAGE_SHOW_SUBTITLE=True, + COURSE_HOMEPAGE_SHOW_ORG=True), + "Welcome to HogwartsX's Introduction to Potions!", 'Potions101'), + ) + @ddt.unpack + def test_info_title(self, site_config, expected_title, expected_subtitle): """ - Test the info page on a course without any display_* settings against - one that does. + Test the info page on a course with all the multiple display options + depeding on the current site configuration """ url = reverse('info', args=(unicode(self.course.id),)) - response = self.client.get(url) + with with_site_configuration_context(configuration=site_config): + response = self.client.get(url) + content = pq(response.content) - expected_title = "Welcome to {org}'s {course_name}!".format( - org=self.course.display_org_with_default, - course_name=self.course.display_number_with_default - ) - display_course = CourseFactory.create( - org="HogwartZ", - number="Potions_3", - display_organization="HogwartsX", - display_coursenumber="Potions", - display_name="Introduction_to_Potions" - ) - display_url = reverse('info', args=(unicode(display_course.id),)) - display_response = self.client.get(display_url) - display_content = pq(display_response.content) - expected_display_title = "Welcome to {org}'s {course_name}!".format( - org=display_course.display_org_with_default, - course_name=display_course.display_number_with_default - ) - self.assertIn( + + self.assertEqual( expected_title, - content('.page-title').contents()[0] - ) - self.assertIn( - expected_display_title, - display_content('.page-title').contents()[0] - ) - self.assertIn( - display_course.display_name_with_default, - display_content('.page-subtitle').contents() + content('.page-title').contents()[0].strip(), ) + if expected_subtitle is None: + self.assertEqual( + [], + content('.page-subtitle'), + ) + else: + self.assertEqual( + expected_subtitle, + content('.page-subtitle').contents()[0].strip(), + ) + @override_waffle_flag(UNIFIED_COURSE_TAB_FLAG, active=False) class CourseInfoTestCaseCCX(SharedModuleStoreTestCase, LoginEnrollmentTestCase): diff --git a/lms/djangoapps/courseware/views/views.py b/lms/djangoapps/courseware/views/views.py index 6e1c14e000645380973df0302130e1fde8b15c50..eb8596d2fa048149919984c930b479752d2b358c 100644 --- a/lms/djangoapps/courseware/views/views.py +++ b/lms/djangoapps/courseware/views/views.py @@ -373,6 +373,27 @@ def course_info(request, course_id): # Get the course tools enabled for this user and course course_tools = CourseToolsPluginManager.get_enabled_course_tools(request, course_key) + course_homepage_invert_title =\ + configuration_helpers.get_value( + 'COURSE_HOMEPAGE_INVERT_TITLE', + False + ) + + course_homepage_show_subtitle =\ + configuration_helpers.get_value( + 'COURSE_HOMEPAGE_SHOW_SUBTITLE', + True + ) + + course_homepage_show_org =\ + configuration_helpers.get_value('COURSE_HOMEPAGE_SHOW_ORG', True) + + course_title = course.display_number_with_default + course_subtitle = course.display_name_with_default + if course_homepage_invert_title: + course_title = course.display_name_with_default + course_subtitle = course.display_number_with_default + context = { 'request': request, 'masquerade_user': user, @@ -380,6 +401,10 @@ def course_info(request, course_id): 'url_to_enroll': CourseTabView.url_to_enroll(course_key), 'cache': None, 'course': course, + 'course_title': course_title, + 'course_subtitle': course_subtitle, + 'show_subtitle': course_homepage_show_subtitle, + 'show_org': course_homepage_show_org, 'staff_access': staff_access, 'masquerade': masquerade, 'supports_preview_menu': True, diff --git a/lms/templates/courseware/info.html b/lms/templates/courseware/info.html index a48cb228018f1a45dc9aef18bb9414df64b4da8d..af15a4f398f0ba323ce06b4596f8a5ebc3175881 100644 --- a/lms/templates/courseware/info.html +++ b/lms/templates/courseware/info.html @@ -58,8 +58,15 @@ from openedx.core.djangolib.markup import HTML, Text > <div class="home"> <div class="page-header-main"> - <h2 class="hd hd-2 page-title">${_("Welcome to {org}'s {course_name}!").format(org=course.display_org_with_default, course_name=course.display_number_with_default)} - <div class="page-subtitle">${course.display_name_with_default}</div> + <h2 class="hd hd-2 page-title"> + % if show_org: + ${_("Welcome to {org}'s {course_title}!").format(org=course.display_org_with_default, course_title=course_title)} + % else: + ${_("Welcome to {course_title}!").format(course_title=course_title)} + % endif + % if show_subtitle: + <div class="page-subtitle">${course_subtitle}</div> + % endif </h2> </div> % if resume_course_url and user_is_enrolled: