diff --git a/common/lib/capa/capa/capa_problem.py b/common/lib/capa/capa/capa_problem.py index 7d511a6624..a21ce346b1 100644 --- a/common/lib/capa/capa/capa_problem.py +++ b/common/lib/capa/capa/capa_problem.py @@ -620,6 +620,7 @@ class LoncapaProblem(object): """ context = {} context['seed'] = self.seed + context['anonymous_student_id'] = self.capa_system.anonymous_student_id all_code = '' python_path = [] diff --git a/common/lib/capa/capa/tests/test_html_render.py b/common/lib/capa/capa/tests/test_html_render.py index a929c454c0..298ba14910 100644 --- a/common/lib/capa/capa/tests/test_html_render.py +++ b/common/lib/capa/capa/tests/test_html_render.py @@ -73,6 +73,24 @@ class CapaHtmlRenderTest(unittest.TestCase): span_element = rendered_html.find('span') self.assertEqual(span_element.text, 'Test text') + def test_anonymous_student_id(self): + # make sure anonymous_student_id is rendered properly as a context variable + xml_str = textwrap.dedent(""" + + Welcome $anonymous_student_id + + """) + + # Create the problem + problem = new_loncapa_problem(xml_str) + + # Render the HTML + rendered_html = etree.XML(problem.get_html()) + + # Expect that the anonymous_student_id was converted to "student" + span_element = rendered_html.find('span') + self.assertEqual(span_element.text, 'Welcome student') + def test_render_script(self): # Generate some XML with a