From 6647cc19581eadd85ada82af28dd92df642dcd55 Mon Sep 17 00:00:00 2001 From: ichuang Date: Wed, 26 Mar 2014 14:52:11 +0000 Subject: [PATCH] allow capa poroblems access to anonymous_student_id fix system->capa_system in capa_problem change for anonid --- common/lib/capa/capa/capa_problem.py | 1 + common/lib/capa/capa/tests/test_html_render.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) 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