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
79e0bc25
Commit
79e0bc25
authored
Aug 06, 2012
by
Victor Shnayder
Committed by
Calen Pennington
Aug 07, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make url_names on error descriptors unique
parent
e6e290f5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
7 deletions
+31
-7
common/lib/xmodule/xmodule/error_module.py
+14
-3
common/lib/xmodule/xmodule/tests/test_import.py
+17
-4
No files found.
common/lib/xmodule/xmodule/error_module.py
View file @
79e0bc25
import
sys
import
logging
import
random
import
string
import
sys
from
pkg_resources
import
resource_string
from
lxml
import
etree
...
...
@@ -35,7 +37,8 @@ class ErrorDescriptor(EditingDescriptor):
error_msg
=
'Error not available'
):
'''Create an instance of this descriptor from the supplied data.
Does not try to parse the data--just stores it.
Does not require that xml_data be parseable--just stores it and exports
as-is if not.
Takes an extra, optional, parameter--the error that caused an
issue. (should be a string, or convert usefully into one).
...
...
@@ -45,6 +48,14 @@ class ErrorDescriptor(EditingDescriptor):
definition
=
{
'data'
:
inner
}
inner
[
'error_msg'
]
=
str
(
error_msg
)
# Pick a unique (random) url_name.
# NOTE: We could try to pull out the url_name of the errored descriptor,
# but url_names aren't guaranteed to be unique between descriptor types,
# and ErrorDescriptor can wrap any type. When the wrapped module is fixed,
# it will be written out with the original url_name.
chars
=
string
.
ascii_uppercase
+
string
.
ascii_lowercase
+
string
.
digits
url_name
=
''
.
join
(
random
.
choice
(
chars
)
for
i
in
range
(
16
))
try
:
# If this is already an error tag, don't want to re-wrap it.
xml_obj
=
etree
.
fromstring
(
xml_data
)
...
...
@@ -63,7 +74,7 @@ class ErrorDescriptor(EditingDescriptor):
inner
[
'contents'
]
=
xml_data
# TODO (vshnayder): Do we need a unique slug here? Just pick a random
# 64-bit num?
location
=
[
'i4x'
,
org
,
course
,
'error'
,
'slug'
]
location
=
[
'i4x'
,
org
,
course
,
'error'
,
url_name
]
metadata
=
{}
# stays in the xml_data
return
cls
(
system
,
definition
,
location
=
location
,
metadata
=
metadata
)
...
...
common/lib/xmodule/xmodule/tests/test_import.py
View file @
79e0bc25
...
...
@@ -47,8 +47,6 @@ class DummySystem(XMLParsingSystem):
raise
Exception
(
"Shouldn't be called"
)
class
ImportTestCase
(
unittest
.
TestCase
):
'''Make sure module imports work properly, including for malformed inputs'''
@staticmethod
...
...
@@ -57,10 +55,9 @@ class ImportTestCase(unittest.TestCase):
return
DummySystem
()
def
test_fallback
(
self
):
'''
Make sure
that malformed xml loads as an ErrorDescriptor.'''
'''
Check
that malformed xml loads as an ErrorDescriptor.'''
bad_xml
=
'''<sequential display_name="oops"><video url="hi"></sequential>'''
system
=
self
.
get_system
()
descriptor
=
XModuleDescriptor
.
load_from_xml
(
bad_xml
,
system
,
'org'
,
'course'
,
...
...
@@ -69,6 +66,22 @@ class ImportTestCase(unittest.TestCase):
self
.
assertEqual
(
descriptor
.
__class__
.
__name__
,
'ErrorDescriptor'
)
def
test_unique_url_names
(
self
):
'''Check that each error gets its very own url_name'''
bad_xml
=
'''<sequential display_name="oops"><video url="hi"></sequential>'''
bad_xml2
=
'''<sequential url_name="oops"><video url="hi"></sequential>'''
system
=
self
.
get_system
()
descriptor1
=
XModuleDescriptor
.
load_from_xml
(
bad_xml
,
system
,
'org'
,
'course'
,
None
)
descriptor2
=
XModuleDescriptor
.
load_from_xml
(
bad_xml2
,
system
,
'org'
,
'course'
,
None
)
self
.
assertNotEqual
(
descriptor1
.
location
,
descriptor2
.
location
)
def
test_reimport
(
self
):
'''Make sure an already-exported error xml tag loads properly'''
...
...
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