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
25d6de24
Commit
25d6de24
authored
Aug 09, 2013
by
Chris Dodge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add portable link rewriting on clone. Added tests.
parent
36fda350
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
4 deletions
+59
-4
cms/djangoapps/contentstore/tests/test_contentstore.py
+51
-0
common/lib/xmodule/xmodule/modulestore/store_utilities.py
+8
-4
No files found.
cms/djangoapps/contentstore/tests/test_contentstore.py
View file @
25d6de24
...
...
@@ -644,6 +644,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
content_store
=
contentstore
()
# now do the actual cloning
clone_course
(
module_store
,
content_store
,
source_location
,
dest_location
)
# first assert that all draft content got cloned as well
...
...
@@ -693,6 +694,56 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
expected_children
.
append
(
child_loc
.
url
())
self
.
assertEqual
(
expected_children
,
lookup_item
.
children
)
def
test_portable_link_rewrites_during_clone_course
(
self
):
course_data
=
{
'org'
:
'MITx'
,
'number'
:
'999'
,
'display_name'
:
'Robot Super Course'
,
'run'
:
'2013_Spring'
}
module_store
=
modulestore
(
'direct'
)
draft_store
=
modulestore
(
'draft'
)
content_store
=
contentstore
()
import_from_xml
(
module_store
,
'common/test/data/'
,
[
'toy'
])
source_course_id
=
'edX/toy/2012_Fall'
dest_course_id
=
'MITx/999/2013_Spring'
source_location
=
CourseDescriptor
.
id_to_location
(
source_course_id
)
dest_location
=
CourseDescriptor
.
id_to_location
(
dest_course_id
)
# let's force a non-portable link in the clone source
# as a final check, make sure that any non-portable links are rewritten during cloning
html_module_location
=
Location
([
source_location
.
tag
,
source_location
.
org
,
source_location
.
course
,
'html'
,
'nonportable'
])
html_module
=
module_store
.
get_instance
(
source_location
.
course_id
,
html_module_location
)
self
.
assertTrue
(
isinstance
(
html_module
.
data
,
basestring
))
new_data
=
html_module
.
data
.
replace
(
'/static/'
,
'/c4x/{0}/{1}/asset/'
.
format
(
source_location
.
org
,
source_location
.
course
))
module_store
.
update_item
(
html_module_location
,
new_data
)
html_module
=
module_store
.
get_instance
(
source_location
.
course_id
,
html_module_location
)
self
.
assertEqual
(
new_data
,
html_module
.
data
)
# create the destination course
resp
=
self
.
client
.
post
(
reverse
(
'create_new_course'
),
course_data
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
data
=
parse_json
(
resp
)
self
.
assertEqual
(
data
[
'id'
],
'i4x://MITx/999/course/2013_Spring'
)
# do the actual cloning
clone_course
(
module_store
,
content_store
,
source_location
,
dest_location
)
# make sure that any non-portable links are rewritten during cloning
html_module_location
=
Location
([
dest_location
.
tag
,
dest_location
.
org
,
dest_location
.
course
,
'html'
,
'nonportable'
])
html_module
=
module_store
.
get_instance
(
dest_location
.
course_id
,
html_module_location
)
self
.
assertIn
(
'/static/foo.jpg'
,
html_module
.
data
)
def
test_illegal_draft_crud_ops
(
self
):
draft_store
=
modulestore
(
'draft'
)
direct_store
=
modulestore
(
'direct'
)
...
...
common/lib/xmodule/xmodule/modulestore/store_utilities.py
View file @
25d6de24
...
...
@@ -29,7 +29,7 @@ def convert_to_portable_links(source_course_id, text):
return
text
def
_clone_modules
(
modulestore
,
modules
,
dest_location
):
def
_clone_modules
(
modulestore
,
modules
,
source_location
,
dest_location
):
for
module
in
modules
:
original_loc
=
Location
(
module
.
location
)
...
...
@@ -44,7 +44,11 @@ def _clone_modules(modulestore, modules, dest_location):
print
"Cloning module {0} to {1}...."
.
format
(
original_loc
,
module
.
location
)
# NOTE: usage of the the internal module.xblock_kvs._data does not include any 'default' values for the fields
modulestore
.
update_item
(
module
.
location
,
module
.
xblock_kvs
.
_data
)
data
=
module
.
xblock_kvs
.
_data
if
isinstance
(
data
,
basestring
):
data
=
convert_to_portable_links
(
source_location
.
course_id
,
data
)
modulestore
.
update_item
(
module
.
location
,
data
)
# repoint children
if
module
.
has_children
:
...
...
@@ -96,10 +100,10 @@ def clone_course(modulestore, contentstore, source_location, dest_location, dele
# Get all modules under this namespace which is (tag, org, course) tuple
modules
=
modulestore
.
get_items
([
source_location
.
tag
,
source_location
.
org
,
source_location
.
course
,
None
,
None
,
None
])
_clone_modules
(
modulestore
,
modules
,
dest_location
)
_clone_modules
(
modulestore
,
modules
,
source_location
,
dest_location
)
modules
=
modulestore
.
get_items
([
source_location
.
tag
,
source_location
.
org
,
source_location
.
course
,
None
,
None
,
'draft'
])
_clone_modules
(
modulestore
,
modules
,
dest_location
)
_clone_modules
(
modulestore
,
modules
,
source_location
,
dest_location
)
# now iterate through all of the assets and clone them
# first the thumbnails
...
...
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