diff --git a/lms/djangoapps/certificates/tests/test_webview_views.py b/lms/djangoapps/certificates/tests/test_webview_views.py
index dd4cae91d4..81a256c801 100644
--- a/lms/djangoapps/certificates/tests/test_webview_views.py
+++ b/lms/djangoapps/certificates/tests/test_webview_views.py
@@ -11,6 +11,7 @@ from django.conf import settings
from django.core.urlresolvers import reverse
from django.test.client import Client, RequestFactory
from django.test.utils import override_settings
+from django.utils import translation
from mock import patch
import ddt
@@ -41,6 +42,7 @@ from nose.plugins.attrib import attr
from openedx.core.djangoapps.certificates.config import waffle
from openedx.core.djangoapps.dark_lang.models import DarkLangConfig
from openedx.core.lib.tests.assertions.events import assert_event_matches
+from openedx.core.djangolib.js_utils import js_escaped_string
from student.roles import CourseStaffRole
from student.tests.factories import CourseEnrollmentFactory, UserFactory
from track.tests import EventTrackingTestCase
@@ -273,8 +275,8 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
('pfCertificationUrl', self.request.build_absolute_uri(test_url),),
])
self.assertIn(
- self.linkedin_url.format(params=urlencode(params)),
- response.content
+ js_escaped_string(self.linkedin_url.format(params=urlencode(params))),
+ response.content.decode('utf-8')
)
@override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED)
@@ -296,7 +298,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
('pfCertificationUrl', 'http://' + settings.MICROSITE_TEST_HOSTNAME + test_url,),
])
self.assertIn(
- self.linkedin_url.format(params=urlencode(params)),
+ js_escaped_string(self.linkedin_url.format(params=urlencode(params))),
response.content
)
@@ -655,6 +657,29 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
self.assertIn("Cannot Find Certificate", response.content)
self.assertIn("We cannot find a certificate with this URL or ID number.", response.content)
+ @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED)
+ def test_html_lang_attribute_is_dynamic_for_invalid_certificate_html_view(self):
+ """
+ Tests that Certificate HTML Web View's lang attribute is based on user language.
+ """
+ self._add_course_certificates(count=1, signatory_count=2)
+ test_url = get_certificate_url(
+ user_id=self.user.id,
+ course_id=unicode(self.course.id)
+ )
+
+ self.cert.invalidate()
+
+ user_language = 'fr'
+ self.client.cookies[settings.LANGUAGE_COOKIE] = user_language
+ response = self.client.get(test_url)
+ self.assertIn('', response.content)
+
+ user_language = 'ar'
+ self.client.cookies[settings.LANGUAGE_COOKIE] = user_language
+ response = self.client.get(test_url)
+ self.assertIn('', response.content)
+
@override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED)
def test_html_view_for_non_viewable_certificate_and_for_student_user(self):
"""
@@ -782,6 +807,34 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
self.assertNotIn('Signatory_Name 0', response.content)
self.assertNotIn('Signatory_Title 0', response.content)
+ @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED)
+ def test_render_html_view_is_html_escaped(self):
+ test_certificates = [
+ {
+ 'id': 0,
+ 'name': 'Certificate Name',
+ 'description': '',
+ 'course_title': '',
+ 'org_logo_path': '/t4x/orgX/testX/asset/org-logo-1.png',
+ 'signatories': [],
+ 'version': 1,
+ 'is_active': True
+ }
+ ]
+
+ self.course.certificates = {'certificates': test_certificates}
+ self.course.cert_html_view_enabled = True
+ self.course.save()
+ self.store.update_item(self.course, self.user.id)
+
+ test_url = get_certificate_url(
+ user_id=self.user.id,
+ course_id=unicode(self.course.id)
+ )
+ response = self.client.get(test_url)
+ self.assertNotIn('