fix: catch and log the CourseOverview.DoesNotExist instead of raising
This commit is contained in:
@@ -100,11 +100,18 @@ class CreditService:
|
||||
}
|
||||
|
||||
if return_course_info:
|
||||
course_overview = CourseOverview.get_from_id(course_key)
|
||||
result.update({
|
||||
'course_name': course_overview.display_name,
|
||||
'course_end_date': course_overview.end,
|
||||
})
|
||||
try:
|
||||
course_overview = CourseOverview.get_from_id(course_key)
|
||||
result.update({
|
||||
'course_name': course_overview.display_name,
|
||||
'course_end_date': course_overview.end,
|
||||
})
|
||||
except CourseOverview.DoesNotExist:
|
||||
log.exception(
|
||||
"Could not get name and end_date for course %s, This happened because we were unable to "
|
||||
"get/create CourseOverview object for the course. It's possible that the Course has been deleted.",
|
||||
str(course_key),
|
||||
)
|
||||
return result
|
||||
|
||||
def set_credit_requirement_status(self, user_id, course_key_or_id, req_namespace,
|
||||
|
||||
@@ -3,9 +3,11 @@ Tests for the Credit xBlock service
|
||||
"""
|
||||
|
||||
|
||||
from unittest.mock import patch
|
||||
import ddt
|
||||
|
||||
from common.djangoapps.course_modes.models import CourseMode
|
||||
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
|
||||
from openedx.core.djangoapps.credit.api.eligibility import set_credit_requirements
|
||||
from openedx.core.djangoapps.credit.models import CreditCourse
|
||||
from openedx.core.djangoapps.credit.services import CreditService
|
||||
@@ -261,6 +263,22 @@ class CreditServiceTests(ModuleStoreTestCase):
|
||||
assert 'course_name' in credit_state
|
||||
assert credit_state['course_name'] == self.course.display_name
|
||||
|
||||
@patch("openedx.core.djangoapps.credit.services.log")
|
||||
def test_course_exception_log(self, exception_log):
|
||||
"""
|
||||
Make sure we catch the CourseOverview.DoesNotExist exception and log it instead of raising
|
||||
"""
|
||||
with patch("openedx.core.djangoapps.content.course_overviews.models.CourseOverview.get_from_id",
|
||||
side_effect=CourseOverview.DoesNotExist):
|
||||
|
||||
self.enroll()
|
||||
credit_state = self.service.get_credit_state(self.user.id, self.course.id, return_course_info=True)
|
||||
assert credit_state is not None
|
||||
exception_log.exception.assert_called_once_with(
|
||||
"Could not get name and end_date for course %s, This happened because we were unable to "
|
||||
"get/create CourseOverview object for the course. It's possible that the Course has been deleted.",
|
||||
str(self.course.id))
|
||||
|
||||
def test_set_status_non_credit(self):
|
||||
"""
|
||||
assert that we can still try to update a credit status but return quickly if
|
||||
|
||||
Reference in New Issue
Block a user