From c270b4fcce383b9cd1eef81f13c2b6c4782b8186 Mon Sep 17 00:00:00 2001 From: Kaustav Banerjee Date: Tue, 6 Feb 2024 04:29:28 +0530 Subject: [PATCH] fix: add missing function import in certificate template (#33904) (#34171) * fix: add missing function import in certificate template * test: add test case to check certificates generated when GA4 is enabled (cherry picked from commit d0a49d1a01bda06722139513919b1aafcf739fa9) --- lms/djangoapps/certificates/tests/test_views.py | 16 ++++++++++++++++ .../certificates/accomplishment-base.html | 6 ++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lms/djangoapps/certificates/tests/test_views.py b/lms/djangoapps/certificates/tests/test_views.py index 32db30d12f61..520baa2a8fb2 100644 --- a/lms/djangoapps/certificates/tests/test_views.py +++ b/lms/djangoapps/certificates/tests/test_views.py @@ -165,3 +165,19 @@ def test_html_view_site_configuration_missing(self): response, 'This should not survive being overwritten by static content', ) + + @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED, GOOGLE_ANALYTICS_4_ID='GA-abc') + @with_site_configuration(configuration={'platform_name': 'My Platform Site'}) + def test_html_view_with_g4(self): + test_url = get_certificate_url( + user_id=self.user.id, + course_id=str(self.course.id), + uuid=self.cert.verify_uuid + ) + self._add_course_certificates(count=1, signatory_count=2) + response = self.client.get(test_url) + self.assertContains( + response, + 'awarded this My Platform Site Honor Code Certificate of Completion', + ) + self.assertContains(response, 'googletagmanager') diff --git a/lms/templates/certificates/accomplishment-base.html b/lms/templates/certificates/accomplishment-base.html index 92c58dc138ff..e742078384b1 100644 --- a/lms/templates/certificates/accomplishment-base.html +++ b/lms/templates/certificates/accomplishment-base.html @@ -1,7 +1,9 @@ <%page expression_filter="h"/> <%namespace name='static' file='/static_content.html'/> -<%! from django.utils.translation import gettext as _%> - +<%! +from django.utils.translation import gettext as _ +from openedx.core.djangolib.js_utils import js_escaped_string +%> <% # set doc language direction from django.utils.translation import get_language_bidi