Skip to content

Commit

Permalink
feat: Remove code related to Old -> Split migration + re-running Old …
Browse files Browse the repository at this point in the history
…Mongo courses as Split
  • Loading branch information
UvgenGen committed Sep 16, 2022
1 parent 9530771 commit 25aa271
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 663 deletions.

This file was deleted.

This file was deleted.

44 changes: 24 additions & 20 deletions cms/djangoapps/contentstore/tests/test_clone_course.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,17 @@ class CloneCourseTest(CourseTestCase):
Unit tests for cloning a course
"""
def test_clone_course(self):
"""Tests cloning of a course as follows: XML -> Mongo (+ data) -> Mongo -> Split -> Split"""
# 1. import and populate test toy course
mongo_course1_id = self.import_and_populate_course()
mongo_course2_id = mongo_course1_id
"""
Tests cloning of a course: Split -> Split
"""

# 3. clone course (mongo -> split)
with self.store.default_store(ModuleStoreEnum.Type.split):
split_course3_id = CourseLocator(
org="edx3", course="split3", run="2013_Fall"
)
self.store.clone_course(mongo_course2_id, split_course3_id, self.user.id)
self.assertCoursesEqual(mongo_course2_id, split_course3_id)

# 4. clone course (split -> split)
split_course4_id = CourseLocator(
split_course1_id = CourseFactory().id
split_course2_id = CourseLocator(
org="edx4", course="split4", run="2013_Fall"
)
self.store.clone_course(split_course3_id, split_course4_id, self.user.id)
self.assertCoursesEqual(split_course3_id, split_course4_id)
self.store.clone_course(split_course1_id, split_course2_id, self.user.id)
self.assertCoursesEqual(split_course1_id, split_course2_id)

def test_space_in_asset_name_for_rerun_course(self):
"""
Expand Down Expand Up @@ -99,24 +91,36 @@ def test_rerun_course(self):
"""
Unit tests for :meth: `contentstore.tasks.rerun_course`
"""
mongo_course1_id = self.import_and_populate_course()
org = 'edX'
course_number = 'CS101'
course_run = '2015_Q1'
display_name = 'rerun'
fields = {'display_name': display_name}

# Create a course using split modulestore
split_course = CourseFactory.create(
org=org,
number=course_number,
run=course_run,
display_name=display_name,
default_store=ModuleStoreEnum.Type.split
)

