Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
79e0bc25
Commit
79e0bc25
authored
12 years ago
by
Victor Shnayder
Committed by
Calen Pennington
12 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Make url_names on error descriptors unique
parent
e6e290f5
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
common/lib/xmodule/xmodule/error_module.py
+14
-3
14 additions, 3 deletions
common/lib/xmodule/xmodule/error_module.py
common/lib/xmodule/xmodule/tests/test_import.py
+17
-4
17 additions, 4 deletions
common/lib/xmodule/xmodule/tests/test_import.py
with
31 additions
and
7 deletions
common/lib/xmodule/xmodule/error_module.py
+
14
−
3
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
)
...
...
This diff is collapsed.
Click to expand it.
common/lib/xmodule/xmodule/tests/test_import.py
+
17
−
4
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
'''
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment