Commit de96a47e by David Baumgold

happy path unit test

parent f08dc428
...@@ -8,6 +8,7 @@ from xmodule.modulestore import Location ...@@ -8,6 +8,7 @@ from xmodule.modulestore import Location
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from xmodule.modulestore.split_migrator import SplitMigrator from xmodule.modulestore.split_migrator import SplitMigrator
from xmodule.modulestore import InvalidLocationError from xmodule.modulestore import InvalidLocationError
from xmodule.modulestore.django import loc_mapper
class Command(BaseCommand): class Command(BaseCommand):
...@@ -60,15 +61,11 @@ class Command(BaseCommand): ...@@ -60,15 +61,11 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
location, user, locator_string = self.parse_args(*args) location, user, locator_string = self.parse_args(*args)
draft = modulestore('default')
direct = modulestore('direct')
split = modulestore('split')
migrator = SplitMigrator( migrator = SplitMigrator(
draft_modulestore=draft, draft_modulestore=modulestore('default'),
direct_modulestore=direct, direct_modulestore=modulestore('direct'),
split_modulestore=split, split_modulestore=modulestore('split'),
loc_mapper=split.loc_mapper, loc_mapper=loc_mapper(),
) )
migrator.migrate_mongo_course(location, user, locator_string) migrator.migrate_mongo_course(location, user, locator_string)
""" """
Unittests for importing a course via management command Unittests for importing a course via management command
""" """
import unittest import unittest
from django.core.management import CommandError from django.core.management import CommandError, call_command
from django.test.utils import override_settings
from contentstore.management.commands.migrate_to_split import Command from contentstore.management.commands.migrate_to_split import Command
from contentstore.tests.modulestore_config import TEST_MODULESTORE
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from student.tests.factories import UserFactory
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.django import loc_mapper
class TestArgParsing(unittest.TestCase): class TestArgParsing(unittest.TestCase):
...@@ -31,3 +37,25 @@ class TestArgParsing(unittest.TestCase): ...@@ -31,3 +37,25 @@ class TestArgParsing(unittest.TestCase):
errstring = "No user exists with email fake@example.com" errstring = "No user exists with email fake@example.com"
with self.assertRaisesRegexp(CommandError, errstring): with self.assertRaisesRegexp(CommandError, errstring):
self.command.handle("i4x://org/course/category/name", "fake@example.com") self.command.handle("i4x://org/course/category/name", "fake@example.com")
@override_settings(MODULESTORE=TEST_MODULESTORE)
class TestMigrateToSplit(ModuleStoreTestCase):
"""
Unit tests for importing a course from command line
"""
def setUp(self):
super(TestMigrateToSplit, self).setUp()
self.course = CourseFactory()
self.user = UserFactory()
def test_happy_path(self):
call_command(
"migrate_to_split",
str(self.course.location),
self.user.email,
)
locator = loc_mapper().translate_location(self.course.id, self.course.location)
course_from_split = modulestore('split').get_course(locator)
self.assertIsNotNone(course_from_split)
...@@ -5,7 +5,7 @@ Modulestore configuration for test cases. ...@@ -5,7 +5,7 @@ Modulestore configuration for test cases.
from uuid import uuid4 from uuid import uuid4
from django.test import TestCase from django.test import TestCase
from xmodule.modulestore.django import editable_modulestore, \ from xmodule.modulestore.django import editable_modulestore, \
clear_existing_modulestores clear_existing_modulestores, loc_mapper
from xmodule.contentstore.django import contentstore from xmodule.contentstore.django import contentstore
...@@ -225,6 +225,9 @@ class ModuleStoreTestCase(TestCase): ...@@ -225,6 +225,9 @@ class ModuleStoreTestCase(TestCase):
if contentstore().fs_files: if contentstore().fs_files:
db = contentstore().fs_files.database db = contentstore().fs_files.database
db.connection.drop_database(db) db.connection.drop_database(db)
lm = loc_mapper()
if lm.db:
lm.location_map.drop()
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
......
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