# rerun from mongo into split
split_course3_id = CourseLocator(
org="edx3", course="split3", run="rerun_test"
)
# Mark the action as initiated
fields = {'display_name': 'rerun'}
CourseRerunState.objects.initiated(mongo_course1_id, split_course3_id, self.user, fields['display_name'])
result = rerun_course.delay(str(mongo_course1_id), str(split_course3_id), self.user.id,
CourseRerunState.objects.initiated(split_course.id, split_course3_id, self.user, fields['display_name'])
result = rerun_course.delay(str(split_course.id), str(split_course3_id), self.user.id,
json.dumps(fields, cls=EdxJSONEncoder))
self.assertEqual(result.get(), "succeeded")
self.assertTrue(has_course_author_access(self.user, split_course3_id), "Didn't grant access")
rerun_state = CourseRerunState.objects.find_first(course_key=split_course3_id)
self.assertEqual(rerun_state.state, CourseRerunUIStateManager.State.SUCCEEDED)

# try creating rerunning again to same name and ensure it generates error
result = rerun_course.delay(str(mongo_course1_id), str(split_course3_id), self.user.id)
result = rerun_course.delay(str(split_course.id), str(split_course3_id), self.user.id)
self.assertEqual(result.get(), "duplicate course")
# the below will raise an exception if the record doesn't exist
CourseRerunState.objects.find_first(
Expand Down
71 changes: 39 additions & 32 deletions cms/djangoapps/contentstore/tests/test_contentstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -1951,7 +1951,7 @@ def test_rerun_course_no_videos_in_val(self):
"""
Test when rerunning a course with no videos, VAL copies nothing
"""
source_course = CourseFactory.create()
source_course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split)
destination_course_key = self.post_rerun_request(source_course.id)
self.verify_rerun_course(source_course.id, destination_course_key, self.destination_course_data['display_name'])
videos, __ = get_videos_for_course(str(destination_course_key))
Expand All @@ -1964,7 +1964,10 @@ def test_rerun_course_video_upload_token(self):
Test when rerunning a course with video upload token, video upload token is not copied to new course.
"""
# Create a course with video upload token.
source_course = CourseFactory.create(video_upload_pipeline={"course_video_upload_token": 'test-token'})
source_course = CourseFactory.create(
video_upload_pipeline={"course_video_upload_token": 'test-token'},
default_store=ModuleStoreEnum.Type.split
)

destination_course_key = self.post_rerun_request(source_course.id)
self.verify_rerun_course(source_course.id, destination_course_key, self.destination_course_data['display_name'])
Expand All @@ -1977,7 +1980,7 @@ def test_rerun_course_video_upload_token(self):
self.assertEqual(new_course.video_upload_pipeline, {})

def test_rerun_course_success(self):
source_course = CourseFactory.create()
source_course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split)
create_video(
dict(
edx_video_id="tree-hugger",
Expand All @@ -2003,14 +2006,17 @@ def test_rerun_course_success(self):
self.assertEqual(new_course.video_upload_pipeline, {})

def test_rerun_course_resets_advertised_date(self):
source_course = CourseFactory.create(advertised_start="01-12-2015")
source_course = CourseFactory.create(
advertised_start="01-12-2015",
default_store=ModuleStoreEnum.Type.split
)
destination_course_key = self.post_rerun_request(source_course.id)
destination_course = self.store.get_course(destination_course_key)

self.assertEqual(None, destination_course.advertised_start)

def test_rerun_of_rerun(self):
source_course = CourseFactory.create()
source_course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split)
rerun_course_key = self.post_rerun_request(source_course.id)
rerun_of_rerun_data = {
'org': rerun_course_key.org,
Expand All @@ -2022,7 +2028,7 @@ def test_rerun_of_rerun(self):
self.verify_rerun_course(rerun_course_key, rerun_of_rerun_course_key, rerun_of_rerun_data['display_name'])

def test_rerun_course_fail_no_source_course(self):
existent_course_key = CourseFactory.create().id
existent_course_key = CourseFactory.create(default_store=ModuleStoreEnum.Type.split).id
non_existent_course_key = CourseLocator("org", "non_existent_course", "non_existent_run")
destination_course_key = self.post_rerun_request(non_existent_course_key)

Expand Down Expand Up @@ -2061,7 +2067,7 @@ def test_rerun_course_fail_duplicate_course(self):

def test_rerun_with_permission_denied(self):
with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}):
source_course = CourseFactory.create()
source_course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split)
auth.add_users(self.user, CourseCreatorRole(), self.user)
self.user.is_staff = False
self.user.save()
Expand Down Expand Up @@ -2090,7 +2096,7 @@ def test_rerun_error_trunc_message(self):
'xmodule.modulestore.mixed.MixedModuleStore.clone_course',
mock.Mock(side_effect=Exception()),
):
source_course = CourseFactory.create()
source_course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split)
message_too_long = "traceback".rjust(CourseRerunState.MAX_MESSAGE_LENGTH * 2, '-')
with mock.patch('traceback.format_exc', return_value=message_too_long):
destination_course_key = self.post_rerun_request(source_course.id)
Expand All @@ -2103,37 +2109,38 @@ def test_rerun_course_wiki_slug(self):
"""
Test that unique wiki_slug is assigned to rerun course.
"""
course_data = {
'org': 'edX',
'number': '123',
'display_name': 'Rerun Course',
'run': '2013'
}
with self.store.default_store(ModuleStoreEnum.Type.split):
course_data = {
'org': 'edX',
'number': '123',
'display_name': 'Rerun Course',
'run': '2013'
}

source_wiki_slug = '{}.{}.{}'.format(course_data['org'], course_data['number'], course_data['run'])
source_wiki_slug = '{}.{}.{}'.format(course_data['org'], course_data['number'], course_data['run'])

source_course_key = _get_course_id(self.store, course_data)
_create_course(self, source_course_key, course_data)
source_course = self.store.get_course(source_course_key)
source_course_key = _get_course_id(self.store, course_data)
_create_course(self, source_course_key, course_data)
source_course = self.store.get_course(source_course_key)

# Verify created course's wiki_slug.
self.assertEqual(source_course.wiki_slug, source_wiki_slug)
# Verify created course's wiki_slug.
self.assertEqual(source_course.wiki_slug, source_wiki_slug)

destination_course_data = course_data
destination_course_data['run'] = '2013_Rerun'
destination_course_data = course_data
destination_course_data['run'] = '2013_Rerun'

destination_course_key = self.post_rerun_request(
source_course.id, destination_course_data=destination_course_data
)
self.verify_rerun_course(source_course.id, destination_course_key, destination_course_data['display_name'])
destination_course = self.store.get_course(destination_course_key)
destination_course_key = self.post_rerun_request(
source_course.id, destination_course_data=destination_course_data
)
self.verify_rerun_course(source_course.id, destination_course_key, destination_course_data['display_name'])
destination_course = self.store.get_course(destination_course_key)

destination_wiki_slug = '{}.{}.{}'.format(
destination_course.id.org, destination_course.id.course, destination_course.id.run
)
destination_wiki_slug = '{}.{}.{}'.format(
destination_course.id.org, destination_course.id.course, destination_course.id.run
)

# Verify rerun course's wiki_slug.
self.assertEqual(destination_course.wiki_slug, destination_wiki_slug)
# Verify rerun course's wiki_slug.
self.assertEqual(destination_course.wiki_slug, destination_wiki_slug)


class ContentLicenseTest(ContentStoreTestCase):
Expand Down
Loading

0 comments on commit 25aa271

Please sign in to comment.