From 6e702c31312c6c80fc1a678a7527f3fc28732704 Mon Sep 17 00:00:00 2001 From: Julia Hansbrough Date: Mon, 9 Jun 2014 21:55:27 +0000 Subject: [PATCH] Fix conditional module rendering --- .../lib/xmodule/xmodule/conditional_module.py | 5 ++- .../xmodule/xmodule/tests/test_conditional.py | 42 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/conditional_module.py b/common/lib/xmodule/xmodule/conditional_module.py index 809c6ef54d..d68dd00741 100644 --- a/common/lib/xmodule/xmodule/conditional_module.py +++ b/common/lib/xmodule/xmodule/conditional_module.py @@ -197,7 +197,10 @@ class ConditionalDescriptor(ConditionalFields, SequenceDescriptor): # substitution can be done. if not self.sources_list: if 'sources' in self.xml_attributes and isinstance(self.xml_attributes['sources'], basestring): - self.sources_list = ConditionalDescriptor.parse_sources(self.xml_attributes) + self.sources_list = [ + self.location.course_key.make_usage_key_from_deprecated_string(item) + for item in ConditionalDescriptor.parse_sources(self.xml_attributes) + ] @staticmethod def parse_sources(xml_element): diff --git a/common/lib/xmodule/xmodule/tests/test_conditional.py b/common/lib/xmodule/xmodule/tests/test_conditional.py index d985ff7ef4..4667bfbaa5 100644 --- a/common/lib/xmodule/xmodule/tests/test_conditional.py +++ b/common/lib/xmodule/xmodule/tests/test_conditional.py @@ -253,3 +253,45 @@ class ConditionalModuleXmlTest(unittest.TestCase): print "post-attempt ajax: ", ajax html = ajax['html'] self.assertTrue(any(['This is a secret' in item for item in html])) + + def test_conditional_module_with_empty_sources_list(self): + """ + If a ConditionalDescriptor is initialized with an empty sources_list, we assert that the sources_list is set + via generating UsageKeys from the values in xml_attributes['sources'] + """ + dummy_system = Mock() + dummy_location = Location("edX", "conditional_test", "test_run", "conditional", "SampleConditional", None) + dummy_scope_ids = ScopeIds(None, None, dummy_location, dummy_location) + dummy_field_data = DictFieldData({ + 'data': '', + 'xml_attributes': {'sources': 'i4x://HarvardX/ER22x/poll_question/T15_poll'}, + 'children': None, + }) + conditional = ConditionalDescriptor( + dummy_system, + dummy_field_data, + dummy_scope_ids, + ) + self.assertEqual( + conditional.sources_list[0], + conditional.location.course_key.make_usage_key_from_deprecated_string(conditional.xml_attributes['sources']) + ) + + def test_conditional_module_parse_sources(self): + dummy_system = Mock() + dummy_location = Location("edX", "conditional_test", "test_run", "conditional", "SampleConditional", None) + dummy_scope_ids = ScopeIds(None, None, dummy_location, dummy_location) + dummy_field_data = DictFieldData({ + 'data': '', + 'xml_attributes': {'sources': 'i4x://HarvardX/ER22x/poll_question/T15_poll;i4x://HarvardX/ER22x/poll_question/T16_poll'}, + 'children': None, + }) + conditional = ConditionalDescriptor( + dummy_system, + dummy_field_data, + dummy_scope_ids, + ) + self.assertEqual( + conditional.parse_sources(conditional.xml_attributes), + ['i4x://HarvardX/ER22x/poll_question/T15_poll', 'i4x://HarvardX/ER22x/poll_question/T16_poll'] + )