diff --git a/.travis.yml b/.travis.yml index b46e8ec9..bb9d34b7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ install: - "pip install -r $VIRTUAL_ENV/src/xblock-sdk/test-requirements.txt" - "pip install -r requirements.txt" - "pip uninstall -y xblock-problem-builder && python setup.py sdist && pip install dist/xblock-problem-builder-2.0.tar.gz" + - "pip install -r test_requirements.txt" script: - pep8 problem_builder --max-line-length=120 - pylint problem_builder --disable=all --enable=function-redefined,undefined-variable,unused-variable diff --git a/problem_builder/questionnaire.py b/problem_builder/questionnaire.py index 74837e7b..b2a352fd 100644 --- a/problem_builder/questionnaire.py +++ b/problem_builder/questionnaire.py @@ -90,34 +90,6 @@ def _(self, text): """ translate text """ return self.runtime.service(self, "i18n").ugettext(text) - @classmethod - def parse_xml(cls, node, runtime, keys, id_generator): - """ - Custom XML parser that can handle list type fields properly, - as well as the old way of defining 'question' and 'message' field values via tags. - """ - block = runtime.construct_xblock_from_class(cls, keys) - - # Load XBlock properties from the XML attributes: - for name, value in node.items(): - if name not in block.fields: - logging.warn("XBlock %s does not contain field %s", type(block), name) - continue - field = block.fields[name] - if isinstance(field, List) and not value.startswith('['): - # This list attribute is just a string of comma separated strings: - setattr(block, name, [unicode(val).strip() for val in value.split(',')]) - elif isinstance(field, String): - setattr(block, name, value) - else: - setattr(block, name, field.from_json(value)) - - for xml_child in node: - if xml_child.tag is not etree.Comment: - block.runtime.add_node_as_child(block, xml_child, id_generator) - - return block - @property def html_id(self): """ diff --git a/problem_builder/tests/integration/xml/assessment_1.xml b/problem_builder/tests/integration/xml/assessment_1.xml index e3806062..77bb7ec3 100644 --- a/problem_builder/tests/integration/xml/assessment_1.xml +++ b/problem_builder/tests/integration/xml/assessment_1.xml @@ -14,32 +14,32 @@ - + Yes Maybe not I don't understand - Great! - Ah, damn. -
Really?
+ Great! + Ah, damn. +
Really?
- + I don't want to rate it - I love good grades. - Will do better next time... - Your loss! + I love good grades. + Will do better next time... + Your loss! - + Its elegance Its beauty Its gracefulness Its bugs - This MRQ is indeed very graceful - This is something everyone has to like about this MRQ - Nah, there isn't any! + This MRQ is indeed very graceful + This is something everyone has to like about this MRQ + Nah, there isn't any! diff --git a/problem_builder/tests/integration/xml/assessment_2.xml b/problem_builder/tests/integration/xml/assessment_2.xml index c7543e4e..dcffb26d 100644 --- a/problem_builder/tests/integration/xml/assessment_2.xml +++ b/problem_builder/tests/integration/xml/assessment_2.xml @@ -4,13 +4,13 @@

Please answer the questions below.

