def test_no_message_before_submission(self): """ Ensure that we don't show the `submitted_message` before submitting. """ conditions = [ {'input_type': 'radio', 'status': Status('unsubmitted'), 'value': ''}, {'input_type': 'radio', 'status': Status('unsubmitted'), 'value': []}, {'input_type': 'checkbox', 'status': Status('unsubmitted'), 'value': []}, # These tests expose bug #365 # When the bug is fixed, uncomment these cases. #{'input_type': 'radio', 'status': 'unsubmitted', 'value': '2'}, #{'input_type': 'radio', 'status': 'unsubmitted', 'value': ['2']}, #{'input_type': 'radio', 'status': 'unsubmitted', 'value': '2'}, #{'input_type': 'radio', 'status': 'unsubmitted', 'value': ['2']}, #{'input_type': 'checkbox', 'status': 'unsubmitted', 'value': ['2']}, #{'input_type': 'checkbox', 'status': 'unsubmitted', 'value': ['2']}] ] self.context['show_correctness'] = 'never' self.context['submitted_message'] = 'Test message' for test_conditions in conditions: self.context.update(test_conditions) xml = self.render_to_xml(self.context) # Expect that we do NOT see the message yet self.assert_no_xpath(xml, "//div[@class='capa_alert']", self.context)
def test_problem_marked_unsubmitted(self): """ Test all conditions under which the entire problem (not a particular option) is marked unanswered. """ conditions = [ {'status': Status('unsubmitted'), 'input_type': 'radio', 'value': ''}, {'status': Status('unsubmitted'), 'input_type': 'radio', 'value': []}, {'status': Status('unsubmitted'), 'input_type': 'checkbox', 'value': []}, {'input_type': 'radio', 'value': ''}, {'input_type': 'radio', 'value': []}, {'input_type': 'checkbox', 'value': []}, {'input_type': 'checkbox', 'value': ['1']}, {'input_type': 'checkbox', 'value': ['1', '2']}] self.context['status'] = Status('unanswered') for test_conditions in conditions: self.context.update(test_conditions) xml = self.render_to_xml(self.context) xpath = "//div[@class='indicator-container']/span[@class='status unanswered']" self.assert_has_xpath(xml, xpath, self.context) # Should NOT mark individual options self.assert_no_xpath(xml, "//label[@class='choicegroup_incorrect']", self.context) self.assert_no_xpath(xml, "//label[@class='choicegroup_correct']", self.context)
def test_problem_marked_incorrect(self): """Test all conditions under which the entire problem (not a particular option) is marked incorrect""" grouping_tags = {'radio': 'label', 'checkbox': 'section'} conditions = [ {'status': Status('incorrect'), 'input_type': 'radio', 'value': {}}, {'status': Status('incorrect'), 'input_type': 'checkbox', 'value': self.WRONG_CHOICE_CHECKBOX}, {'status': Status('incorrect'), 'input_type': 'checkbox', 'value': self.BOTH_CHOICE_CHECKBOX}, {'status': Status('incorrect'), 'input_type': 'checkbox', 'value': self.VALUE_DICT}, {'status': Status('incomplete'), 'input_type': 'radio', 'value': {}}, {'status': Status('incomplete'), 'input_type': 'checkbox', 'value': self.WRONG_CHOICE_CHECKBOX}, {'status': Status('incomplete'), 'input_type': 'checkbox', 'value': self.BOTH_CHOICE_CHECKBOX}, {'status': Status('incomplete'), 'input_type': 'checkbox', 'value': self.VALUE_DICT}] for test_conditions in conditions: self.context.update(test_conditions) xml = self.render_to_xml(self.context) xpath = "//div[@class='indicator-container']/span[@class='status incorrect']" self.assert_has_xpath(xml, xpath, self.context) # Should NOT mark individual options grouping_tag = grouping_tags[test_conditions['input_type']] self.assert_no_xpath(xml, "//{0}[@class='choicetextgroup_incorrect']".format(grouping_tag), self.context) self.assert_no_xpath(xml, "//{0}[@class='choicetextgroup_correct']".format(grouping_tag), self.context)
def test_never_show_correctness(self): """ Test conditions under which we tell the template to NOT show correct/incorrect, but instead show a message. This is used, for example, by the Justice course to ask questions without specifying a correct answer. When the student responds, the problem displays "Thank you for your response" """ conditions = [ {'input_type': 'radio', 'status': Status('correct'), 'value': ''}, {'input_type': 'radio', 'status': Status('correct'), 'value': '2'}, {'input_type': 'radio', 'status': Status('correct'), 'value': ['2']}, {'input_type': 'radio', 'status': Status('incorrect'), 'value': '2'}, {'input_type': 'radio', 'status': Status('incorrect'), 'value': []}, {'input_type': 'radio', 'status': Status('incorrect'), 'value': ['2']}, {'input_type': 'checkbox', 'status': Status('correct'), 'value': []}, {'input_type': 'checkbox', 'status': Status('correct'), 'value': ['2']}, {'input_type': 'checkbox', 'status': Status('incorrect'), 'value': []}, {'input_type': 'checkbox', 'status': Status('incorrect'), 'value': ['2']}] self.context['show_correctness'] = 'never' self.context['submitted_message'] = 'Test message' for test_conditions in conditions: self.context.update(test_conditions) xml = self.render_to_xml(self.context) # Should NOT mark the entire problem correct/incorrect xpath = "//div[@class='indicator-container']/span[@class='status correct']" self.assert_no_xpath(xml, xpath, self.context) xpath = "//div[@class='indicator-container']/span[@class='status incorrect']" self.assert_no_xpath(xml, xpath, self.context) # Should NOT mark individual options self.assert_no_xpath(xml, "//label[@class='choicegroup_incorrect']", self.context) self.assert_no_xpath(xml, "//label[@class='choicegroup_correct']", self.context) # Expect to see the message self.assert_has_text(xml, "//div[@class='capa_alert']", self.context['submitted_message'])
def setUp(self): self.context = {'id': 2, 'drag_and_drop_json': '', 'value': 0, 'status': Status('unsubmitted'), 'msg': ''} super(DragAndDropTemplateTest, self).setUp()
def setUp(self): choices = [ ( '1_choiceinput_0bc', [ {'tail_text': '', 'type': 'text', 'value': '', 'contents': ''}, {'tail_text': '', 'type': 'textinput', 'value': '', 'contents': 'choiceinput_0_textinput_0'}, ] ), ( '1_choiceinput_1bc', [ {'tail_text': '', 'type': 'text', 'value': '', 'contents': ''}, {'tail_text': '', 'type': 'textinput', 'value': '', 'contents': 'choiceinput_1_textinput_0'}, ] ) ] self.context = { 'id': '1', 'choices': choices, 'status': Status('correct'), 'input_type': 'radio', 'label': 'choicetext label', 'value': self.VALUE_DICT, } super(ChoiceTextGroupTemplateTest, self).setUp()
def setUp(self): super(ChoiceTextGroupTemplateTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments choices = [ ( '1_choiceinput_0bc', [ {'tail_text': '', 'type': 'text', 'value': '', 'contents': ''}, {'tail_text': '', 'type': 'textinput', 'value': '', 'contents': 'choiceinput_0_textinput_0'}, ] ), ( '1_choiceinput_1bc', [ {'tail_text': '', 'type': 'text', 'value': '', 'contents': ''}, {'tail_text': '', 'type': 'textinput', 'value': '', 'contents': 'choiceinput_1_textinput_0'}, ] ) ] self.context = { 'id': '1', 'choices': choices, 'status': Status('correct'), 'input_type': 'radio', 'value': self.VALUE_DICT, 'response_data': self.RESPONSE_DATA }
def setUp(self): super(DragAndDropTemplateTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.context = {'id': 2, 'drag_and_drop_json': '', 'value': 0, 'status': Status('unsubmitted'), 'msg': ''}
def assert_status(self, status_div=False, status_class=False): """ Verify status information. Arguments: status_div (bool): check presence of status div status_class (bool): check presence of status class """ cases = [('correct', 'correct'), ('unsubmitted', 'unanswered'), ('incorrect', 'incorrect'), ('incomplete', 'incorrect')] for context_status, div_class in cases: self.context['status'] = Status(context_status) xml = self.render_to_xml(self.context) # Expect that we get a <div> with correct class if status_div: xpath = "//div[normalize-space(@class)='%s']" % div_class self.assert_has_xpath(xml, xpath, self.context) # Expect that we get a <span> with class="status" # (used to by CSS to draw the green check / red x) self.assert_has_text( xml, "//span[@class=normalize-space('status {}')]/span[@class='sr']" .format(div_class if status_class else ''), self.context['status'].display_tooltip)
def test_option_marked_correct(self): """ Test conditions under which a particular option (not the entire problem) is marked correct. """ conditions = [{ 'input_type': 'radio', 'question_label': '', 'value': '2' }, { 'input_type': 'radio', 'question_label': '', 'value': ['2'] }] self.context['status'] = Status('correct') for test_conditions in conditions: self.context.update(test_conditions) xml = self.render_to_xml(self.context) xpath = "//label[@class='choicegroup_correct']" self.assert_has_xpath(xml, xpath, self.context) # Should NOT mark the whole problem xpath = "//div[@class='indicator_container']/span" self.assert_no_xpath(xml, xpath, self.context)
def setUp(self): self.context = {'id': '1', 'status': Status('correct'), 'label': 'test', 'value': '3', 'preprocessor': None, 'trailing_text': None} super(TextlineTemplateTest, self).setUp()
def setUp(self): super(ChemicalEquationTemplateTest, self).setUp() self.context = { 'id': '1', 'status': Status('correct'), 'previewer': 'dummy.js', 'value': '101', }
def setUp(self): super(ChemicalEquationTemplateTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.context = { 'id': '1', 'status': Status('correct'), 'previewer': 'dummy.js', 'value': '101', }
def setUp(self): self.context = { 'id': 2, 'options': [], 'status': Status('unsubmitted'), 'label': 'test', 'value': 0 } super(OptionInputTemplateTest, self).setUp()
def setUp(self): self.context = { 'id': 2, 'value': 'PREFILLED_VALUE', 'status': Status('unsubmitted'), 'label': 'test', 'previewer': 'file.js', 'reported_status': 'REPORTED_STATUS', } super(FormulaEquationInputTemplateTest, self).setUp()
def setUp(self): choices = [('1', 'choice 1'), ('2', 'choice 2'), ('3', 'choice 3')] self.context = {'id': '1', 'choices': choices, 'status': Status('correct'), 'label': 'test', 'input_type': 'checkbox', 'name_array_suffix': '1', 'value': '3'} super(ChoiceGroupTemplateTest, self).setUp()
def setUp(self): super(OptionInputTemplateTest, self).setUp() self.context = { 'id': 2, 'options': [], 'status': Status('unsubmitted'), 'value': 0, 'default_option_text': 'Select an option', 'response_data': self.RESPONSE_DATA, 'describedby_html': self.DESCRIBEDBY, }
def setUp(self): super(TextlineTemplateTest, self).setUp() self.context = { 'id': '1', 'status': Status('correct'), 'value': '3', 'preprocessor': None, 'trailing_text': None, 'response_data': self.RESPONSE_DATA, 'describedby_html': self.DESCRIBEDBY, }
def setUp(self): super(TextlineTemplateTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.context = { 'id': '1', 'status': Status('correct'), 'value': '3', 'preprocessor': None, 'trailing_text': None, 'response_data': self.RESPONSE_DATA, 'describedby_html': HTML(self.DESCRIBEDBY), }
def setUp(self): super(OptionInputTemplateTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.context = { 'id': 2, 'options': [], 'status': Status('unsubmitted'), 'value': 0, 'default_option_text': 'Select an option', 'response_data': self.RESPONSE_DATA, 'describedby_html': HTML(self.DESCRIBEDBY), }
def setUp(self): super(FormulaEquationInputTemplateTest, self).setUp() self.context = { 'id': 2, 'value': 'PREFILLED_VALUE', 'status': Status('unsubmitted'), 'previewer': 'file.js', 'reported_status': 'REPORTED_STATUS', 'trailing_text': None, 'response_data': self.RESPONSE_DATA, 'describedby_html': self.DESCRIBEDBY, }
def test_do_inline(self): cases = [('correct', 'correct'), ('unsubmitted', 'unanswered'), ('incorrect', 'incorrect'), ('incomplete', 'incorrect')] self.context['inline'] = True for (context_status, div_class) in cases: self.context['status'] = Status(context_status) xml = self.render_to_xml(self.context) # Expect that we get a <div> with correct class xpath = "//div[@class='%s inline']" % div_class self.assert_has_xpath(xml, xpath, self.context)
def setUp(self): super(ChoiceGroupTemplateTest, self).setUp() choices = [('1', 'choice 1'), ('2', 'choice 2'), ('3', 'choice 3')] self.context = { 'id': '1', 'choices': choices, 'status': Status('correct'), 'input_type': 'checkbox', 'name_array_suffix': '1', 'value': '3', 'response_data': self.RESPONSE_DATA, 'describedby_html': self.DESCRIBEDBY, }
def test_submission_status(self): """ Test that the submission status displays correctly. """ # Test cases of `(input_status, expected_css_class)` tuples test_cases = [('unsubmitted', 'unanswered'), ('incomplete', 'incorrect'), ('incorrect', 'incorrect')] for (input_status, expected_css_class) in test_cases: self.context['status'] = Status(input_status) xml = self.render_to_xml(self.context) xpath = "//span[@class='status {0}']".format(expected_css_class) self.assert_has_xpath(xml, xpath, self.context) # If individual options are being marked, then expect # just the option to be marked incorrect, not the whole problem self.context['has_options_value'] = True self.context['status'] = Status('incorrect') xpath = "//span[@class='incorrect']" xml = self.render_to_xml(self.context) self.assert_no_xpath(xml, xpath, self.context)
def test_grouping_tag(self): """ Tests whether we are using a section or a label to wrap choice elements. Section is used for checkbox, so inputting text does not deselect """ input_tags = ('radio', 'checkbox') self.context['status'] = Status('correct') xpath = "//section[@id='forinput1_choiceinput_0bc']" self.context['value'] = {} for input_type in input_tags: self.context['input_type'] = input_type xml = self.render_to_xml(self.context) self.assert_has_xpath(xml, xpath, self.context)
def test_status(self): # Test cases, where each tuple represents # `(input_status, expected_css_class)` test_cases = [('unsubmitted', 'status unanswered'), ('correct', 'status correct'), ('incorrect', 'status incorrect'), ('incomplete', 'status incorrect')] for (input_status, expected_css_class) in test_cases: self.context['status'] = Status(input_status) xml = self.render_to_xml(self.context) xpath = "//span[@class='{0}']".format(expected_css_class) self.assert_has_xpath(xml, xpath, self.context)
def setUp(self): self.context = {'id': 2, 'value': '<p>Test value</p>', 'title': '<h1>This is a title</h1>', 'text': '<p><b>This</b> is a test.</p>', 'comment': '<p>This is a test comment</p>', 'comment_prompt': '<p>This is a test comment prompt</p>', 'comment_value': '<p>This is the value of a test comment</p>', 'tag_prompt': '<p>This is a tag prompt</p>', 'options': [], 'has_options_value': False, 'debug': False, 'status': Status('unsubmitted'), 'return_to_annotation': False, 'msg': '<p>This is a test message</p>', } super(AnnotationInputTemplateTest, self).setUp()
def setUp(self): super(SchematicInputTemplateTest, self).setUp() self.context = { 'id': '1', 'status': Status('correct'), 'previewer': 'dummy.js', 'value': '101', 'STATIC_URL': '/dummy-static/', 'msg': '', 'initial_value': 'two large batteries', 'width': '100', 'height': '100', 'parts': 'resistors, capacitors, and flowers', 'setup_script': '/dummy-static/js/capa/schematicinput.js', 'analyses': 'fast, slow, and pink', 'submit_analyses': 'maybe', }
def setUp(self): super(CodeinputTemplateTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.context = { 'id': '1', 'status': Status('correct'), 'mode': 'parrot', 'linenumbers': 'false', 'rows': '37', 'cols': '11', 'tabsize': '7', 'hidden': '', 'msg': '', 'value': 'print "good evening"', 'aria_label': 'python editor', 'code_mirror_exit_message': 'Press ESC then TAB or click outside of the code editor to exit', 'response_data': self.RESPONSE_DATA, 'describedby': HTML(self.DESCRIBEDBY), }
def test_status(self): cases = [('correct', 'correct', 'correct'), ('unsubmitted', 'unanswered', 'unanswered'), ('incorrect', 'incorrect', 'incorrect'), ('incomplete', 'incorrect', 'incomplete')] for (context_status, div_class, status_mark) in cases: self.context['status'] = Status(context_status) xml = self.render_to_xml(self.context) # Expect that we get a <div> with correct class xpath = "//div[@class='%s ']" % div_class self.assert_has_xpath(xml, xpath, self.context) # Expect that we get a <span> with class="status" # (used to by CSS to draw the green check / red x) self.assert_has_text(xml, "//span[@class='status']/span[@class='sr']", status_mark, exact=False)