refactor: Move get_course_by_id helper from LMS to core

This helper is used by the LMS, CMS, _and_ `openedx.core`,
so let's move it to `openedx.core` to reduce import complexity.

The following files no longer import from LMS:
- cms/djangoapps/contentstore/management/commands/edit_course_tabs.py
- lms/djangoapps/ccx/migrations/0006_set_display_name_as_override.py
- openedx/core/djangoapps/ccxcon/api.py
- openedx/core/djangoapps/verified_track_content/models.py
- openedx/features/course_experience/plugins.py

Note: The LTI XBlock has a dependency on this import path (!?);
a fix can be found here [1].

- [1] https://github.com/edx/xblock-lti-consumer/pull/154
This commit is contained in:
stvn
2021-04-08 15:02:18 -07:00
parent 01199fc221
commit 43698fff0a
31 changed files with 63 additions and 52 deletions

View File

@@ -32,6 +32,7 @@ from lms.djangoapps.ccx.utils import ccx_course as ccx_course_cm
from lms.djangoapps.courseware import courses
from lms.djangoapps.instructor.access import allow_access, list_with_level
from lms.djangoapps.instructor.enrollment import enroll_email, get_email_params
from openedx.core.lib.courses import get_course_by_id
USER_PASSWORD = 'test'
@@ -422,7 +423,7 @@ class CcxListTest(CcxRestApiTest):
self.mstore.update_item(self.course, self.coach.id)
# case with deprecated master_course_id
with mock.patch('lms.djangoapps.courseware.courses.get_course_by_id', autospec=True) as mocked:
with mock.patch('lms.djangoapps.ccx.api.v0.views.get_course_by_id', autospec=True) as mocked:
mocked.return_value.id.deprecated = True
resp = self.client.post(self.list_url, data, format='json', HTTP_AUTHORIZATION=self.auth)
@@ -594,7 +595,7 @@ class CcxListTest(CcxRestApiTest):
coach_role_on_master_course = CourseCcxCoachRole(self.master_course_key)
assert coach_role_on_master_course.has_user(self.coach)
# check that the coach has been enrolled in the ccx
ccx_course_object = courses.get_course_by_id(course_key)
ccx_course_object = get_course_by_id(course_key)
assert CourseEnrollment.objects.filter(course_id=ccx_course_object.id, user=self.coach).exists()
# check that an email has been sent to the coach
assert len(outbox) == 1
@@ -1053,7 +1054,7 @@ class CcxDetailTest(CcxRestApiTest):
coach_role_on_master_course = CourseCcxCoachRole(self.master_course_key)
assert coach_role_on_master_course.has_user(new_coach)
# check that the coach has been enrolled in the ccx
ccx_course_object = courses.get_course_by_id(self.ccx_key)
ccx_course_object = get_course_by_id(self.ccx_key)
assert CourseEnrollment.objects.filter(course_id=ccx_course_object.id, user=new_coach).exists()
# check that an email has been sent to the coach
assert len(outbox) == 1

View File

@@ -28,6 +28,7 @@ from lms.djangoapps.courseware import courses
from lms.djangoapps.instructor.enrollment import enroll_email, get_email_params
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from openedx.core.lib.api import authentication, permissions
from openedx.core.lib.courses import get_course_by_id
from xmodule.modulestore.django import SignalHandler
from .paginators import CCXAPIPagination
@@ -70,7 +71,7 @@ def get_valid_course(course_id, is_ccx=False, advanced_course_check=False):
if not is_ccx:
try:
course_object = courses.get_course_by_id(course_key)
course_object = get_course_by_id(course_key)
except Http404:
log.info('Master Course with ID "%s" not found', course_id)
return None, None, 'course_id_does_not_exist', status.HTTP_404_NOT_FOUND