fix: learning_sequences missing courses now return 404 (not 500)
We weren't properly catching the CourseOutlineData.DoesNotExist error before this commit. TNL-7979
This commit is contained in:
@@ -70,6 +70,15 @@ class CourseOutlineViewTest(CacheIsolationTestCase, APITestCase): # lint-amnest
|
||||
result = self.client.get(self.course_url)
|
||||
assert result.status_code == 403
|
||||
|
||||
def test_non_existent_course_404(self):
|
||||
"""
|
||||
We should 404, not 500, when asking for a course that isn't there.
|
||||
"""
|
||||
self.client.login(username='staff', password='staff_pass')
|
||||
fake_course_key = self.course_key.replace(run="not_real")
|
||||
result = self.client.get(self.url_for(fake_course_key))
|
||||
assert result.status_code == 404
|
||||
|
||||
def test_deprecated_course_key(self):
|
||||
"""
|
||||
For now, make sure you need staff access bits to use the API.
|
||||
|
||||
@@ -12,13 +12,15 @@ from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthenticat
|
||||
from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser
|
||||
from opaque_keys import InvalidKeyError
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import serializers
|
||||
from rest_framework.exceptions import NotFound
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
import attr # lint-amnesty, pylint: disable=unused-import
|
||||
|
||||
from openedx.core.lib.api.permissions import IsStaff
|
||||
from .api import get_user_course_outline_details
|
||||
from .data import CourseOutlineData
|
||||
|
||||
User = get_user_model()
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -165,7 +167,11 @@ class CourseOutlineView(APIView):
|
||||
user = self._determine_user(request)
|
||||
|
||||
# Grab the user's outline and send our response...
|
||||
user_course_outline_details = get_user_course_outline_details(course_key, user, at_time)
|
||||
try:
|
||||
user_course_outline_details = get_user_course_outline_details(course_key, user, at_time)
|
||||
except CourseOutlineData.DoesNotExist:
|
||||
raise NotFound()
|
||||
|
||||
serializer = self.UserCourseOutlineDataSerializer(user_course_outline_details)
|
||||
return Response(serializer.data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user