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
e2b02137
Commit
e2b02137
authored
Dec 10, 2015
by
Feanil Patel
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10927 from edx/feanil/fix_delete_command
Fix the delete course management command.
parents
493defa3
a4006c86
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
87 deletions
+20
-87
cms/djangoapps/contentstore/management/commands/delete_course.py
+9
-22
cms/djangoapps/contentstore/management/commands/tests/test_delete_course.py
+11
-65
No files found.
cms/djangoapps/contentstore/management/commands/delete_course.py
View file @
e2b02137
...
...
@@ -24,32 +24,19 @@ class Command(BaseCommand):
"""
help
=
'''Delete a MongoDB backed course'''
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'course_key'
,
help
=
"ID of the course to delete."
)
def
handle
(
self
,
*
args
,
**
options
):
if
len
(
args
)
==
0
:
raise
CommandError
(
"Arguments missing: 'org/number/run commit'"
)
if
len
(
args
)
==
1
:
if
args
[
0
]
==
'commit'
:
raise
CommandError
(
"Delete_course requires a course_key <org/number/run> argument."
)
else
:
raise
CommandError
(
"Delete_course requires a commit argument at the end"
)
elif
len
(
args
)
==
2
:
try
:
course_key
=
CourseKey
.
from_string
(
args
[
0
])
except
InvalidKeyError
:
try
:
course_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
args
[
0
])
except
InvalidKeyError
:
raise
CommandError
(
"Invalid course_key: '
%
s'. Proper syntax: 'org/number/run commit' "
%
args
[
0
])
if
args
[
1
]
!=
'commit'
:
raise
CommandError
(
"Delete_course requires a commit argument at the end"
)
elif
len
(
args
)
>
2
:
raise
CommandError
(
"Too many arguments! Expected <course_key> <commit>"
)
try
:
course_key
=
CourseKey
.
from_string
(
options
[
'course_key'
])
except
InvalidKeyError
:
raise
CommandError
(
"Invalid course_key: '
%
s'."
%
options
[
'course_key'
])
if
not
modulestore
()
.
get_course
(
course_key
):
raise
CommandError
(
"Course with '
%
s' key not found."
%
args
[
0
])
raise
CommandError
(
"Course with '
%
s' key not found."
%
options
[
'course_key'
])
print
'
Actually going to delete the
%
s course from DB....'
%
args
[
0
]
print
'
Going to delete the
%
s course from DB....'
%
options
[
'course_key'
]
if
query_yes_no
(
"Deleting course {0}. Confirm?"
.
format
(
course_key
),
default
=
"no"
):
if
query_yes_no
(
"Are you sure. This action cannot be undone!"
,
default
=
"no"
):
delete_course_and_groups
(
course_key
,
ModuleStoreEnum
.
UserID
.
mgmt_command
)
...
...
cms/djangoapps/contentstore/management/commands/tests/test_delete_course.py
View file @
e2b02137
...
...
@@ -6,72 +6,12 @@ import unittest
import
mock
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
from
django.core.management
import
CommandError
from
contentstore.management.commands.delete_course
import
Command
from
django.core.management
import
call_command
,
CommandError
from
contentstore.tests.utils
import
CourseTestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
from
xmodule.modulestore.django
import
modulestore
class
TestArgParsing
(
unittest
.
TestCase
):
"""
Tests for parsing arguments for the 'delete_course' management command
"""
def
setUp
(
self
):
super
(
TestArgParsing
,
self
)
.
setUp
()
self
.
command
=
Command
()
def
test_no_args
(
self
):
"""
Testing 'delete_course' command with no arguments provided
"""
errstring
=
"Arguments missing: 'org/number/run commit'"
with
self
.
assertRaisesRegexp
(
CommandError
,
errstring
):
self
.
command
.
handle
()
def
test_no_course_key
(
self
):
"""
Testing 'delete_course' command with no course key provided
"""
errstring
=
"Delete_course requires a course_key <org/number/run> argument."
with
self
.
assertRaisesRegexp
(
CommandError
,
errstring
):
self
.
command
.
handle
(
"commit"
)
def
test_commit_argument
(
self
):
"""
Testing 'delete_course' command without 'commit' argument
"""
errstring
=
"Delete_course requires a commit argument at the end"
with
self
.
assertRaisesRegexp
(
CommandError
,
errstring
):
self
.
command
.
handle
(
"TestX/TS01/run"
)
def
test_invalid_course_key
(
self
):
"""
Testing 'delete_course' command with an invalid course key argument
"""
errstring
=
"Invalid course_key: 'TestX/TS01'. Proper syntax: 'org/number/run commit' "
with
self
.
assertRaisesRegexp
(
CommandError
,
errstring
):
self
.
command
.
handle
(
"TestX/TS01"
,
"commit"
)
def
test_missing_commit_argument
(
self
):
"""
Testing 'delete_course' command with misspelled 'commit' argument
"""
errstring
=
"Delete_course requires a commit argument at the end"
with
self
.
assertRaisesRegexp
(
CommandError
,
errstring
):
self
.
command
.
handle
(
"TestX/TS01/run"
,
"comit"
)
def
test_too_many_arguments
(
self
):
"""
Testing 'delete_course' command with more than 2 arguments
"""
errstring
=
"Too many arguments! Expected <course_key> <commit>"
with
self
.
assertRaisesRegexp
(
CommandError
,
errstring
):
self
.
command
.
handle
(
"TestX/TS01/run"
,
"commit"
,
"invalid"
)
class
DeleteCourseTest
(
CourseTestCase
):
"""
Test for course deleting functionality of the 'delete_course' command
...
...
@@ -82,8 +22,6 @@ class DeleteCourseTest(CourseTestCase):
def
setUp
(
self
):
super
(
DeleteCourseTest
,
self
)
.
setUp
()
self
.
command
=
Command
()
org
=
'TestX'
course_number
=
'TS01'
course_run
=
'2015_Q1'
...
...
@@ -95,13 +33,21 @@ class DeleteCourseTest(CourseTestCase):
run
=
course_run
)
def
test_invalid_key_not_found
(
self
):
"""
Test for when a course key is malformed
"""
errstring
=
"Invalid course_key: 'foo/TestX/TS01/2015_Q7'."
with
self
.
assertRaisesRegexp
(
CommandError
,
errstring
):
call_command
(
'delete_course'
,
'foo/TestX/TS01/2015_Q7'
)
def
test_course_key_not_found
(
self
):
"""
Test for when a non-existing course key is entered
"""
errstring
=
"Course with 'TestX/TS01/2015_Q7' key not found."
with
self
.
assertRaisesRegexp
(
CommandError
,
errstring
):
self
.
command
.
handle
(
'TestX/TS01/2015_Q7'
,
"commit"
)
call_command
(
'delete_course'
,
'TestX/TS01/2015_Q7'
)
def
test_course_deleted
(
self
):
"""
...
...
@@ -113,5 +59,5 @@ class DeleteCourseTest(CourseTestCase):
with
mock
.
patch
(
self
.
YESNO_PATCH_LOCATION
)
as
patched_yes_no
:
patched_yes_no
.
return_value
=
True
self
.
command
.
handle
(
'TestX/TS01/2015_Q1'
,
"commit"
)
call_command
(
'delete_course'
,
'TestX/TS01/2015_Q1'
)
self
.
assertIsNone
(
modulestore
()
.
get_course
(
SlashSeparatedCourseKey
(
"TestX"
,
"TS01"
,
"2015_Q1"
)))
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