diff --git a/cms/djangoapps/contentstore/management/commands/course_id_clash.py b/cms/djangoapps/contentstore/management/commands/course_id_clash.py deleted file mode 100644 index 791a5bf1bd..0000000000 --- a/cms/djangoapps/contentstore/management/commands/course_id_clash.py +++ /dev/null @@ -1,52 +0,0 @@ -""" -Script for finding all courses whose org/name pairs == other courses when ignoring case -""" -from django.core.management.base import BaseCommand -from xmodule.modulestore.django import modulestore -from xmodule.modulestore import ModuleStoreEnum - - -# -# To run from command line: ./manage.py cms --settings dev course_id_clash -# -class Command(BaseCommand): - """ - Script for finding all courses in the Mongo Modulestore whose org/name pairs == other courses when ignoring case - """ - help = 'List all courses ids in the Mongo Modulestore which may collide when ignoring case' - - def handle(self, *args, **options): - mstore = modulestore()._get_modulestore_by_type(ModuleStoreEnum.Type.mongo) # pylint: disable=protected-access - if hasattr(mstore, 'collection'): - map_fn = ''' - function () { - emit(this._id.org.toLowerCase()+this._id.course.toLowerCase(), {target: this._id}); - } - ''' - reduce_fn = ''' - function (idpair, matches) { - var result = {target: []}; - matches.forEach(function (match) { - result.target.push(match.target); - }); - return result; - } - ''' - finalize = ''' - function(key, reduced) { - if (Array.isArray(reduced.target)) { - return reduced; - } - else {return null;} - } - ''' - results = mstore.collection.map_reduce( - map_fn, reduce_fn, {'inline': True}, query={'_id.category': 'course'}, finalize=finalize - ) - results = results.get('results') - for entry in results: - if entry.get('value') is not None: - print '{:-^40}'.format(entry.get('_id')) - for course_id in entry.get('value').get('target'): - print ' {}/{}/{}'.format(course_id.get('org'), course_id.get('course'), course_id.get('name')) - diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_course_id_clash.py b/cms/djangoapps/contentstore/management/commands/tests/test_course_id_clash.py deleted file mode 100644 index dfe3339ad3..0000000000 --- a/cms/djangoapps/contentstore/management/commands/tests/test_course_id_clash.py +++ /dev/null @@ -1,40 +0,0 @@ -import sys -from StringIO import StringIO -from django.test import TestCase -from django.core.management import call_command -from xmodule.modulestore.tests.factories import CourseFactory - -class ClashIdTestCase(TestCase): - """ - Test for course_id_clash. - """ - def test_course_clash(self): - """ - Test for course_id_clash. - """ - expected = [] - # clashing courses - course = CourseFactory.create(org="test", course="courseid", display_name="run1") - expected.append(course.id) - course = CourseFactory.create(org="TEST", course="courseid", display_name="RUN12") - expected.append(course.id) - course = CourseFactory.create(org="test", course="CourseId", display_name="aRUN123") - expected.append(course.id) - # not clashing courses - not_expected = [] - course = CourseFactory.create(org="test", course="course2", display_name="run1") - not_expected.append(course.id) - course = CourseFactory.create(org="test1", course="courseid", display_name="run1") - not_expected.append(course.id) - course = CourseFactory.create(org="test", course="courseid0", display_name="run1") - not_expected.append(course.id) - - old_stdout = sys.stdout - sys.stdout = mystdout = StringIO() - call_command('course_id_clash', stdout=mystdout) - sys.stdout = old_stdout - result = mystdout.getvalue() - for courseid in expected: - self.assertIn(courseid.to_deprecated_string(), result) - for courseid in not_expected: - self.assertNotIn(courseid.to_deprecated_string(), result) diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index 1dc25a8f17..a667c52e1d 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -49,8 +49,6 @@ from opaque_keys import InvalidKeyError from contentstore.tests.utils import get_url from course_action_state.models import CourseRerunState, CourseRerunUIStateManager -from unittest import skipIf - from course_action_state.managers import CourseActionStateItemNotFoundError @@ -63,7 +61,7 @@ class ContentStoreTestCase(CourseTestCase): """ Base class for Content Store Test Cases """ - pass + class ContentStoreToyCourseTest(ContentStoreTestCase): """ @@ -317,7 +315,7 @@ class ContentStoreToyCourseTest(ContentStoreTestCase): def test_delete(self): store = self.store - course = CourseFactory.create(org='edX', course='999', display_name='Robot Super Course') + course = CourseFactory.create() chapterloc = ItemFactory.create(parent_location=course.location, display_name="Chapter").location ItemFactory.create(parent_location=chapterloc, category='sequential', display_name="Sequential") @@ -567,7 +565,7 @@ class ContentStoreToyCourseTest(ContentStoreTestCase): def test_illegal_draft_crud_ops(self): draft_store = self.store - course = CourseFactory.create(org='MITx', course='999', display_name='Robot Super Course') + course = CourseFactory.create() location = course.id.make_usage_key('chapter', 'neuvo') # Ensure draft mongo store does not create drafts for things that shouldn't be draft @@ -1186,7 +1184,7 @@ class ContentStoreTest(ContentStoreTestCase): def test_course_index_view_with_course(self): """Test viewing the index page with an existing course""" - CourseFactory.create(display_name='Robot Super Educational Course') + CourseFactory.create(, display_name='Robot Super Educational Course') resp = self.client.get_html('/course/') self.assertContains( resp, @@ -1197,13 +1195,14 @@ class ContentStoreTest(ContentStoreTestCase): def test_course_overview_view_with_course(self): """Test viewing the course overview page with an existing course""" - course = CourseFactory.create(org='MITx', course='999', display_name='Robot Super Course') + course_cat_num = self.random_course_name() + course = CourseFactory.create(org='MITx', course=course_cat_num, display_name='Robot Super Course') resp = self._show_course_overview(course.id) self.assertContains( resp, '
'.format( - locator='i4x://MITx/999/course/Robot_Super_Course', - course_key='MITx/999/Robot_Super_Course', + locator=unicode(course.location), + course_key=unicode(course.id), ), status_code=200, html=True @@ -1211,7 +1210,7 @@ class ContentStoreTest(ContentStoreTestCase): def test_create_item(self): """Test creating a new xblock instance.""" - course = _course_factory_create_course() + course = CourseFactory.create()() section_data = { 'parent_locator': unicode(course.location), @@ -1223,14 +1222,12 @@ class ContentStoreTest(ContentStoreTestCase): self.assertEqual(resp.status_code, 200) data = parse_json(resp) - self.assertRegexpMatches( - data['locator'], - r"MITx/999/chapter/([0-9]|[a-f]){3,}$" - ) + retarget = unicode(course.id.make_usage_key('chapter', 'REPLACE')).replace('REPLACE', r'([0-9]|[a-f]){3,}') + self.assertRegexpMatches(data['locator'], retarget) def test_capa_module(self): """Test that a problem treats markdown specially.""" - course = _course_factory_create_course() + course = CourseFactory.create()() problem_data = { 'parent_locator': unicode(course.location), @@ -1382,7 +1379,7 @@ class ContentStoreTest(ContentStoreTestCase): self.assertTrue(did_load_item) def test_forum_id_generation(self): - course = CourseFactory.create(org='edX', course='999', display_name='Robot Super Course') + course = CourseFactory.create() # crate a new module and add it as a child to a vertical new_discussion_item = self.store.create_item(self.user.id, course.id, 'discussion', 'new_component') @@ -1501,8 +1498,7 @@ class MetadataSaveTestCase(ContentStoreTestCase): def setUp(self): super(MetadataSaveTestCase, self).setUp() - course = CourseFactory.create( - org='edX', course='999', display_name='Robot Super Course') + course = CourseFactory.create() video_sample_xml = '''