Fix up tests to support updated management commands
This commit is contained in:
@@ -5,7 +5,6 @@ import ddt
|
||||
from django.core.management import CommandError, call_command
|
||||
from django.test import TestCase
|
||||
|
||||
from contentstore.management.commands.create_course import Command
|
||||
from xmodule.modulestore import ModuleStoreEnum
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.django import modulestore
|
||||
@@ -18,26 +17,24 @@ class TestArgParsing(TestCase):
|
||||
def setUp(self):
|
||||
super(TestArgParsing, self).setUp()
|
||||
|
||||
self.command = Command()
|
||||
|
||||
def test_no_args(self):
|
||||
errstring = "create_course requires 5 arguments"
|
||||
errstring = "Error: too few arguments"
|
||||
with self.assertRaisesRegexp(CommandError, errstring):
|
||||
self.command.handle('create_course')
|
||||
call_command('create_course')
|
||||
|
||||
def test_invalid_store(self):
|
||||
with self.assertRaises(CommandError):
|
||||
self.command.handle("foo", "user@foo.org", "org", "course", "run")
|
||||
call_command('create_course', "foo", "user@foo.org", "org", "course", "run")
|
||||
|
||||
def test_nonexistent_user_id(self):
|
||||
errstring = "No user 99 found"
|
||||
with self.assertRaisesRegexp(CommandError, errstring):
|
||||
self.command.handle("split", "99", "org", "course", "run")
|
||||
call_command('create_course', "split", "99", "org", "course", "run")
|
||||
|
||||
def test_nonexistent_user_email(self):
|
||||
errstring = "No user fake@example.com found"
|
||||
with self.assertRaisesRegexp(CommandError, errstring):
|
||||
self.command.handle("mongo", "fake@example.com", "org", "course", "run")
|
||||
call_command('create_course', "mongo", "fake@example.com", "org", "course", "run")
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
|
||||
@@ -56,10 +56,10 @@ class TestGitExport(CourseTestCase):
|
||||
Test that the command interface works. Ignore stderr for clean
|
||||
test output.
|
||||
"""
|
||||
with self.assertRaisesRegexp(CommandError, 'This script requires.*'):
|
||||
with self.assertRaisesRegexp(CommandError, 'Error: unrecognized arguments:*'):
|
||||
call_command('git_export', 'blah', 'blah', 'blah', stderr=StringIO.StringIO())
|
||||
|
||||
with self.assertRaisesRegexp(CommandError, 'This script requires.*'):
|
||||
with self.assertRaisesMessage(CommandError, 'Error: too few arguments'):
|
||||
call_command('git_export', stderr=StringIO.StringIO())
|
||||
|
||||
# Send bad url to get course not exported
|
||||
|
||||
@@ -3,7 +3,6 @@ Unittests for migrating a course to split mongo
|
||||
"""
|
||||
from django.core.management import CommandError, call_command
|
||||
from django.test import TestCase
|
||||
from contentstore.management.commands.migrate_to_split import Command
|
||||
from xmodule.modulestore import ModuleStoreEnum
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
@@ -17,15 +16,14 @@ class TestArgParsing(TestCase):
|
||||
"""
|
||||
def setUp(self):
|
||||
super(TestArgParsing, self).setUp()
|
||||
self.command = Command()
|
||||
|
||||
def test_no_args(self):
|
||||
"""
|
||||
Test the arg length error
|
||||
"""
|
||||
errstring = "migrate_to_split requires at least two arguments"
|
||||
errstring = "Error: too few arguments"
|
||||
with self.assertRaisesRegexp(CommandError, errstring):
|
||||
self.command.handle()
|
||||
call_command("migrate_to_split")
|
||||
|
||||
def test_invalid_location(self):
|
||||
"""
|
||||
@@ -33,7 +31,7 @@ class TestArgParsing(TestCase):
|
||||
"""
|
||||
errstring = "Invalid location string"
|
||||
with self.assertRaisesRegexp(CommandError, errstring):
|
||||
self.command.handle("foo", "bar")
|
||||
call_command("migrate_to_split", "foo", "bar")
|
||||
|
||||
def test_nonexistent_user_id(self):
|
||||
"""
|
||||
@@ -41,7 +39,7 @@ class TestArgParsing(TestCase):
|
||||
"""
|
||||
errstring = "No user found identified by 99"
|
||||
with self.assertRaisesRegexp(CommandError, errstring):
|
||||
self.command.handle("org/course/name", "99")
|
||||
call_command("migrate_to_split", "org/course/name", "99")
|
||||
|
||||
def test_nonexistent_user_email(self):
|
||||
"""
|
||||
@@ -49,7 +47,7 @@ class TestArgParsing(TestCase):
|
||||
"""
|
||||
errstring = "No user found identified by fake@example.com"
|
||||
with self.assertRaisesRegexp(CommandError, errstring):
|
||||
self.command.handle("org/course/name", "fake@example.com")
|
||||
call_command("migrate_to_split", "org/course/name", "fake@example.com")
|
||||
|
||||
|
||||
# pylint: disable=no-member, protected-access
|
||||
@@ -77,13 +75,6 @@ class TestMigrateToSplit(ModuleStoreTestCase):
|
||||
split_store.has_course(new_key),
|
||||
"Could not find course"
|
||||
)
|
||||
# I put this in but realized that the migrator doesn't make the new course the
|
||||
# default mapping in mixed modulestore. I left the test here so we can debate what it ought to do.
|
||||
# self.assertEqual(
|
||||
# ModuleStoreEnum.Type.split,
|
||||
# modulestore()._get_modulestore_for_courselike(new_key).get_modulestore_type(),
|
||||
# "Split is not the new default for the course"
|
||||
# )
|
||||
|
||||
def test_user_id(self):
|
||||
"""
|
||||
@@ -104,7 +95,9 @@ class TestMigrateToSplit(ModuleStoreTestCase):
|
||||
"migrate_to_split",
|
||||
str(self.course.id),
|
||||
str(self.user.id),
|
||||
"org.dept", "name", "run",
|
||||
org="org.dept",
|
||||
course="name",
|
||||
run="run",
|
||||
)
|
||||
split_store = modulestore()._get_modulestore_by_type(ModuleStoreEnum.Type.split)
|
||||
locator = split_store.make_course_key("org.dept", "name", "run")
|
||||
|
||||
@@ -48,7 +48,7 @@ class TestReindexCourse(ModuleStoreTestCase):
|
||||
|
||||
def test_given_no_arguments_raises_command_error(self):
|
||||
""" Test that raises CommandError for incorrect arguments """
|
||||
with self.assertRaisesRegexp(CommandError, ".* requires one or more arguments.*"):
|
||||
with self.assertRaisesRegexp(CommandError, ".* requires one or more *"):
|
||||
call_command('reindex_course')
|
||||
|
||||
@ddt.data('qwerty', 'invalid_key', 'xblockv1:qwerty')
|
||||
|
||||
@@ -49,7 +49,7 @@ class TestReindexLibrary(ModuleStoreTestCase):
|
||||
|
||||
def test_given_no_arguments_raises_command_error(self):
|
||||
""" Test that raises CommandError for incorrect arguments """
|
||||
with self.assertRaisesRegexp(CommandError, ".* requires one or more arguments.*"):
|
||||
with self.assertRaisesRegexp(CommandError, ".* requires one or more *"):
|
||||
call_command('reindex_library')
|
||||
|
||||
@ddt.data('qwerty', 'invalid_key', 'xblock-v1:qwe+rty')
|
||||
|
||||
Reference in New Issue
Block a user