From de96a47eac35a7cb340848c6d14a3512f86a1210 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Fri, 24 Jan 2014 13:40:05 -0500 Subject: [PATCH] happy path unit test --- .../management/commands/migrate_to_split.py | 13 +++----- .../commands/tests/test_migrate_to_split.py | 32 +++++++++++++++++-- .../xmodule/modulestore/tests/django_utils.py | 5 ++- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/cms/djangoapps/contentstore/management/commands/migrate_to_split.py b/cms/djangoapps/contentstore/management/commands/migrate_to_split.py index 01c6be25a0..87197886e2 100644 --- a/cms/djangoapps/contentstore/management/commands/migrate_to_split.py +++ b/cms/djangoapps/contentstore/management/commands/migrate_to_split.py @@ -8,6 +8,7 @@ from xmodule.modulestore import Location from xmodule.modulestore.django import modulestore from xmodule.modulestore.split_migrator import SplitMigrator from xmodule.modulestore import InvalidLocationError +from xmodule.modulestore.django import loc_mapper class Command(BaseCommand): @@ -60,15 +61,11 @@ class Command(BaseCommand): def handle(self, *args, **options): location, user, locator_string = self.parse_args(*args) - draft = modulestore('default') - direct = modulestore('direct') - split = modulestore('split') - migrator = SplitMigrator( - draft_modulestore=draft, - direct_modulestore=direct, - split_modulestore=split, - loc_mapper=split.loc_mapper, + draft_modulestore=modulestore('default'), + direct_modulestore=modulestore('direct'), + split_modulestore=modulestore('split'), + loc_mapper=loc_mapper(), ) migrator.migrate_mongo_course(location, user, locator_string) diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_migrate_to_split.py b/cms/djangoapps/contentstore/management/commands/tests/test_migrate_to_split.py index f800b2f62a..55879e4f43 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_migrate_to_split.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_migrate_to_split.py @@ -1,11 +1,17 @@ """ Unittests for importing a course via management command """ - 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.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): @@ -31,3 +37,25 @@ class TestArgParsing(unittest.TestCase): errstring = "No user exists with email fake@example.com" with self.assertRaisesRegexp(CommandError, errstring): 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) diff --git a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py index 684664890e..12994c9498 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py @@ -5,7 +5,7 @@ Modulestore configuration for test cases. from uuid import uuid4 from django.test import TestCase from xmodule.modulestore.django import editable_modulestore, \ - clear_existing_modulestores + clear_existing_modulestores, loc_mapper from xmodule.contentstore.django import contentstore @@ -225,6 +225,9 @@ class ModuleStoreTestCase(TestCase): if contentstore().fs_files: db = contentstore().fs_files.database db.connection.drop_database(db) + lm = loc_mapper() + if lm.db: + lm.location_map.drop() @classmethod def setUpClass(cls):