From 55a0cada7b5299147b65251ac5e50d5c08f9ac32 Mon Sep 17 00:00:00 2001 From: Victor Shnayder Date: Fri, 2 Nov 2012 16:59:41 -0400 Subject: [PATCH] Fix a bug with pointer-tag detection on load if a tag has text but no children, wasn't properly detected as an inline definition. --- .../lib/xmodule/xmodule/tests/test_import.py | 29 +++++++++++++++++++ common/lib/xmodule/xmodule/xml_module.py | 7 +++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/common/lib/xmodule/xmodule/tests/test_import.py b/common/lib/xmodule/xmodule/tests/test_import.py index 21dd8968f6..e8a9719422 100644 --- a/common/lib/xmodule/xmodule/tests/test_import.py +++ b/common/lib/xmodule/xmodule/tests/test_import.py @@ -176,6 +176,33 @@ class ImportTestCase(unittest.TestCase): self.assertEqual(chapter_xml.tag, 'chapter') self.assertFalse('graceperiod' in chapter_xml.attrib) + def test_is_pointer_tag(self): + """ + Check that is_pointer_tag works properly. + """ + + yes = ["""""", + """""", + """ """, + """""", + """"""] + + no = ["""""", + """some text""", + """tree""", + """ + 3 + + """] + + for xml_str in yes: + print "should be True for {0}".format(xml_str) + self.assertTrue(is_pointer_tag(etree.fromstring(xml_str))) + + for xml_str in no: + print "should be False for {0}".format(xml_str) + self.assertFalse(is_pointer_tag(etree.fromstring(xml_str))) + def test_metadata_inherit(self): """Make sure that metadata is inherited properly""" @@ -311,3 +338,5 @@ class ImportTestCase(unittest.TestCase): system = self.get_system(False) self.assertRaises(etree.XMLSyntaxError, system.process_xml, bad_xml) + + diff --git a/common/lib/xmodule/xmodule/xml_module.py b/common/lib/xmodule/xmodule/xml_module.py index a5b3460f17..ec755af4ef 100644 --- a/common/lib/xmodule/xmodule/xml_module.py +++ b/common/lib/xmodule/xmodule/xml_module.py @@ -25,7 +25,7 @@ def name_to_pathname(name): def is_pointer_tag(xml_obj): """ Check if xml_obj is a pointer tag: . - No children, one attribute named url_name. + No children, one attribute named url_name, no text. Special case for course roots: the pointer is @@ -40,7 +40,10 @@ def is_pointer_tag(xml_obj): expected_attr = set(['url_name', 'course', 'org']) actual_attr = set(xml_obj.attrib.keys()) - return len(xml_obj) == 0 and actual_attr == expected_attr + + has_text = xml_obj.text is not None and len(xml_obj.text.strip()) > 0 + + return len(xml_obj) == 0 and actual_attr == expected_attr and not has_text def get_metadata_from_xml(xml_object, remove=True): meta = xml_object.find('meta')