Use English for the marketing site buttons in an edx-controlled domain
This commit is contained in:
@@ -258,29 +258,44 @@ class ViewsTestCase(TestCase):
|
||||
self.assertIn('Coming Soon', response.content)
|
||||
|
||||
def test_course_mktg_register(self):
|
||||
admin = AdminFactory()
|
||||
self.client.login(username=admin.username, password='test')
|
||||
url = reverse('mktg_about_course', kwargs={'course_id': self.course_key.to_deprecated_string()})
|
||||
response = self.client.get(url)
|
||||
response = self._load_mktg_about()
|
||||
self.assertIn('Register for', response.content)
|
||||
self.assertNotIn('and choose your student track', response.content)
|
||||
|
||||
def test_course_mktg_register_multiple_modes(self):
|
||||
admin = AdminFactory()
|
||||
CourseMode.objects.get_or_create(mode_slug='honor',
|
||||
mode_display_name='Honor Code Certificate',
|
||||
course_id=self.course_key)
|
||||
CourseMode.objects.get_or_create(mode_slug='verified',
|
||||
mode_display_name='Verified Certificate',
|
||||
course_id=self.course_key)
|
||||
self.client.login(username=admin.username, password='test')
|
||||
url = reverse('mktg_about_course', kwargs={'course_id': self.course_key.to_deprecated_string()})
|
||||
response = self.client.get(url)
|
||||
CourseMode.objects.get_or_create(
|
||||
mode_slug='honor',
|
||||
mode_display_name='Honor Code Certificate',
|
||||
course_id=self.course_key
|
||||
)
|
||||
CourseMode.objects.get_or_create(
|
||||
mode_slug='verified',
|
||||
mode_display_name='Verified Certificate',
|
||||
course_id=self.course_key
|
||||
)
|
||||
|
||||
response = self._load_mktg_about()
|
||||
self.assertIn('Register for', response.content)
|
||||
self.assertIn('and choose your student track', response.content)
|
||||
# clean up course modes
|
||||
CourseMode.objects.all().delete()
|
||||
|
||||
@patch.dict(settings.FEATURES, {'IS_EDX_DOMAIN': True})
|
||||
def test_mktg_about_language_edx_domain(self):
|
||||
# Since we're in an edx-controlled domain, and our marketing site
|
||||
# supports only English, override the language setting
|
||||
# and use English.
|
||||
response = self._load_mktg_about(language='eo')
|
||||
self.assertContains(response, "Register for")
|
||||
|
||||
@patch.dict(settings.FEATURES, {'IS_EDX_DOMAIN': False})
|
||||
def test_mktg_about_language_openedx(self):
|
||||
# If we're in an OpenEdX installation,
|
||||
# may want to support languages other than English,
|
||||
# so respect the language code.
|
||||
response = self._load_mktg_about(language='eo')
|
||||
self.assertContains(response, u"Régïstér för".encode('utf-8'))
|
||||
|
||||
def test_submission_history_accepts_valid_ids(self):
|
||||
# log into a staff account
|
||||
admin = AdminFactory()
|
||||
@@ -320,6 +335,30 @@ class ViewsTestCase(TestCase):
|
||||
response = self.client.get(url)
|
||||
self.assertFalse('<script>' in response.content)
|
||||
|
||||
def _load_mktg_about(self, language=None):
|
||||
"""
|
||||
Retrieve the marketing about button (iframed into the marketing site)
|
||||
and return the HTTP response.
|
||||
|
||||
Keyword Args:
|
||||
language (string): If provided, send this in the 'Accept-Language' HTTP header.
|
||||
|
||||
Returns:
|
||||
Response
|
||||
|
||||
"""
|
||||
# Log in as an administrator to guarantee that we can access the button
|
||||
admin = AdminFactory()
|
||||
self.client.login(username=admin.username, password='test')
|
||||
|
||||
# If provided, set the language header
|
||||
headers = {}
|
||||
if language is not None:
|
||||
headers['HTTP_ACCEPT_LANGUAGE'] = language
|
||||
|
||||
url = reverse('mktg_about_course', kwargs={'course_id': unicode(self.course_key)})
|
||||
return self.client.get(url, **headers)
|
||||
|
||||
|
||||
# setting TIME_ZONE_DISPLAYED_FOR_DEADLINES explicitly
|
||||
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE, TIME_ZONE_DISPLAYED_FOR_DEADLINES="UTC")
|
||||
|
||||
@@ -7,6 +7,7 @@ import urllib
|
||||
import json
|
||||
|
||||
from collections import defaultdict
|
||||
from django.utils import translation
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from django.conf import settings
|
||||
@@ -710,15 +711,30 @@ def mktg_course_about(request, course_id):
|
||||
settings.FEATURES.get('ENABLE_LMS_MIGRATION'))
|
||||
course_modes = CourseMode.modes_for_course_dict(course.id)
|
||||
|
||||
return render_to_response('courseware/mktg_course_about.html', {
|
||||
context = {
|
||||
'course': course,
|
||||
'registered': registered,
|
||||
'allow_registration': allow_registration,
|
||||
'course_target': course_target,
|
||||
'show_courseware_link': show_courseware_link,
|
||||
'course_modes': course_modes,
|
||||
})
|
||||
}
|
||||
|
||||
# The edx.org marketing site currently displays only in English.
|
||||
# To avoid displaying a different language in the register / access button,
|
||||
# we force the language to English.
|
||||
# However, OpenEdX installations with a different marketing front-end
|
||||
# may want to respect the language specified by the user or the site settings.
|
||||
force_english = settings.FEATURES.get('IS_EDX_DOMAIN', False)
|
||||
if force_english:
|
||||
translation.activate('en-us')
|
||||
|
||||
try:
|
||||
return render_to_response('courseware/mktg_course_about.html', context)
|
||||
finally:
|
||||
# Just to be safe, reset the language if we forced it to be English.
|
||||
if force_english:
|
||||
translation.deactivate()
|
||||
|
||||
@login_required
|
||||
@cache_control(no_cache=True, no_store=True, must_revalidate=True)
|
||||
|
||||
Reference in New Issue
Block a user