Commit 07328f1b by Tim Krones

Add integration test.

parent 21ee62c0
......@@ -19,12 +19,16 @@ class BaseIntegrationTest(SeleniumBaseTest):
"'": "'"
}
def _make_scenario_xml(self, display_name, question_text, completed):
def _make_scenario_xml(self, display_name, show_title, question_text, completed):
return """
<vertical_demo>
<drag-and-drop-v2 display_name='{display_name}' question_text='{question_text}' weight='1' completed='{completed}'/>
<drag-and-drop-v2 display_name='{display_name}' show_title='{show_title}' question_text='{question_text}'
weight='1' completed='{completed}'/>
</vertical_demo>
""".format(display_name=escape(display_name), question_text=escape(question_text), completed=completed)
""".format(
display_name=escape(display_name), show_title=show_title, question_text=escape(question_text),
completed=completed
)
def _get_custom_scenario_xml(self, filename):
data = load_resource(filename)
......
from ddt import ddt, unpack, data
from selenium.common.exceptions import NoSuchElementException
from tests.integration.test_base import BaseIntegrationTest
from workbench import scenarios
......@@ -13,9 +14,11 @@ class TestDragAndDropTitleAndQuestion(BaseIntegrationTest):
('html2', '<span style="color:red">Title: HTML?</span>', '<span style="color:red">Span question</span>'),
)
def test_title_and_question_parameters(self, _, display_name, question_text):
const_page_name = 'Test block parameters'
const_page_id = 'test_block_title'
scenario_xml = self._make_scenario_xml(display_name, question_text, False)
const_page_name = 'Test title and question parameters'
const_page_id = 'test_block_title_and_question'
scenario_xml = self._make_scenario_xml(
display_name=display_name, show_title=True, question_text=question_text, completed=False
)
scenarios.add_xml_scenario(const_page_id, const_page_name, scenario_xml)
self.addCleanup(scenarios.remove_scenario, const_page_id)
......@@ -25,3 +28,27 @@ class TestDragAndDropTitleAndQuestion(BaseIntegrationTest):
question = page.find_element_by_css_selector('section.problem > p')
self.assertEqual(self.get_element_html(question), question_text)
@unpack
@data(
('plain shown', 'title1', True),
('plain hidden', 'title2', False),
('html shown', 'title with <i>HTML</i>', True),
('html hidden', '<span style="color:red">Title: HTML?</span>', False)
)
def test_show_title_parameter(self, _, display_name, show_title):
const_page_name = 'Test show title parameter'
const_page_id = 'test_block_show_title'
scenario_xml = self._make_scenario_xml(
display_name=display_name, show_title=show_title, question_text='Generic question', completed=False
)
scenarios.add_xml_scenario(const_page_id, const_page_name, scenario_xml)
self.addCleanup(scenarios.remove_scenario, const_page_id)
page = self.go_to_page(const_page_name)
if show_title:
problem_header = page.find_element_by_css_selector('h2.problem-header')
self.assertEqual(self.get_element_html(problem_header), display_name)
else:
with self.assertRaises(NoSuchElementException):
page.find_element_by_css_selector('h2.problem-header')
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