Commit 3e1567d8 by E. Kolpakov

Further improved test scenario discovery

Added plain text tests (broken)
parent 5092ba6e
...@@ -13,17 +13,14 @@ class BaseIntegrationTest(SeleniumTest): ...@@ -13,17 +13,14 @@ class BaseIntegrationTest(SeleniumTest):
def setUp(self): def setUp(self):
super(BaseIntegrationTest, self).setUp() super(BaseIntegrationTest, self).setUp()
# Use test scenarios self.browser.get(self.live_server_url) # Needed to load scenarios once
self.browser.get(self.live_server_url) # Needed to load tests once
scenarios.SCENARIOS.clear() scenarios.SCENARIOS.clear()
for identifier, title, xml in self._get_scenarios_for_test(): for identifier, title, xml in self._get_scenarios_for_test():
scenarios.add_xml_scenario(identifier, title, xml) scenarios.add_xml_scenario(identifier, title, xml)
self.addCleanup(scenarios.remove_scenario, identifier) self.addCleanup(scenarios.remove_scenario, identifier)
# Suzy opens the browser to visit the workbench
self.browser.get(self.live_server_url) self.browser.get(self.live_server_url)
# She knows it's the site by the header
header1 = self.browser.find_element_by_css_selector('h1') header1 = self.browser.find_element_by_css_selector('h1')
self.assertEqual(header1.text, 'XBlock scenarios') self.assertEqual(header1.text, 'XBlock scenarios')
...@@ -41,3 +38,13 @@ class BaseIntegrationTest(SeleniumTest): ...@@ -41,3 +38,13 @@ class BaseIntegrationTest(SeleniumTest):
def get_element_html(self, element): def get_element_html(self, element):
return element.get_attribute('innerHTML').strip() return element.get_attribute('innerHTML').strip()
class SingleScenarioIntegrationTest(BaseIntegrationTest):
def setUp(self):
super(SingleScenarioIntegrationTest, self).setUp()
def _get_scenarios_for_test(self):
identifier, title, scenario = self._get_scenario_for_test()
self._page_title = title
return [(identifier, title, scenario)]
\ No newline at end of file
from tests.integration.test_base import SingleScenarioIntegrationTest
from tests.utils import load_scenario_from_file
class TestBlockContentsPlain(SingleScenarioIntegrationTest):
def _get_scenario_for_test(self):
return load_scenario_from_file('integration/data/drag_and_drop-whats_up.json')
def test_check_item_labels(self):
page = self.go_to_page(self._page_title)
items_container = page.find_element_by_css_selector('ul.items')
items = items_container.find_elements_by_css_selector('li.option')
self.assertEqual(len(items), 3)
self.assertEqual(items[0].text, 'A')
self.assertEqual(items[1].text, 'B')
self.assertEqual(items[2].text, 'X')
\ No newline at end of file
from xml.sax.saxutils import escape from xml.sax.saxutils import escape
from nose_parameterized import parameterized from nose_parameterized import parameterized
from tests.utils import make_scenario_from_data
from workbench import scenarios from workbench import scenarios
from tests.integration.test_base import BaseIntegrationTest from tests.integration.test_base import BaseIntegrationTest
...@@ -15,14 +16,8 @@ class TestBlockParameters(BaseIntegrationTest): ...@@ -15,14 +16,8 @@ class TestBlockParameters(BaseIntegrationTest):
def test_block_parameters(self, _, display_name, question_text): def test_block_parameters(self, _, display_name, question_text):
const_page_name = "Test block parameters" const_page_name = "Test block parameters"
const_page_id = 'test_block_title' const_page_id = 'test_block_title'
scenarios.add_xml_scenario( scenario_xml = make_scenario_from_data(None, display_name, question_text, False)
const_page_id, const_page_name, scenarios.add_xml_scenario(const_page_id, const_page_name, scenario_xml)
"""
<vertical_demo><drag-and-drop-v2
display_name='{display_name}' question_text='{question_text}'
/></vertical_demo>
""".format(display_name=escape(display_name), question_text=escape(question_text))
)
self.addCleanup(scenarios.remove_scenario, const_page_id) self.addCleanup(scenarios.remove_scenario, const_page_id)
page = self.go_to_page(const_page_name) page = self.go_to_page(const_page_name)
......
import os import os
import json
import pkg_resources import pkg_resources
from xml.sax.saxutils import escape from xml.sax.saxutils import escape
def load_resource(resource_path): def load_resource(resource_path):
""" """
Gets the content of a resource Gets the content of a resource
...@@ -11,15 +14,17 @@ def load_resource(resource_path): ...@@ -11,15 +14,17 @@ def load_resource(resource_path):
def make_scenario_from_data(data, display_name, question_text, completed): def make_scenario_from_data(data, display_name, question_text, completed):
return """ parameters = {
<vertical_demo> 'data': data,
<drag-and-drop-v2 'display_name': display_name,
display_name='{display_name}' question_text='{question_text}' 'question_text': question_text,
weight='1' completed='{completed}' 'completed': completed,
data='{data}' 'weight': '1'
/> }
</vertical_demo> attributes = ["{0}='{1}'".format(key, escape(value)) for key, value in parameters.items() if value]
""".format(data=escape(data), display_name=display_name, question_text=question_text, completed=completed) attributes_str = " ".join(attributes)
return """<vertical_demo><drag-and-drop-v2 {attrs}/></vertical_demo>""".format(attrs=attributes_str)
def format_name(raw_name): def format_name(raw_name):
return raw_name.replace('_', ' ').title() return raw_name.replace('_', ' ').title()
...@@ -38,7 +43,7 @@ def get_scenarios_from_path(scenarios_path, include_identifier=False): ...@@ -38,7 +43,7 @@ def get_scenarios_from_path(scenarios_path, include_identifier=False):
for template in os.listdir(scenarios_fullpath): for template in os.listdir(scenarios_fullpath):
if not template.endswith('.json'): if not template.endswith('.json'):
continue continue
identifier, title, scenario = get_scenario_from_file(template, scenarios_path) identifier, title, scenario = get_scenario_from_file(scenarios_path, template)
if not include_identifier: if not include_identifier:
scenarios.append((title, scenario)) scenarios.append((title, scenario))
else: else:
...@@ -47,12 +52,13 @@ def get_scenarios_from_path(scenarios_path, include_identifier=False): ...@@ -47,12 +52,13 @@ def get_scenarios_from_path(scenarios_path, include_identifier=False):
return scenarios return scenarios
def get_scenario_from_file(filename, scenarios_path): def get_scenario_from_file(scenarios_path, filename):
identifier = filename[:-5] identifier = filename[:-5]
block_title, question_text = map(format_name, identifier.split('-')) block_title, question_text = map(format_name, identifier.split('-'))
title = identifier.replace('_', ' ').replace('-', ' ').title() title = identifier.replace('_', ' ').replace('-', ' ').title()
scenario_file = os.path.join(scenarios_path, filename) scenario_file = os.path.join(scenarios_path, filename)
scenario = make_scenario_from_data(scenario_file, block_title, question_text, False) scenario_data = json.loads(load_resource(scenario_file))
scenario = make_scenario_from_data(scenario_data, block_title, question_text, False)
return identifier, title, scenario return identifier, title, scenario
...@@ -61,3 +67,9 @@ def load_scenarios_from_path(scenarios_path): ...@@ -61,3 +67,9 @@ def load_scenarios_from_path(scenarios_path):
Load all xml files contained in a specified directory, as workbench scenarios Load all xml files contained in a specified directory, as workbench scenarios
""" """
return get_scenarios_from_path(scenarios_path, include_identifier=True) return get_scenarios_from_path(scenarios_path, include_identifier=True)
def load_scenario_from_file(filename):
scenario_path, template = os.path.split(filename)
return get_scenario_from_file(scenario_path, template)
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