Commit 24d72883 by Kevin Falcone

Merge pull request #10684 from edx/jibsheet/force_publish-arg-parsing

Jibsheet/force publish arg parsing
parents c22d0de9 149df9b2
......@@ -17,39 +17,37 @@ class Command(BaseCommand):
help = '''
Force publish a course. Takes two arguments:
<course_id>: the course id of the course you want to publish forcefully
commit: do the force publish
--commit: do the force publish
If you do not specify 'commit', the command will print out what changes would be made.
If you do not specify '--commit', the command will print out what changes would be made.
'''
def add_arguments(self, parser):
parser.add_argument('course_key', help="ID of the Course to force publish")
parser.add_argument('--commit', action='store_true', help="Pull updated metadata from external IDPs")
def handle(self, *args, **options):
"""Execute the command"""
if len(args) not in {1, 2}:
raise CommandError("force_publish requires 1 or more argument: <course_id> |commit|")
try:
course_key = CourseKey.from_string(args[0])
course_key = CourseKey.from_string(options['course_key'])
except InvalidKeyError:
raise CommandError("Invalid course key.")
if not modulestore().get_course(course_key):
raise CommandError("Course not found.")
commit = False
if len(args) == 2:
commit = args[1] == 'commit'
# for now only support on split mongo
owning_store = modulestore()._get_modulestore_for_courselike(course_key) # pylint: disable=protected-access
if hasattr(owning_store, 'force_publish_course'):
versions = get_course_versions(args[0])
versions = get_course_versions(options['course_key'])
print "Course versions : {0}".format(versions)
if commit:
if options['commit']:
if query_yes_no("Are you sure to publish the {0} course forcefully?".format(course_key), default="no"):
# publish course forcefully
updated_versions = owning_store.force_publish_course(
course_key, ModuleStoreEnum.UserID.mgmt_command, commit
course_key, ModuleStoreEnum.UserID.mgmt_command, options['commit']
)
if updated_versions:
# if publish and draft were different
......
......@@ -2,7 +2,7 @@
Tests for the force_publish management command
"""
import mock
from django.core.management.base import CommandError
from django.core.management import call_command, CommandError
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
......@@ -25,9 +25,9 @@ class TestForcePublish(SharedModuleStoreTestCase):
"""
Test 'force_publish' command with no arguments
"""
errstring = "force_publish requires 1 or more argument: <course_id> |commit"
errstring = "Error: too few arguments"
with self.assertRaisesRegexp(CommandError, errstring):
self.command.handle()
call_command('force_publish')
def test_invalid_course_key(self):
"""
......@@ -35,15 +35,15 @@ class TestForcePublish(SharedModuleStoreTestCase):
"""
errstring = "Invalid course key."
with self.assertRaisesRegexp(CommandError, errstring):
self.command.handle('TestX/TS01')
call_command('force_publish', 'TestX/TS01')
def test_too_many_arguments(self):
"""
Test 'force_publish' command with more than 2 arguments
"""
errstring = "force_publish requires 1 or more argument: <course_id> |commit"
errstring = "Error: unrecognized arguments: invalid-arg"
with self.assertRaisesRegexp(CommandError, errstring):
self.command.handle(unicode(self.course.id), 'commit', 'invalid-arg')
call_command('force_publish', unicode(self.course.id), '--commit', 'invalid-arg')
def test_course_key_not_found(self):
"""
......@@ -51,7 +51,7 @@ class TestForcePublish(SharedModuleStoreTestCase):
"""
errstring = "Course not found."
with self.assertRaisesRegexp(CommandError, errstring):
self.command.handle(unicode('course-v1:org+course+run'))
call_command('force_publish', unicode('course-v1:org+course+run'))
def test_force_publish_non_split(self):
"""
......@@ -60,7 +60,7 @@ class TestForcePublish(SharedModuleStoreTestCase):
course = CourseFactory.create(default_store=ModuleStoreEnum.Type.mongo)
errstring = 'The owning modulestore does not support this command.'
with self.assertRaisesRegexp(CommandError, errstring):
self.command.handle(unicode(course.id))
call_command('force_publish', unicode(course.id))
@SharedModuleStoreTestCase.modifies_courseware
def test_force_publish(self):
......@@ -91,7 +91,7 @@ class TestForcePublish(SharedModuleStoreTestCase):
patched_yes_no.return_value = True
# force publish course
self.command.handle(unicode(self.course.id), 'commit')
call_command('force_publish', unicode(self.course.id), '--commit')
# verify that course has no changes
self.assertFalse(self.store.has_changes(self.store.get_item(self.course.location)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment