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
78a8fd80
Commit
78a8fd80
authored
Feb 06, 2015
by
cahrens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
If existing course is found on import, make sure dest_course_id is correct.
TNL-1362
parent
149c4e78
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
2 deletions
+30
-2
cms/djangoapps/contentstore/management/commands/tests/test_import.py
+22
-1
common/lib/xmodule/xmodule/modulestore/xml_importer.py
+8
-1
No files found.
cms/djangoapps/contentstore/management/commands/tests/test_import.py
View file @
78a8fd80
...
...
@@ -11,6 +11,7 @@ from django.core.management import call_command
from
django_comment_common.utils
import
are_permissions_roles_seeded
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore
import
ModuleStoreEnum
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
...
...
@@ -27,7 +28,7 @@ class TestImport(ModuleStoreTestCase):
'course="{0.course}"/>'
.
format
(
course_id
))
with
open
(
os
.
path
.
join
(
directory
,
"course"
,
"{0.run}.xml"
.
format
(
course_id
)),
"w+"
)
as
f
:
f
.
write
(
'<course></course>'
)
f
.
write
(
'<course><
chapter name="Test Chapter"></chapter><
/course>'
)
return
directory
...
...
@@ -72,3 +73,23 @@ class TestImport(ModuleStoreTestCase):
# Now load up the course with a similar course_id and verify it loads
call_command
(
'import'
,
self
.
content_dir
,
self
.
course_dir
)
self
.
assertIsNotNone
(
store
.
get_course
(
self
.
truncated_key
))
def
test_existing_course_with_different_modulestore
(
self
):
"""
Checks that a course that originally existed in old mongo can be re-imported when
split is the default modulestore.
"""
with
modulestore
()
.
default_store
(
ModuleStoreEnum
.
Type
.
mongo
):
call_command
(
'import'
,
self
.
content_dir
,
self
.
good_dir
)
# Clear out the modulestore mappings, else when the next import command goes to create a destination
# course_key, it will find the existing course and return the mongo course_key. To reproduce TNL-1362,
# the destination course_key needs to be the one for split modulestore.
modulestore
()
.
mappings
=
{}
with
modulestore
()
.
default_store
(
ModuleStoreEnum
.
Type
.
split
):
call_command
(
'import'
,
self
.
content_dir
,
self
.
good_dir
)
course
=
modulestore
()
.
get_course
(
self
.
base_course_key
)
# With the bug, this fails because the chapter's course_key is the split mongo form,
# while the course's course_key is the old mongo form.
self
.
assertEqual
(
unicode
(
course
.
location
.
course_key
),
unicode
(
course
.
children
[
0
]
.
course_key
))
common/lib/xmodule/xmodule/modulestore/xml_importer.py
View file @
78a8fd80
...
...
@@ -195,11 +195,18 @@ def import_from_xml(
if
target_course_id
is
not
None
:
dest_course_id
=
target_course_id
else
:
# Note that dest_course_id will be in the format for the default modulestore.
dest_course_id
=
store
.
make_course_key
(
course_key
.
org
,
course_key
.
course
,
course_key
.
run
)
existing_course_id
=
store
.
has_course
(
dest_course_id
,
ignore_case
=
True
)
# store.has_course will return the course_key in the format for the modulestore in which it was found.
# This may be different from dest_course_id, so correct to the format found.
if
existing_course_id
:
dest_course_id
=
existing_course_id
runtime
=
None
# Creates a new course if it doesn't already exist
if
create_course_if_not_present
and
not
store
.
has_course
(
dest_course_id
,
ignore_case
=
True
)
:
if
create_course_if_not_present
and
not
existing_course_id
:
try
:
new_course
=
store
.
create_course
(
dest_course_id
.
org
,
dest_course_id
.
course
,
dest_course_id
.
run
,
user_id
)
runtime
=
new_course
.
runtime
...
...
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