def _inner(*args, **kwargs): # pylint: disable=C0111 # Create a scenario, just one tag for our mocked class. scenarios.add_xml_scenario(scenario_name, "Temporary scenario", "<%s/>" % temp_class.__name__) try: return func(*args, **kwargs) finally: scenarios.remove_scenario(scenario_name)
def load_scenarios_from_path(scenarios_path): """ Load all xml files contained in a specified directory, as workbench scenarios """ scenarios = get_scenarios_from_path(scenarios_path, include_identifier=True) for identifier, title, xml_template in scenarios: add_xml_scenario(identifier, title, xml_template) return scenarios
def _inner(*args, **kwargs): # pylint: disable=C0111 # Create a scenario, just one tag for our mocked class. scenarios.add_xml_scenario( scenario_name, "Temporary scenario {}".format(temp_class.__name__), "<%s/>" % temp_class.__name__ ) try: return func(*args, **kwargs) finally: scenarios.remove_scenario(scenario_name)
def _inner(*args, **kwargs): # Create a scenario, just one tag for our mocked class. scenarios.add_xml_scenario( scenario_name, u"Temporary scenario {}".format(temp_class.__name__), "<%s/>" % temp_class.__name__ ) try: return func(*args, **kwargs) finally: scenarios.remove_scenario(scenario_name)
def load_scenario(self, xml, view_name=None, student_id='tester1'): """ Load a scenario into the workbench and fetch it using self.client """ import workbench.urls # Trigger scenario load. pylint: disable=unused-variable from workbench.scenarios import SCENARIOS, add_xml_scenario SCENARIOS.clear() add_xml_scenario("test", "Test Scenario", xml) scenario_url = '/scenario/test/' if view_name: scenario_url += view_name + '/' scenario_url += '?student_id=' + student_id return self.client.get(scenario_url)
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) 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) problem_header = page.find_element_by_css_selector('h2.problem-header') self.assertEqual(self.get_element_html(problem_header), display_name) question = page.find_element_by_css_selector('section.problem > p') self.assertEqual(self.get_element_html(question), question_text)
def setUp(self): super(ThreeThumbsTest, self).setUp() scenarios.add_xml_scenario( "test_three_thumbs", "three thumbs test", """<vertical_demo><thumbs/><thumbs/><thumbs/></vertical_demo>""") self.addCleanup(scenarios.remove_scenario, "test_three_thumbs") # Suzy opens the browser to visit the workbench 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') self.assertEqual(header1.text, 'XBlock scenarios')
def test_studio_view(self): """ Test the studio edit view for grade leaderboards. """ # We need <generic> XBlock in order to do this test, as we need a # hierarchy and the normal SDK demo blocks don't support studio_view. # However, <generic> is not usually registered, so if we put it in the # xml folder it will cause issues. Instead, we create the scenario now: import workbench.urls # Trigger scenario load. pylint: disable=unused-variable from workbench.scenarios import SCENARIOS, add_xml_scenario SCENARIOS.clear() add_xml_scenario( "test", "Test Scenario", """ <generic> <generic display_name="Problem1" /> <generic display_name="Problem2" /> <generic-no-score display_name="has_score False container"> <generic display_name="Problem3"/> </generic-no-score> <generic-no-score display_name="has_score False leaf"/> <grade_leaderboard count="93"/> </generic> """) scenario_url = self.live_server_url + '/scenario/test/studio_view/' self.browser.get(scenario_url) count_field = self.browser.find_element_by_css_selector( 'input[id=count]') self.assertEqual(count_field.get_attribute('value'), "93") select = self.browser.find_element_by_css_selector( 'select#graded_target_id') option_elements = select.find_elements_by_css_selector('option') options = {} for opt in option_elements: desc = opt.text.strip() value = opt.get_attribute("value") enabled = not opt.get_attribute("disabled") options[desc] = (value, enabled) for display_name in ("Problem1", "Problem2", "Problem3", "has_score False container"): self.assertIn(display_name, options) self.assertTrue(options[display_name][1]) # Should be enabled for display_name in ("has_score False leaf", "Grade Leaderboard (This leaderboard)"): self.assertIn(display_name, options) # The current block and any blocks that don't contain a has_score problem # should not be selectable: self.assertFalse(options[display_name][1])
def setUp(self): super(ThreeThumbsTest, self).setUp() scenarios.add_xml_scenario( "test_three_thumbs", "three thumbs test", """<vertical><thumbs/><thumbs/><thumbs/></vertical>""" ) self.addCleanup(scenarios.remove_scenario, "test_three_thumbs") # Suzy opens the browser to visit the workbench 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') self.assertEqual(header1.text, 'XBlock scenarios')
def setUp(self): super(SeleniumBaseTest, self).setUp() # Use test scenarios: loader = ResourceLoader(self._module_name) scenarios_list = loader.load_scenarios_from_path(self.relative_scenario_path, include_identifier=True) for identifier, title, xml in scenarios_list: add_xml_scenario(identifier, title, xml) self.addCleanup(remove_scenario, identifier) # Suzy opens the browser to visit the workbench 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') self.assertEqual(header1.text, 'XBlock scenarios')
def test_studio_view(self): """ Test the studio edit view for grade leaderboards. """ # We need <generic> XBlock in order to do this test, as we need a # hierarchy and the normal SDK demo blocks don't support studio_view. # However, <generic> is not usually registered, so if we put it in the # xml folder it will cause issues. Instead, we create the scenario now: import workbench.urls # Trigger scenario load. pylint: disable=unused-variable from workbench.scenarios import SCENARIOS, add_xml_scenario SCENARIOS.clear() add_xml_scenario( "test", "Test Scenario", """ <generic> <generic display_name="Problem1" /> <generic display_name="Problem2" /> <generic-no-score display_name="has_score False container"> <generic display_name="Problem3"/> </generic-no-score> <generic-no-score display_name="has_score False leaf"/> <grade_leaderboard count="93"/> </generic> """ ) scenario_url = self.live_server_url + '/scenario/test/studio_view/' self.browser.get(scenario_url) count_field = self.browser.find_element_by_css_selector('input[id=count]') self.assertEqual(count_field.get_attribute('value'), "93") select = self.browser.find_element_by_css_selector('select#graded_target_id') option_elements = select.find_elements_by_css_selector('option') options = {} for opt in option_elements: desc = opt.text.strip() value = opt.get_attribute("value") enabled = not opt.get_attribute("disabled") options[desc] = (value, enabled) for display_name in ("Problem1", "Problem2", "Problem3", "has_score False container"): self.assertIn(display_name, options) self.assertTrue(options[display_name][1]) # Should be enabled for display_name in ("has_score False leaf", "Grade Leaderboard (This leaderboard)"): self.assertIn(display_name, options) # The current block and any blocks that don't contain a has_score problem # should not be selectable: self.assertFalse(options[display_name][1])
def setUp(self): super(MentoringBaseTest, self).setUp() # Use test scenarios self.browser.get(self.live_server_url) # Needed to load tests once scenarios.SCENARIOS.clear() scenarios_list = load_scenarios_from_path('../tests/xml') for identifier, title, xml in scenarios_list: scenarios.add_xml_scenario(identifier, title, xml) self.addCleanup(scenarios.remove_scenario, identifier) # Suzy opens the browser to visit the workbench 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') self.assertEqual(header1.text, 'XBlock scenarios')
def test_title_parameters(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, problem_text='Generic problem', ) 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('h3.hd.hd-3.problem-header') self.assertEqual(self.get_element_html(problem_header), display_name) else: with self.assertRaises(NoSuchElementException): page.find_element_by_css_selector('h3.hd.hd-3.problem-header')
def test_problem_parameters(self, problem_text, show_problem_header): const_page_name = 'Test title and problem parameters' const_page_id = 'test_block_title_and_problem' scenario_xml = self._make_scenario_xml( display_name="Title", show_title=True, problem_text=problem_text, show_problem_header=show_problem_header, ) 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) is_problem_header_visible = len(page.find_elements_by_css_selector('.problem > h4')) > 0 self.assertEqual(is_problem_header_visible, show_problem_header) problem = page.find_element_by_css_selector('.problem > p') self.assertEqual(self.get_element_html(problem), problem_text)
def test_problem_parameters(self, problem_text, show_problem_header): const_page_name = 'Test title and problem parameters' const_page_id = 'test_block_title_and_problem' scenario_xml = self._make_scenario_xml( display_name="Title", show_title=True, problem_text=problem_text, show_problem_header=show_problem_header, ) 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) is_problem_header_visible = len(page.find_elements_by_css_selector('section.problem > h3')) > 0 self.assertEqual(is_problem_header_visible, show_problem_header) problem = page.find_element_by_css_selector('section.problem > p') self.assertEqual(self.get_element_html(problem), problem_text)
def test_title_parameters(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, problem_text='Generic problem', ) 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-title') self.assertEqual(self.get_element_html(problem_header), display_name) else: with self.assertRaises(NoSuchElementException): page.find_element_by_css_selector('h2.problem-title')
def setUp(self): super(ProblemInteractionTest, self).setUp() one_problem = """ <problem_demo> <html_demo><p class="the_numbers">$a $b</p></html_demo> <textinput_demo name="sum_input" input_type="int" /> <equality_demo name="sum_checker" left="./sum_input/@student_input" right="$c" /> <script> import random a = random.randint(1, 1000000) b = random.randint(1, 1000000) c = a + b </script> </problem_demo> """ self.num_problems = 3 scenarios.add_xml_scenario( "test_many_problems", "Many problems", "<vertical_demo>" + one_problem * self.num_problems + "</vertical_demo>") self.addCleanup(scenarios.remove_scenario, "test_many_problems")
def setUp(self): super(ProblemInteractionTest, self).setUp() one_problem = """ <problem> <html><p class="the_numbers">$a $b</p></html> <textinput name="sum_input" input_type="int" /> <equality name="sum_checker" left="./sum_input/@student_input" right="$c" /> <script> import random a = random.randint(1, 1000000) b = random.randint(1, 1000000) c = a + b </script> </problem> """ self.num_problems = 3 scenarios.add_xml_scenario( "test_many_problems", "Many problems", "<vertical>" + one_problem * self.num_problems + "</vertical>" ) self.addCleanup(scenarios.remove_scenario, "test_many_problems")
def set_scenario_xml(xml): """ Reset the workbench to have only one scenario with the specified XML """ SCENARIOS.clear() add_xml_scenario("test", "Test Scenario", xml)
def _add_scenario(self, identifier, title, xml): scenarios.add_xml_scenario(identifier, title, xml) self.addCleanup(scenarios.remove_scenario, identifier)