Added command to delete split-mongo course
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
"""
|
||||
Django management command to rollback a migration to split. The way to do this
|
||||
is to delete the course from the split mongo datastore.
|
||||
"""
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from xmodule.modulestore.exceptions import ItemNotFoundError
|
||||
from xmodule.modulestore.locator import CourseLocator
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
"Delete a course from the split Mongo datastore"
|
||||
|
||||
help = "Delete a course from the split Mongo datastore"
|
||||
args = "locator"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
if len(args) < 1:
|
||||
raise CommandError(
|
||||
"delete_split_course requires at least one argument (locator)"
|
||||
)
|
||||
|
||||
try:
|
||||
locator = CourseLocator(url=args[0])
|
||||
except ValueError:
|
||||
raise CommandError("Invalid locator string {}".format(args[0]))
|
||||
|
||||
try:
|
||||
modulestore('split').delete_course(locator.package_id)
|
||||
except ItemNotFoundError:
|
||||
raise CommandError("No course found with locator {}".format(locator))
|
||||
@@ -0,0 +1,53 @@
|
||||
"""
|
||||
Unittests for deleting a split mongo course
|
||||
"""
|
||||
import unittest
|
||||
|
||||
from django.core.management import CommandError, call_command
|
||||
from django.test.utils import override_settings
|
||||
from contentstore.management.commands.delete_split_course import Command
|
||||
from contentstore.tests.modulestore_config import TEST_MODULESTORE
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.persistent_factories import PersistentCourseFactory
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from xmodule.modulestore.exceptions import ItemNotFoundError
|
||||
|
||||
|
||||
class TestArgParsing(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.command = Command()
|
||||
|
||||
def test_no_args(self):
|
||||
errstring = "delete_split_course requires at least one argument"
|
||||
with self.assertRaisesRegexp(CommandError, errstring):
|
||||
self.command.handle()
|
||||
|
||||
def test_invalid_locator(self):
|
||||
errstring = "Invalid locator string !?!"
|
||||
with self.assertRaisesRegexp(CommandError, errstring):
|
||||
self.command.handle("!?!")
|
||||
|
||||
def test_nonexistant_locator(self):
|
||||
errstring = "No course found with locator course/branch/name"
|
||||
with self.assertRaisesRegexp(CommandError, errstring):
|
||||
self.command.handle("course/branch/name")
|
||||
|
||||
|
||||
@override_settings(MODULESTORE=TEST_MODULESTORE)
|
||||
class TestDeleteSplitCourse(ModuleStoreTestCase):
|
||||
"""
|
||||
Unit tests for deleting a split-mongo course from command line
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super(TestDeleteSplitCourse, self).setUp()
|
||||
self.course = PersistentCourseFactory()
|
||||
|
||||
def test_happy_path(self):
|
||||
locator = self.course.location
|
||||
call_command(
|
||||
"delete_split_course",
|
||||
str(locator),
|
||||
)
|
||||
with self.assertRaises(ItemNotFoundError):
|
||||
modulestore('split').get_course(locator)
|
||||
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
Unittests for importing a course via management command
|
||||
Unittests for migrating a course to split mongo
|
||||
"""
|
||||
import unittest
|
||||
|
||||
|
||||
Reference in New Issue
Block a user