- - Yes - Maybe not - I don't understand + + Yes + Maybe not + I don't understand - Great! - Ah, damn. -
Really?
+ Great! + Ah, damn. +
Really?
diff --git a/problem_builder/tests/integration/xml/mcq_1.xml b/problem_builder/tests/integration/xml/mcq_1.xml index 0d73fe4d..47293979 100644 --- a/problem_builder/tests/integration/xml/mcq_1.xml +++ b/problem_builder/tests/integration/xml/mcq_1.xml @@ -1,21 +1,21 @@ - + Yes Maybe not I don't understand - Great! - Ah, damn. -
Really?
+ Great! + Ah, damn. +
Really?
- + I don't want to rate it - I love good grades. - Will do better next time... - Your loss! + I love good grades. + Will do better next time... + Your loss! diff --git a/problem_builder/tests/integration/xml/mcq_with_comments_1.xml b/problem_builder/tests/integration/xml/mcq_with_comments_1.xml index 32540f16..6f119c09 100644 --- a/problem_builder/tests/integration/xml/mcq_with_comments_1.xml +++ b/problem_builder/tests/integration/xml/mcq_with_comments_1.xml @@ -1,15 +1,15 @@ - + Its elegance Its beauty Its gracefulness Its bugs - This MRQ is indeed very graceful - This is something everyone has to like about this MRQ - This is something everyone has to like about beauty - Nah, there isn\'t any! + This MRQ is indeed very graceful + This is something everyone has to like about this MRQ + This is something everyone has to like about beauty + Nah, there isn\'t any! diff --git a/problem_builder/tests/integration/xml/mcq_with_fixed_height_tips.xml b/problem_builder/tests/integration/xml/mcq_with_fixed_height_tips.xml index 4a4dee69..a9ce0520 100644 --- a/problem_builder/tests/integration/xml/mcq_with_fixed_height_tips.xml +++ b/problem_builder/tests/integration/xml/mcq_with_fixed_height_tips.xml @@ -1,13 +1,13 @@ - + Yes Maybe not I don't understand - Great! - Ah, damn. - Really? + Great! + Ah, damn. + Really? diff --git a/problem_builder/tests/integration/xml/mcq_with_html_choices.xml b/problem_builder/tests/integration/xml/mcq_with_html_choices.xml index 2a0c6112..f83de791 100644 --- a/problem_builder/tests/integration/xml/mcq_with_html_choices.xml +++ b/problem_builder/tests/integration/xml/mcq_with_html_choices.xml @@ -1,15 +1,15 @@ - + Its elegance Its beauty Its gracefulness Its bugs - This MCQ is indeed very graceful - This is something everyone has to like about this MCQ - This is something everyone has to like about beauty - Nah, there isn\'t any! + This MCQ is indeed very graceful + This is something everyone has to like about this MCQ + This is something everyone has to like about beauty + Nah, there isn\'t any! diff --git a/problem_builder/tests/integration/xml/mrq_with_html_choices.xml b/problem_builder/tests/integration/xml/mrq_with_html_choices.xml index ffcb95ee..4d234e45 100644 --- a/problem_builder/tests/integration/xml/mrq_with_html_choices.xml +++ b/problem_builder/tests/integration/xml/mrq_with_html_choices.xml @@ -1,15 +1,15 @@ - + Its elegance Its beauty Its gracefulness Its bugs - This MRQ is indeed very graceful - This is something everyone has to like about this MRQ - This is something everyone has to like about beauty - Nah, there aren\'t any! + This MRQ is indeed very graceful + This is something everyone has to like about this MRQ + This is something everyone has to like about beauty + Nah, there aren\'t any! diff --git a/problem_builder/tests/integration/xml/theme_1.xml b/problem_builder/tests/integration/xml/theme_1.xml index c7543e4e..2872d862 100644 --- a/problem_builder/tests/integration/xml/theme_1.xml +++ b/problem_builder/tests/integration/xml/theme_1.xml @@ -4,13 +4,13 @@

Please answer the questions below.

