Commit 22e9f125 by muhammad-ammar

fix tests

parent 3b60ff69
...@@ -49,8 +49,11 @@ class CapaHtmlRenderTest(unittest.TestCase): ...@@ -49,8 +49,11 @@ class CapaHtmlRenderTest(unittest.TestCase):
# Render the HTML # Render the HTML
rendered_html = etree.XML(problem.get_html()) rendered_html = etree.XML(problem.get_html())
# get question
question = rendered_html.find(".//div[@class='question']")
# Expect that the include file was embedded in the problem # Expect that the include file was embedded in the problem
test_element = rendered_html.find("test") test_element = question.find("test")
self.assertEqual(test_element.tag, "test") self.assertEqual(test_element.tag, "test")
self.assertEqual(test_element.text, "Test include") self.assertEqual(test_element.text, "Test include")
...@@ -68,9 +71,12 @@ class CapaHtmlRenderTest(unittest.TestCase): ...@@ -68,9 +71,12 @@ class CapaHtmlRenderTest(unittest.TestCase):
# Render the HTML # Render the HTML
rendered_html = etree.XML(problem.get_html()) rendered_html = etree.XML(problem.get_html())
# get question
question = rendered_html.find(".//div[@class='question']")
# Expect that the <startouttext /> and <endouttext /> # Expect that the <startouttext /> and <endouttext />
# were converted to <span></span> tags # were converted to <span></span> tags
span_element = rendered_html.find('span') span_element = question.find('span')
self.assertEqual(span_element.text, 'Test text') self.assertEqual(span_element.text, 'Test text')
def test_anonymous_student_id(self): def test_anonymous_student_id(self):
...@@ -87,8 +93,11 @@ class CapaHtmlRenderTest(unittest.TestCase): ...@@ -87,8 +93,11 @@ class CapaHtmlRenderTest(unittest.TestCase):
# Render the HTML # Render the HTML
rendered_html = etree.XML(problem.get_html()) rendered_html = etree.XML(problem.get_html())
# get question
question = rendered_html.find(".//div[@class='question']")
# Expect that the anonymous_student_id was converted to "student" # Expect that the anonymous_student_id was converted to "student"
span_element = rendered_html.find('span') span_element = question.find('span')
self.assertEqual(span_element.text, 'Welcome student') self.assertEqual(span_element.text, 'Welcome student')
def test_render_script(self): def test_render_script(self):
...@@ -151,12 +160,15 @@ class CapaHtmlRenderTest(unittest.TestCase): ...@@ -151,12 +160,15 @@ class CapaHtmlRenderTest(unittest.TestCase):
# Expect problem has been turned into a <div> # Expect problem has been turned into a <div>
self.assertEqual(rendered_html.tag, "div") self.assertEqual(rendered_html.tag, "div")
# get question
question = rendered_html.find(".//div[@class='question']")
# Expect question text is in a <p> child # Expect question text is in a <p> child
question_element = rendered_html.find("p") question_element = question.find("p")
self.assertEqual(question_element.text, "Test question") self.assertEqual(question_element.text, "Test question")
# Expect that the response has been turned into a <span> # Expect that the response has been turned into a <span>
response_element = rendered_html.find("span") response_element = question.find("span")
self.assertEqual(response_element.tag, "span") self.assertEqual(response_element.tag, "span")
# Expect that the response <span> # Expect that the response <span>
...@@ -166,7 +178,7 @@ class CapaHtmlRenderTest(unittest.TestCase): ...@@ -166,7 +178,7 @@ class CapaHtmlRenderTest(unittest.TestCase):
# Expect a child <div> for the solution # Expect a child <div> for the solution
# with the rendered template # with the rendered template
solution_element = rendered_html.find("div") solution_element = question.find("div")
self.assertEqual(solution_element.text, 'Input Template Render') self.assertEqual(solution_element.text, 'Input Template Render')
# Expect that the template renderer was called with the correct # Expect that the template renderer was called with the correct
...@@ -251,8 +263,11 @@ class CapaHtmlRenderTest(unittest.TestCase): ...@@ -251,8 +263,11 @@ class CapaHtmlRenderTest(unittest.TestCase):
problem = new_loncapa_problem(xml_str) problem = new_loncapa_problem(xml_str)
rendered_html = etree.XML(problem.get_html()) rendered_html = etree.XML(problem.get_html())
# get question
question = rendered_html.find(".//div[@class='question']")
# Expect that the variable $test has been replaced with its value # Expect that the variable $test has been replaced with its value
span_element = rendered_html.find('span') span_element = question.find('span')
self.assertEqual(span_element.get('attr'), "TEST") self.assertEqual(span_element.get('attr'), "TEST")
def test_xml_comments_and_other_odd_things(self): def test_xml_comments_and_other_odd_things(self):
...@@ -307,5 +322,5 @@ class CapaHtmlRenderTest(unittest.TestCase): ...@@ -307,5 +322,5 @@ class CapaHtmlRenderTest(unittest.TestCase):
# Create the problem # Create the problem
problem = new_loncapa_problem(xml_str) problem = new_loncapa_problem(xml_str)
childs = [child.tag for child in problem.tree.getchildren()] # pylint: disable=no-member childs = [child.tag for child in problem.tree.getchildren()] # pylint: disable=no-member
self.assertEqual(set(childs), set(['question'])) self.assertEqual(set(childs), set(['question']))
...@@ -209,12 +209,6 @@ class CapaMixin(CapaFields): ...@@ -209,12 +209,6 @@ class CapaMixin(CapaFields):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(CapaMixin, self).__init__(*args, **kwargs) super(CapaMixin, self).__init__(*args, **kwargs)
# For Blank Advanced Problem, there is no template so `<problem></problem>` is generated,
# It should be converted to <problem><question></question></problem> to make the things consistent
# TODO! Find a better way to do this
if self.data == '<problem></problem>':
self.data = '<problem><question></question></problem>'
due_date = self.due due_date = self.due
if self.graceperiod is not None and due_date: if self.graceperiod is not None and due_date:
......
...@@ -1366,7 +1366,7 @@ class CapaModuleTest(unittest.TestCase): ...@@ -1366,7 +1366,7 @@ class CapaModuleTest(unittest.TestCase):
mock_track_function.assert_called_with( mock_track_function.assert_called_with(
module, 'edx.problem.hint.demandhint_displayed', module, 'edx.problem.hint.demandhint_displayed',
{'hint_index': 0, 'module_id': u'i4x://edX/capa_test/problem/meh', {'hint_index': 0, 'module_id': u'i4x://edX/capa_test/problem/meh',
'hint_text': 'Demand 1', 'hint_len': 2} 'hint_text': 'question 1 hint 1', 'hint_len': 2}
) )
def test_input_state_consistency(self): def test_input_state_consistency(self):
......
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