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
789a15ae
Commit
789a15ae
authored
Oct 29, 2014
by
Matt Drayer
Committed by
Jonathan Piacenti
Aug 20, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mattdrayer/api-cmc-stage-fix: Strip i4x prefix from stage column values
parent
8e443f59
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
0 deletions
+75
-0
lms/djangoapps/api_manager/management/commands/migrate_stage_prefix.py
+25
-0
lms/djangoapps/api_manager/management/commands/tests/test_migrate_stage_prefix.py
+50
-0
No files found.
lms/djangoapps/api_manager/management/commands/migrate_stage_prefix.py
0 → 100644
View file @
789a15ae
"""
One-time data migration script -- shouldn't need to run it again
"""
import
logging
from
django.core.management.base
import
BaseCommand
from
api_manager
import
models
as
api_models
log
=
logging
.
getLogger
(
__name__
)
class
Command
(
BaseCommand
):
"""
Migrates legacy course/content identifiers across several models to the new format
"""
def
handle
(
self
,
*
args
,
**
options
):
log
.
warning
(
'Migrating Course Module Completions Stage Field...'
)
course_module_completions
=
api_models
.
CourseModuleCompletion
.
objects
.
all
()
for
cmc
in
course_module_completions
:
if
cmc
.
stage
is
not
None
:
cmc
.
stage
=
cmc
.
stage
.
replace
(
"i4x://"
,
""
)
cmc
.
save
()
log
.
warning
(
'Complete!'
)
lms/djangoapps/api_manager/management/commands/tests/test_migrate_stage_prefix.py
0 → 100644
View file @
789a15ae
"""
Run these tests @ Devstack:
rake fasttest_lms[common/djangoapps/api_manager/management/commands/tests/test_migrate_orgdata.py]
"""
from
django.contrib.auth.models
import
User
from
api_manager
import
models
as
api_models
from
api_manager.management.commands
import
migrate_stage_prefix
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
class
MigrateCourseIdsTests
(
ModuleStoreTestCase
):
"""
Test suite for data migration script
"""
def
setUp
(
self
):
self
.
good_style_course_id
=
"old/style/id"
self
.
good_style_content_id
=
"i4x://old/style/chapter/1234567890"
self
.
bad_style_stage
=
'i4x://evaluation'
self
.
good_style_stage
=
'evaluation'
self
.
good_style_course_id2
=
"old2/style2/id2"
self
.
good_style_content_id2
=
"i4x://old2/style2/chapter2/1234567890"
self
.
bad_style_stage2
=
'i4x://upload'
self
.
good_style_stage2
=
'upload'
def
test_migrate_stage_prefix
(
self
):
"""
Test the data migration
"""
# Set up the data to be migrated
user
=
User
.
objects
.
create
(
email
=
'testuser@edx.org'
,
username
=
'testuser'
,
password
=
'testpassword'
,
is_active
=
True
)
course_module_completion
=
api_models
.
CourseModuleCompletion
.
objects
.
create
(
user
=
user
,
course_id
=
self
.
good_style_course_id
,
content_id
=
self
.
good_style_content_id
,
stage
=
self
.
bad_style_stage
)
user2
=
User
.
objects
.
create
(
email
=
'testuser2@edx.org'
,
username
=
'testuser2'
,
password
=
'testpassword2'
,
is_active
=
True
)
course_module_completion2
=
api_models
.
CourseModuleCompletion
.
objects
.
create
(
user
=
user2
,
course_id
=
self
.
good_style_course_id2
,
content_id
=
self
.
good_style_content_id2
,
stage
=
self
.
bad_style_stage2
)
# Run the data migration
migrate_stage_prefix
.
Command
()
.
handle
()
updated_course_module_completion
=
api_models
.
CourseModuleCompletion
.
objects
.
get
(
id
=
course_module_completion
.
id
)
self
.
assertEqual
(
updated_course_module_completion
.
stage
,
self
.
good_style_stage
)
updated_course_module_completion
=
api_models
.
CourseModuleCompletion
.
objects
.
get
(
id
=
course_module_completion2
.
id
)
self
.
assertEqual
(
updated_course_module_completion
.
stage
,
self
.
good_style_stage2
)
print
"Course Module Completion Data Migration Passed"
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