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
8c9a7d3a
Commit
8c9a7d3a
authored
Aug 01, 2012
by
Victor Shnayder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add metadata inherit test
* also make a placeholder roundtrip export test
parent
d8b7ce94
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
15 deletions
+76
-15
common/lib/xmodule/tests/test_export.py
+8
-0
common/lib/xmodule/tests/test_import.py
+68
-15
No files found.
common/lib/xmodule/tests/test_export.py
View file @
8c9a7d3a
from
xmodule.modulestore.xml
import
XMLModuleStore
from
nose.tools
import
assert_equals
from
nose
import
SkipTest
from
tempfile
import
mkdtemp
from
fs.osfs
import
OSFS
...
...
@@ -26,3 +27,10 @@ def check_export_roundtrip(data_dir):
for
location
in
initial_import
.
modules
.
keys
():
print
"Checking"
,
location
assert_equals
(
initial_import
.
modules
[
location
],
second_import
.
modules
[
location
])
def
test_toy_roundtrip
():
dir
=
""
# TODO: add paths and make this run.
raise
SkipTest
()
check_export_roundtrip
(
dir
)
common/lib/xmodule/tests/test_import.py
View file @
8c9a7d3a
from
path
import
path
import
unittest
from
fs.memoryfs
import
MemoryFS
from
lxml
import
etree
from
xmodule.x_module
import
XMLParsingSystem
,
XModuleDescriptor
from
xmodule.errortracker
import
null
_error_tracker
from
xmodule.errortracker
import
make
_error_tracker
from
xmodule.modulestore
import
Location
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
class
ImportTestCase
(
unittest
.
TestCase
):
'''Make sure module imports work properly, including for malformed inputs'''
ORG
=
'test_org'
COURSE
=
'test_course'
class
DummySystem
(
XMLParsingSystem
):
def
__init__
(
self
):
self
.
modules
=
{}
self
.
resources_fs
=
MemoryFS
()
self
.
errorlog
=
make_error_tracker
()
@staticmethod
def
get_system
():
'''Get a dummy system'''
# Shouldn't need any system params, because the initial parse should fail
def
load_item
(
loc
):
raise
Exception
(
"Shouldn't be called"
)
loc
=
Location
(
loc
)
if
loc
in
self
.
modules
:
return
self
.
modules
[
loc
]
resources_fs
=
None
print
"modules: "
print
self
.
modules
raise
ItemNotFoundError
(
"Can't find item at loc: {0}"
.
format
(
loc
))
def
process_xml
(
xml
):
raise
Exception
(
"Shouldn't be called"
)
print
"loading {0}"
.
format
(
xml
)
descriptor
=
XModuleDescriptor
.
load_from_xml
(
xml
,
self
,
ORG
,
COURSE
,
None
)
# Need to save module so we can find it later
self
.
modules
[
descriptor
.
location
]
=
descriptor
# always eager
descriptor
.
get_children
()
return
descriptor
XMLParsingSystem
.
__init__
(
self
,
load_item
,
self
.
resources_fs
,
self
.
errorlog
.
tracker
,
process_xml
)
def
render_template
(
template
,
context
):
def
render_template
(
self
,
template
,
context
):
raise
Exception
(
"Shouldn't be called"
)
system
=
XMLParsingSystem
(
load_item
,
resources_fs
,
null_error_tracker
,
process_xml
)
system
.
render_template
=
render_template
return
system
class
ImportTestCase
(
unittest
.
TestCase
):
'''Make sure module imports work properly, including for malformed inputs'''
@staticmethod
def
get_system
():
'''Get a dummy system'''
return
DummySystem
()
def
test_fallback
(
self
):
'''Make sure that malformed xml loads as an ErrorDescriptor.'''
...
...
@@ -85,3 +110,31 @@ class ImportTestCase(unittest.TestCase):
xml_out
=
etree
.
fromstring
(
xml_str_out
)
self
.
assertEqual
(
xml_out
.
tag
,
'sequential'
)
def
test_metadata_inherit
(
self
):
"""Make sure metadata inherits properly"""
system
=
self
.
get_system
()
v
=
"1 hour"
start_xml
=
'''<course graceperiod="{grace}" url_name="test1" display_name="myseq">
<chapter url="hi" url_name="ch" display_name="CH">
<html url_name="h" display_name="H">Two houses, ...</html></chapter>
</course>'''
.
format
(
grace
=
v
)
descriptor
=
XModuleDescriptor
.
load_from_xml
(
start_xml
,
system
,
'org'
,
'course'
)
print
"Errors: {0}"
.
format
(
system
.
errorlog
.
errors
)
print
descriptor
,
descriptor
.
metadata
self
.
assertEqual
(
descriptor
.
metadata
[
'graceperiod'
],
v
)
# Check that the child inherits correctly
child
=
descriptor
.
get_children
()[
0
]
self
.
assertEqual
(
child
.
metadata
[
'graceperiod'
],
v
)
# Now export and see if the chapter tag has a graceperiod attribute
resource_fs
=
MemoryFS
()
exported_xml
=
descriptor
.
export_to_xml
(
resource_fs
)
print
"Exported xml:"
,
exported_xml
root
=
etree
.
fromstring
(
exported_xml
)
chapter_tag
=
root
[
0
]
self
.
assertEqual
(
chapter_tag
.
tag
,
'chapter'
)
self
.
assertFalse
(
'graceperiod'
in
chapter_tag
.
attrib
)
self
.
assertTrue
(
False
)
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