Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
f38ba3ce
Commit
f38ba3ce
authored
Nov 02, 2012
by
David Ormsbee
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1012 from MITx/bugfix/victor/xml-loading
Fix a bug with pointer-tag detection on load
parents
7595ab4a
55a0cada
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
2 deletions
+34
-2
common/lib/xmodule/xmodule/tests/test_import.py
+29
-0
common/lib/xmodule/xmodule/xml_module.py
+5
-2
No files found.
common/lib/xmodule/xmodule/tests/test_import.py
View file @
f38ba3ce
...
...
@@ -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
=
[
"""<html url_name="blah"/>"""
,
"""<html url_name="blah"></html>"""
,
"""<html url_name="blah"> </html>"""
,
"""<problem url_name="blah"/>"""
,
"""<course org="HogwartsX" course="Mathemagics" url_name="3.14159"/>"""
]
no
=
[
"""<html url_name="blah" also="this"/>"""
,
"""<html url_name="blah">some text</html>"""
,
"""<problem url_name="blah"><sub>tree</sub></problem>"""
,
"""<course org="HogwartsX" course="Mathemagics" url_name="3.14159">
<chapter>3</chapter>
</course>
"""
]
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
)
common/lib/xmodule/xmodule/xml_module.py
View file @
f38ba3ce
...
...
@@ -25,7 +25,7 @@ def name_to_pathname(name):
def
is_pointer_tag
(
xml_obj
):
"""
Check if xml_obj is a pointer tag: <blah url_name="something" />.
No children, one attribute named url_name.
No children, one attribute named url_name
, no text
.
Special case for course roots: the pointer is
<course url_name="something" org="myorg" course="course">
...
...
@@ -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'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment