def check_parse(self, latex_in, mathjax_out): xml_str = """<math>{tex}</math>""".format(tex=latex_in) element = etree.fromstring(xml_str) renderer = lookup_tag('math')(test_capa_system(), element) self.assertEqual(renderer.mathstr, mathjax_out)
def check_parse(self, latex_in, mathjax_out): # lint-amnesty, pylint: disable=missing-function-docstring xml_str = """<math>{tex}</math>""".format(tex=latex_in) element = etree.fromstring(xml_str) renderer = lookup_tag('math')(test_capa_system(), element) assert renderer.mathstr == mathjax_out
def test_rendering(self): solution = 'To compute unicorns, count them.' xml_str = """<solution id="solution_12">{s}</solution>""".format(s=solution) element = etree.fromstring(xml_str) renderer = lookup_tag('solution')(test_capa_system(), element) self.assertEqual(renderer.id, 'solution_12') # Our test_capa_system "renders" templates to a div with the repr of the context. xml = renderer.get_html() context = extract_context(xml) self.assertEqual(context, {'id': 'solution_12'})
def test_rendering(self): solution = 'To compute unicorns, count them.' xml_str = """<solution id="solution_12">{s}</solution>""".format(s=solution) element = etree.fromstring(xml_str) renderer = lookup_tag('solution')(test_capa_system(), element) assert renderer.id == 'solution_12' # Our test_capa_system "renders" templates to a div with the repr of the context. xml = renderer.get_html() context = extract_context(xml) assert context == {'id': 'solution_12'}
def setUp(self): super(CapaHtmlRenderTest, self).setUp() self.capa_system = test_capa_system()
def test_render_response_xml(self): # Generate some XML for a string response kwargs = { 'question_text': "Test question", 'explanation_text': "Test explanation", 'answer': 'Test answer', 'hints': [('test prompt', 'test_hint', 'test hint text')] } xml_str = StringResponseXMLFactory().build_xml(**kwargs) # Mock out the template renderer the_system = test_capa_system() the_system.render_template = mock.Mock() the_system.render_template.return_value = "<div class='input-template-render'>Input Template Render</div>" # Create the problem and render the HTML problem = new_loncapa_problem(xml_str, capa_system=the_system) rendered_html = etree.XML(problem.get_html()) # Expect problem has been turned into a <div> self.assertEqual(rendered_html.tag, "div") # Expect that the response has been turned into a <div> with correct attributes response_element = rendered_html.find('div') self.assertEqual(response_element.tag, "div") self.assertEqual(response_element.attrib["aria-label"], "Question 1") # Expect that the response div.wrapper-problem-response # that contains a <div> for the textline textline_element = response_element.find('div') self.assertEqual(textline_element.text, 'Input Template Render') # Expect a child <div> for the solution # with the rendered template solution_element = rendered_html.xpath('//div[@class="input-template-render"]')[0] self.assertEqual(solution_element.text, 'Input Template Render') # Expect that the template renderer was called with the correct # arguments, once for the textline input and once for # the solution expected_textline_context = { 'STATIC_URL': '/dummy-static/', 'status': the_system.STATUS_CLASS('unsubmitted'), 'value': '', 'preprocessor': None, 'msg': '', 'inline': False, 'hidden': False, 'do_math': False, 'id': '1_2_1', 'trailing_text': '', 'size': None, 'response_data': {'label': 'Test question', 'descriptions': {}}, 'describedby_html': HTML('aria-describedby="status_1_2_1"') } expected_solution_context = {'id': '1_solution_1'} expected_calls = [ mock.call('textline.html', expected_textline_context), mock.call('solutionspan.html', expected_solution_context), mock.call('textline.html', expected_textline_context), mock.call('solutionspan.html', expected_solution_context) ] self.assertEqual( the_system.render_template.call_args_list, expected_calls )
def setUp(self): super(CapaShuffleTest, self).setUp() self.system = test_capa_system()
def setUp(self): super(CapaTargetedFeedbackTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.system = test_capa_system()
def setUp(self): super(CapaHtmlRenderTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.capa_system = test_capa_system()
def check(self, d): xml = etree.XML(test_capa_system().render_template('blah', d)) assert d == extract_context(xml)
def check(self, d): xml = etree.XML(test_capa_system().render_template('blah', d)) self.assertEqual(d, extract_context(xml))
def setUp(self): super(UtilTest, self).setUp() self.system = test_capa_system()
def setUp(self): super(CapaTargetedFeedbackTest, self).setUp() self.system = test_capa_system()
def setUp(self): super(UtilTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.system = test_capa_system()
def setUp(self): super(CapaAnswerPoolTest, self).setUp() self.system = test_capa_system()
def test_render_response_xml(self): # Generate some XML for a string response kwargs = { 'question_text': "Test question", 'explanation_text': "Test explanation", 'answer': 'Test answer', 'hints': [('test prompt', 'test_hint', 'test hint text')] } xml_str = StringResponseXMLFactory().build_xml(**kwargs) # Mock out the template renderer the_system = test_capa_system() the_system.render_template = mock.Mock() the_system.render_template.return_value = "<div class='input-template-render'>Input Template Render</div>" # Create the problem and render the HTML problem = new_loncapa_problem(xml_str, capa_system=the_system) rendered_html = etree.XML(problem.get_html()) # Expect problem has been turned into a <div> assert rendered_html.tag == 'div' # Expect that the response has been turned into a <div> with correct attributes response_element = rendered_html.find('div') assert response_element.tag == 'div' assert response_element.attrib['aria-label'] == 'Question 1' # Expect that the response div.wrapper-problem-response # that contains a <div> for the textline textline_element = response_element.find('div') assert textline_element.text == 'Input Template Render' # Expect a child <div> for the solution # with the rendered template solution_element = rendered_html.xpath( '//div[@class="input-template-render"]')[0] assert solution_element.text == 'Input Template Render' # Expect that the template renderer was called with the correct # arguments, once for the textline input and once for # the solution expected_textline_context = { 'STATIC_URL': '/dummy-static/', 'status': the_system.STATUS_CLASS('unsubmitted'), 'value': '', 'preprocessor': None, 'msg': '', 'inline': False, 'hidden': False, 'do_math': False, 'id': '1_2_1', 'trailing_text': '', 'size': None, 'response_data': { 'label': 'Test question', 'descriptions': {} }, 'describedby_html': HTML('aria-describedby="status_1_2_1"') } expected_solution_context = {'id': '1_solution_1'} expected_calls = [ mock.call('textline.html', expected_textline_context), mock.call('solutionspan.html', expected_solution_context), mock.call('textline.html', expected_textline_context), mock.call('solutionspan.html', expected_solution_context) ] assert the_system.render_template.call_args_list == expected_calls
def test_render_response_xml(self): # Generate some XML for a string response kwargs = { 'question_text': "Test question", 'explanation_text': "Test explanation", 'answer': 'Test answer', 'hints': [('test prompt', 'test_hint', 'test hint text')] } xml_str = StringResponseXMLFactory().build_xml(**kwargs) # Mock out the template renderer the_system = test_capa_system() the_system.render_template = mock.Mock() the_system.render_template.return_value = "<div>Input Template Render</div>" # Create the problem and render the HTML problem = new_loncapa_problem(xml_str, capa_system=the_system) rendered_html = etree.XML(problem.get_html()) # Expect problem has been turned into a <div> self.assertEqual(rendered_html.tag, "div") # Expect question text is in a <p> child question_element = rendered_html.find("p") self.assertEqual(question_element.text, "Test question") # Expect that the response has been turned into a <section> with correct attributes response_element = rendered_html.find("section") self.assertEqual(response_element.tag, "section") self.assertEqual(response_element.attrib["aria-label"], "Question 1") # Expect that the response <section> # that contains a <div> for the textline textline_element = response_element.find("div") self.assertEqual(textline_element.text, 'Input Template Render') # Expect a child <div> for the solution # with the rendered template solution_element = rendered_html.find("div") self.assertEqual(solution_element.text, 'Input Template Render') # Expect that the template renderer was called with the correct # arguments, once for the textline input and once for # the solution expected_textline_context = { 'STATIC_URL': '/dummy-static/', 'status': the_system.STATUS_CLASS('unsubmitted'), 'value': '', 'preprocessor': None, 'msg': '', 'inline': False, 'hidden': False, 'do_math': False, 'id': '1_2_1', 'trailing_text': '', 'size': None, 'response_data': { 'label': '', 'descriptions': {} }, 'describedby_html': '' } expected_solution_context = {'id': '1_solution_1'} expected_calls = [ mock.call('textline.html', expected_textline_context), mock.call('solutionspan.html', expected_solution_context), mock.call('textline.html', expected_textline_context), mock.call('solutionspan.html', expected_solution_context) ] self.assertEqual(the_system.render_template.call_args_list, expected_calls)