From 23bc5af0fc154c83e6c711d7563508cc7f0bbce7 Mon Sep 17 00:00:00 2001 From: Waheed Ahmed Date: Mon, 5 Aug 2019 13:44:09 +0500 Subject: [PATCH] Fix course:org link creation upon rerun. Upon rerun creation from publisher course:organization link was not creating, due to which org logo was not appearing on course certificates. Fixed by creating course:org link upon rerun. PROD-125 --- .../api/v1/tests/test_views/test_course_runs.py | 11 +++++++++++ cms/djangoapps/contentstore/tasks.py | 3 +++ .../contentstore/tests/test_course_create_rerun.py | 9 +++++++++ 3 files changed, 23 insertions(+) diff --git a/cms/djangoapps/api/v1/tests/test_views/test_course_runs.py b/cms/djangoapps/api/v1/tests/test_views/test_course_runs.py index cdc1d3819d..fd58859526 100644 --- a/cms/djangoapps/api/v1/tests/test_views/test_course_runs.py +++ b/cms/djangoapps/api/v1/tests/test_views/test_course_runs.py @@ -9,12 +9,14 @@ import pytz from django.core.files.uploadedfile import SimpleUploadedFile from django.test import RequestFactory from django.urls import reverse +from mock import patch from opaque_keys.edx.keys import CourseKey from rest_framework.test import APIClient from openedx.core.lib.courses import course_image_url from student.models import CourseAccessRole from student.tests.factories import TEST_PASSWORD, AdminFactory, UserFactory +from util.organizations_helpers import add_organization, get_course_organizations from xmodule.contentstore.content import StaticContent from xmodule.contentstore.django import contentstore from xmodule.exceptions import NotFoundError @@ -320,6 +322,7 @@ class CourseRunViewSetTests(ModuleStoreTestCase): # There should now be an image stored contentstore().find(content_key) + @patch.dict('django.conf.settings.FEATURES', {'ORGANIZATIONS_APP': True}) @ddt.data( ('instructor_paced', False, 'NotOriginalNumber1x'), ('self_paced', True, None), @@ -327,6 +330,11 @@ class CourseRunViewSetTests(ModuleStoreTestCase): @ddt.unpack def test_rerun(self, pacing_type, expected_self_paced_value, number): original_course_run = ToyCourseFactory() + add_organization({ + 'name': 'Test Organization', + 'short_name': original_course_run.id.org, + 'description': 'Testing Organization Description', + }) start = datetime.datetime.now(pytz.UTC).replace(microsecond=0) end = start + datetime.timedelta(days=30) user = UserFactory() @@ -369,6 +377,9 @@ class CourseRunViewSetTests(ModuleStoreTestCase): self.assert_course_run_schedule(course_run, start, end) self.assert_access_role(course_run, user, role) self.assert_course_access_role_count(course_run, 1) + course_orgs = get_course_organizations(course_run_key) + self.assertEqual(len(course_orgs), 1) + self.assertEqual(course_orgs[0]['short_name'], original_course_run.id.org) def test_rerun_duplicate_run(self): course_run = ToyCourseFactory() diff --git a/cms/djangoapps/contentstore/tasks.py b/cms/djangoapps/contentstore/tasks.py index 3fdad36719..b1f5f6d94a 100644 --- a/cms/djangoapps/contentstore/tasks.py +++ b/cms/djangoapps/contentstore/tasks.py @@ -45,6 +45,7 @@ from models.settings.course_metadata import CourseMetadata from openedx.core.djangoapps.embargo.models import CountryAccessRule, RestrictedCourse from openedx.core.lib.extract_tar import safetar_extractall from student.auth import has_course_author_access +from util.organizations_helpers import add_organization_course, get_organization_by_short_name from xmodule.contentstore.django import contentstore from xmodule.course_module import CourseFields from xmodule.exceptions import SerializationError @@ -484,6 +485,8 @@ 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 = get_organization_by_short_name(source_course_key.org) + add_organization_course(org_data, destination_course_key) return "succeeded" except DuplicateCourseError: diff --git a/cms/djangoapps/contentstore/tests/test_course_create_rerun.py b/cms/djangoapps/contentstore/tests/test_course_create_rerun.py index f390799b08..d7189c016c 100644 --- a/cms/djangoapps/contentstore/tests/test_course_create_rerun.py +++ b/cms/djangoapps/contentstore/tests/test_course_create_rerun.py @@ -66,10 +66,16 @@ class TestCourseListing(ModuleStoreTestCase): self.client.logout() ModuleStoreTestCase.tearDown(self) + @patch.dict('django.conf.settings.FEATURES', {'ORGANIZATIONS_APP': True}) def test_rerun(self): """ Just testing the functionality the view handler adds over the tasks tested in test_clone_course """ + add_organization({ + 'name': 'Test Organization', + 'short_name': self.source_course_key.org, + 'description': 'Testing Organization Description', + }) response = self.client.ajax_post(self.course_create_rerun_url, { 'source_course_key': six.text_type(self.source_course_key), 'org': self.source_course_key.org, 'course': self.source_course_key.course, 'run': 'copy', @@ -86,6 +92,9 @@ class TestCourseListing(ModuleStoreTestCase): self.assertEqual(dest_course.end, source_course.end) self.assertEqual(dest_course.enrollment_start, None) self.assertEqual(dest_course.enrollment_end, None) + course_orgs = get_course_organizations(dest_course_key) + self.assertEqual(len(course_orgs), 1) + self.assertEqual(course_orgs[0]['short_name'], self.source_course_key.org) @ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split) def test_newly_created_course_has_web_certs_enabled(self, store):