Merge pull request #36860 from mitodl/asad/fix-organzation-course-linking
fix: link reruns & clones to correct orgs
This commit is contained in:
@@ -37,7 +37,7 @@ from opaque_keys.edx.keys import CourseKey, UsageKey
|
||||
from opaque_keys.edx.locator import LibraryLocator, LibraryContainerLocator
|
||||
from organizations.api import add_organization_course, ensure_organization
|
||||
from organizations.exceptions import InvalidOrganizationException
|
||||
from organizations.models import Organization, OrganizationCourse
|
||||
from organizations.models import Organization
|
||||
from path import Path as path
|
||||
from pytz import UTC
|
||||
from user_tasks.models import UserTaskArtifact, UserTaskStatus
|
||||
@@ -163,12 +163,6 @@ def rerun_course(source_course_key_string, destination_course_key_string, user_i
|
||||
# call edxval to attach videos to the rerun
|
||||
copy_course_videos(source_course_key, destination_course_key)
|
||||
|
||||
# Copy OrganizationCourse
|
||||
organization_course = OrganizationCourse.objects.filter(course_id=source_course_key_string).first()
|
||||
|
||||
if organization_course:
|
||||
clone_instance(organization_course, {'course_id': destination_course_key_string})
|
||||
|
||||
# Copy RestrictedCourse
|
||||
restricted_course = RestrictedCourse.objects.filter(course_key=source_course_key).first()
|
||||
|
||||
@@ -178,7 +172,7 @@ def rerun_course(source_course_key_string, destination_course_key_string, user_i
|
||||
for country_access_rule in country_access_rules:
|
||||
clone_instance(country_access_rule, {'restricted_course': new_restricted_course})
|
||||
|
||||
org_data = ensure_organization(source_course_key.org)
|
||||
org_data = ensure_organization(destination_course_key.org)
|
||||
add_organization_course(org_data, destination_course_key)
|
||||
return "succeeded"
|
||||
|
||||
|
||||
@@ -189,6 +189,26 @@ class RerunCourseTaskTestCase(CourseTestCase): # lint-amnesty, pylint: disable=
|
||||
country=restricted_country
|
||||
)
|
||||
|
||||
def test_success_different_org(self):
|
||||
"""
|
||||
The task should clone the OrganizationCourse with a different org.
|
||||
"""
|
||||
old_course_key = self.course.id
|
||||
new_course_key = CourseLocator(org='neworg', course=old_course_key.course, run='rerun')
|
||||
|
||||
old_course_id = str(old_course_key)
|
||||
new_course_id = str(new_course_key)
|
||||
|
||||
organization = OrganizationFactory(short_name=old_course_key.org)
|
||||
OrganizationCourse.objects.create(course_id=old_course_id, organization=organization)
|
||||
|
||||
# Run the task!
|
||||
self._rerun_course(old_course_key, new_course_key)
|
||||
|
||||
# Verify the OrganizationCourse is cloned with a different org
|
||||
self.assertEqual(OrganizationCourse.objects.count(), 2)
|
||||
OrganizationCourse.objects.get(course_id=new_course_id, organization__short_name='neworg')
|
||||
|
||||
|
||||
@override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE)
|
||||
class RegisterExamsTaskTestCase(CourseTestCase): # pylint: disable=missing-class-docstring
|
||||
|
||||
Reference in New Issue
Block a user