- + Yes Maybe not I don't understand - Great! - Ah, damn. -
Really?
+ Great! + Ah, damn. +
Really?
diff --git a/problem_builder/tip.py b/problem_builder/tip.py index 6d32671d..5c861991 100644 --- a/problem_builder/tip.py +++ b/problem_builder/tip.py @@ -132,7 +132,7 @@ def parse_xml(cls, node, runtime, keys, id_generator): """ block = runtime.construct_xblock_from_class(cls, keys) - block.values = [unicode(val).strip() for val in node.get('values', '').split(',')] + block.values = cls.values.from_string(node.get('values', '[]')) block.width = node.get('width', '') block.height = node.get('height', '') diff --git a/problem_builder/v1/tests/test_upgrade.py b/problem_builder/v1/tests/test_upgrade.py index bc2143f2..828a9f71 100644 --- a/problem_builder/v1/tests/test_upgrade.py +++ b/problem_builder/v1/tests/test_upgrade.py @@ -57,8 +57,7 @@ def setUp(self): @XBlock.register_temp_plugin(MentoringBlock, "mentoring") def test_xml_upgrade(self, file_name): """ - Convert a v1 mentoring block to v2 and then compare the resulting block to a - pre-converted one. + Convert a v1 mentoring block to v2 and then compare the resulting block to a pre-converted one. """ with open("{}/{}_old.xml".format(xml_path, file_name)) as xmlfile: temp_node = etree.parse(xmlfile).getroot() diff --git a/problem_builder/v1/tests/xml/v1_upgrade_a_new.xml b/problem_builder/v1/tests/xml/v1_upgrade_a_new.xml index a33eaa28..7dd3e2bf 100644 --- a/problem_builder/v1/tests/xml/v1_upgrade_a_new.xml +++ b/problem_builder/v1/tests/xml/v1_upgrade_a_new.xml @@ -6,30 +6,30 @@

Please answer the questions below.

- + Yes Maybe not I don't understand - Great! - Ah, damn. - + Great! + Ah, damn. +
Really?
- + I don't want to rate it - I love good grades. - Will do better next time... - Your loss! + I love good grades. + Will do better next time... + Your loss! - + Its elegance Its beauty Its gracefulness Its bugs - This MRQ is indeed very graceful - This is something everyone has to like about this MRQ - Nah, there isn't any! + This MRQ is indeed very graceful + This is something everyone has to like about this MRQ + Nah, there isn't any!

Congratulations!

diff --git a/problem_builder/v1/tests/xml/v1_upgrade_b_new.xml b/problem_builder/v1/tests/xml/v1_upgrade_b_new.xml index 726d1e7c..cdaac62c 100644 --- a/problem_builder/v1/tests/xml/v1_upgrade_b_new.xml +++ b/problem_builder/v1/tests/xml/v1_upgrade_b_new.xml @@ -4,31 +4,31 @@

Now, let's make sure your frog meets the criteria for a strong column 1. Here is your frog:

- + Yes Maybe not I don't understand - Great. Your frog should be happy for you. - In the end, all the feedback you have gotten from others should not lead you to choose a frog that does not also feel happy and important to you. - + Great. Your frog should be happy for you. + In the end, all the feedback you have gotten from others should not lead you to choose a frog that does not also feel happy and important to you. +

If a frog is happy for you, that means it is a frog that you genuinely feel in your own heart to be something that you want to improve. What is in your heart?

- + Yes Maybe not I don't understand - Great. Your frog should implicate you. - + Great. Your frog should implicate you. +

Since the Trial of Uruk-Shan focuses on your own growth and change, it is important to be clear about the ways you are hoping to change and improve.

- Your frog implicates you if it is clear that you must get better at something. Your frog should focus on something you can control. + Your frog implicates you if it is clear that you must get better at something. Your frog should focus on something you can control.
- + I don't understand - Great! - The Trial of Uruk-Shan helps you uncover some of the core beliefs and assumptions you have held that are preventing you from making change. - A frog is important if it is one that could make a big difference in helping you reach your frogs in your work life or your personal life (or both). + Great! + The Trial of Uruk-Shan helps you uncover some of the core beliefs and assumptions you have held that are preventing you from making change. + A frog is important if it is one that could make a big difference in helping you reach your frogs in your work life or your personal life (or both). Great! You have indicated that you have chosen a frog that is happy for you, implicates you, has room for improvement, and is important to you. You are now ready to move onto the next step. diff --git a/problem_builder/v1/xml_changes.py b/problem_builder/v1/xml_changes.py index a4c2d94d..1d2b638a 100644 --- a/problem_builder/v1/xml_changes.py +++ b/problem_builder/v1/xml_changes.py @@ -21,6 +21,7 @@ Each class in this file represents a change made to the XML schema between v1 and v2. """ from lxml import etree +import json import warnings @@ -292,6 +293,22 @@ def apply(self): self.node.tag = "html" +class CommaSeparatedListToJson(Change): + APPLY_TO_ATTRIBUTES = ("values", "correct_choices", "required_choices", "ignored_choices") + + def _convert_value(self, raw_value): + return json.dumps([unicode(val).strip() for val in raw_value.split(',')]) + + @staticmethod + def applies_to(node): + return node.tag in ("pb-tip", "pb-mrq", "pb-mcq", "pb-rating") + + def apply(self): + for attribute in self.APPLY_TO_ATTRIBUTES: + if attribute in self.node.attrib: + self.node.attrib[attribute] = self._convert_value(self.node.attrib[attribute]) + + # An *ordered* list of all XML schema changes: xml_changes = ( RenameMentoringTag, @@ -307,6 +324,7 @@ def apply(self): QuestionSubmitMessageToField, TipChanges, SharedHeaderToHTML, + CommaSeparatedListToJson, ) diff --git a/test_requirements.txt b/test_requirements.txt new file mode 100644 index 00000000..7b7a84e8 --- /dev/null +++ b/test_requirements.txt @@ -0,0 +1 @@ +-e git+https://github.com/edx/XBlock.git@496d3cb9aca1d9e0a18b0f5e73c7bede824e465f#egg=XBlock \ No newline at end of file