Commit 34c28cf4 by ichuang

Merge pull request #3068 from edx/fix/ichuang/capa-customresponse-anonid

allow capa problems access to anonymous_student_id
parents c0a5171c 6647cc19
...@@ -620,6 +620,7 @@ class LoncapaProblem(object): ...@@ -620,6 +620,7 @@ class LoncapaProblem(object):
""" """
context = {} context = {}
context['seed'] = self.seed context['seed'] = self.seed
context['anonymous_student_id'] = self.capa_system.anonymous_student_id
all_code = '' all_code = ''
python_path = [] python_path = []
......
...@@ -73,6 +73,24 @@ class CapaHtmlRenderTest(unittest.TestCase): ...@@ -73,6 +73,24 @@ class CapaHtmlRenderTest(unittest.TestCase):
span_element = rendered_html.find('span') span_element = rendered_html.find('span')
self.assertEqual(span_element.text, 'Test text') 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("""
<problem>
<span>Welcome $anonymous_student_id</span>
</problem>
""")
# 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): def test_render_script(self):
# Generate some XML with a <script> tag # Generate some XML with a <script> tag
xml_str = textwrap.dedent(""" xml_str = textwrap.dedent("""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment