Merge pull request #17936 from edx/ibrahimahmed443/WL-1519-duplicate-course-fix
catch duplicate course error
This commit is contained in:
@@ -10,6 +10,7 @@ from django.core.management.base import BaseCommand, CommandError
|
||||
from contentstore.management.commands.utils import user_from_str
|
||||
from contentstore.views.course import create_new_course_in_store
|
||||
from xmodule.modulestore import ModuleStoreEnum
|
||||
from xmodule.modulestore.exceptions import DuplicateCourseError
|
||||
|
||||
|
||||
MODULESTORE_CHOICES = (ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
|
||||
@@ -75,12 +76,16 @@ class Command(BaseCommand):
|
||||
}
|
||||
if name:
|
||||
fields["display_name"] = name
|
||||
new_course = create_new_course_in_store(
|
||||
storetype,
|
||||
user,
|
||||
org,
|
||||
number,
|
||||
run,
|
||||
fields
|
||||
)
|
||||
self.stdout.write(u"Created {}".format(text_type(new_course.id)))
|
||||
|
||||
try:
|
||||
new_course = create_new_course_in_store(
|
||||
storetype,
|
||||
user,
|
||||
org,
|
||||
number,
|
||||
run,
|
||||
fields
|
||||
)
|
||||
self.stdout.write(u"Created {}".format(text_type(new_course.id)))
|
||||
except DuplicateCourseError:
|
||||
self.stdout.write(u"Course already exists")
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
Unittests for creating a course in an chosen modulestore
|
||||
"""
|
||||
from StringIO import StringIO
|
||||
import ddt
|
||||
from django.core.management import CommandError, call_command
|
||||
from django.test import TestCase
|
||||
@@ -59,6 +60,29 @@ class TestCreateCourse(ModuleStoreTestCase):
|
||||
# pylint: disable=protected-access
|
||||
self.assertEqual(store, modulestore()._get_modulestore_for_courselike(new_key).get_modulestore_type())
|
||||
|
||||
def test_duplicate_course(self):
|
||||
"""
|
||||
Test that creating a duplicate course exception is properly handled
|
||||
"""
|
||||
call_command(
|
||||
"create_course",
|
||||
"split",
|
||||
str(self.user.email),
|
||||
"org", "course", "run", "dummy-course-name"
|
||||
)
|
||||
|
||||
# create the course again
|
||||
out = StringIO()
|
||||
call_command(
|
||||
"create_course",
|
||||
"split",
|
||||
str(self.user.email),
|
||||
"org", "course", "run", "dummy-course-name",
|
||||
stderr=out
|
||||
)
|
||||
expected = u"Course already exists"
|
||||
self.assertIn(out.getvalue().strip(), expected)
|
||||
|
||||
@ddt.data(ModuleStoreEnum.Type.split, ModuleStoreEnum.Type.mongo)
|
||||
def test_get_course_with_different_case(self, default_store):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user