diff --git a/common/lib/capa/capa/tests/response_xml_factory.py b/common/lib/capa/capa/tests/response_xml_factory.py index c7e43f5152..7aa299d20d 100644 --- a/common/lib/capa/capa/tests/response_xml_factory.py +++ b/common/lib/capa/capa/tests/response_xml_factory.py @@ -676,26 +676,23 @@ class AnnotationResponseXMLFactory(ResponseXMLFactory): def create_input_element(self, **kwargs): """ Create a element.""" - title = kwargs.get('title', 'super cool annotation') - text = kwargs.get('text', 'texty text') - comment = kwargs.get('comment', 'blah blah erudite comment blah blah') - comment_prompt = kwargs.get('comment_prompt', 'type a commentary below') - tag_prompt = kwargs.get('tag_prompt', 'select one tag') - options = kwargs.get('options', [ - ('green', 'correct'), - ('eggs', 'incorrect'), - ('ham', 'partially-correct') - ]) - - # Create the element input_element = etree.Element("annotationinput") - etree.SubElement(input_element, 'title') - etree.SubElement(input_element, 'text') - etree.SubElement(input_element, 'comment') - etree.SubElement(input_element, 'comment_prompt') - etree.SubElement(input_element, 'tag_prompt') + text_children = [ + {'tag': 'title', 'text': kwargs.get('title', 'super cool annotation') }, + {'tag': 'text', 'text': kwargs.get('text', 'texty text') }, + {'tag': 'comment', 'text':kwargs.get('comment', 'blah blah erudite comment blah blah') }, + {'tag': 'comment_prompt', 'text': kwargs.get('comment_prompt', 'type a commentary below') }, + {'tag': 'tag_prompt', 'text': kwargs.get('tag_prompt', 'select one tag') } + ] + + for child in text_children: + etree.SubElement(input_element, child['tag']).text = child['text'] + + default_options = [('green', 'correct'),('eggs', 'incorrect'),('ham', 'partially-correct')] + options = kwargs.get('options', default_options) options_element = etree.SubElement(input_element, 'options') + for (description, correctness) in options: option_element = etree.SubElement(options_element, 'option', {'choice': correctness}) option_element.text = description diff --git a/common/lib/capa/capa/tests/test_inputtypes.py b/common/lib/capa/capa/tests/test_inputtypes.py index 8b8bbe74de..c9f14cb79b 100644 --- a/common/lib/capa/capa/tests/test_inputtypes.py +++ b/common/lib/capa/capa/tests/test_inputtypes.py @@ -624,6 +624,7 @@ class AnnotationInputTest(unittest.TestCase): ], 'value': json_value, 'options_value': value['options'], + 'has_options_value': len(value['options']) > 0, 'comment_value': value['comment'], 'debug': False, 'return_to_annotation': True