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
c3b8d52d
Commit
c3b8d52d
authored
Jan 28, 2014
by
David Baumgold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move user-finding logic out of command
parent
096088cc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
21 deletions
+32
-21
cms/djangoapps/contentstore/management/commands/migrate_to_split.py
+18
-17
cms/djangoapps/contentstore/management/commands/tests/test_migrate_to_split.py
+14
-4
No files found.
cms/djangoapps/contentstore/management/commands/migrate_to_split.py
View file @
c3b8d52d
...
...
@@ -11,6 +11,21 @@ from xmodule.modulestore import InvalidLocationError
from
xmodule.modulestore.django
import
loc_mapper
def
user_from_str
(
s
):
"""
Return a user identified by the given string. The string could be an email
address, or a stringified integer corresponding to the ID of the user in
the database. If no user could be found, a User.DoesNotExist exception
will be raised.
"""
try
:
user_id
=
int
(
s
)
except
ValueError
:
return
User
.
objects
.
get
(
email
=
s
)
else
:
return
User
.
objects
.
get
(
id
=
user_id
)
class
Command
(
BaseCommand
):
help
=
"Migrate a course from old-Mongo to split-Mongo"
args
=
"location email <locator>"
...
...
@@ -32,24 +47,10 @@ class Command(BaseCommand):
except
InvalidLocationError
:
raise
CommandError
(
"Invalid location string {}"
.
format
(
args
[
0
]))
user_id
=
None
email
=
None
try
:
user_id
=
int
(
args
[
1
])
except
ValueError
:
email
=
args
[
1
]
if
user_id
:
try
:
user
=
User
.
objects
.
get
(
pk
=
user_id
)
except
User
.
DoesNotExist
:
raise
CommandError
(
"No user exists with ID {}"
.
format
(
user_id
))
else
:
try
:
user
=
User
.
objects
.
get
(
email
=
email
)
except
User
.
DoesNotExist
:
raise
CommandError
(
"No user exists with email {}"
.
format
(
email
))
assert
user
,
"User doesn't exist! That shouldn't happen..."
user
=
user_from_str
(
args
[
1
])
except
User
.
DoesNotExist
:
raise
CommandError
(
"No user found identified by {}"
.
format
(
args
[
1
]))
try
:
locator_string
=
args
[
2
]
...
...
cms/djangoapps/contentstore/management/commands/tests/test_migrate_to_split.py
View file @
c3b8d52d
...
...
@@ -29,12 +29,12 @@ class TestArgParsing(unittest.TestCase):
self
.
command
.
handle
(
"foo"
,
"bar"
)
def
test_nonexistant_user_id
(
self
):
errstring
=
"No user
exists with ID
99"
errstring
=
"No user
found identified by
99"
with
self
.
assertRaisesRegexp
(
CommandError
,
errstring
):
self
.
command
.
handle
(
"i4x://org/course/category/name"
,
"99"
)
def
test_nonexistant_user_email
(
self
):
errstring
=
"No user
exists with email
fake@example.com"
errstring
=
"No user
found identified by
fake@example.com"
with
self
.
assertRaisesRegexp
(
CommandError
,
errstring
):
self
.
command
.
handle
(
"i4x://org/course/category/name"
,
"fake@example.com"
)
...
...
@@ -53,11 +53,21 @@ class TestMigrateToSplit(ModuleStoreTestCase):
self
.
user
=
User
.
objects
.
create_user
(
uname
,
email
,
password
)
self
.
course
=
CourseFactory
()
def
test_happy_path
(
self
):
def
test_happy_path
_email
(
self
):
call_command
(
"migrate_to_split"
,
str
(
self
.
course
.
location
),
self
.
user
.
email
,
str
(
self
.
user
.
email
),
)
locator
=
loc_mapper
()
.
translate_location
(
self
.
course
.
id
,
self
.
course
.
location
)
course_from_split
=
modulestore
(
'split'
)
.
get_course
(
locator
)
self
.
assertIsNotNone
(
course_from_split
)
def
test_happy_path_user_id
(
self
):
call_command
(
"migrate_to_split"
,
str
(
self
.
course
.
location
),
str
(
self
.
user
.
id
),
)
locator
=
loc_mapper
()
.
translate_location
(
self
.
course
.
id
,
self
.
course
.
location
)
course_from_split
=
modulestore
(
'split'
)
.
get_course
(
locator
)
...
...
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