Commit bbb67343 by Tyler Hallada

Fallback to fake video ids when LMS down

parent b23464c7
import logging
from requests.exceptions import RequestException
from edx_rest_api_client.client import EdxRestApiClient
from edx_rest_api_client.exceptions import HttpClientError
from opaque_keys.edx.keys import UsageKey
......@@ -40,6 +42,9 @@ class CourseBlocksApiClient(EdxRestApiClient):
else:
logger.warning("Course Blocks API failed to return video ids (%s).", e.response.status_code)
return None
except RequestException as e:
logger.warning("Course Blocks API request failed. Is the LMS running?: " + str(e))
return None
# Setup a terrible hack to silence mysterious flood of ImportErrors from stevedore inside edx-opaque-keys.
# (The UsageKey utility still works despite the import errors, so I think the errors are not important).
......
......@@ -11,6 +11,7 @@ from django.db.utils import ConnectionHandler, DatabaseError
from django.test import TestCase
from django.test.utils import override_settings
from rest_framework.authtoken.models import Token
from requests.exceptions import ConnectionError
from analytics_data_api.v0.models import CourseEnrollmentDaily, CourseEnrollmentByBirthYear
from analyticsdataserver.clients import CourseBlocksApiClient
......@@ -177,6 +178,15 @@ class ClientTests(TestCase):
self.assertEqual(videos, None)
@responses.activate
@mock.patch('analyticsdataserver.clients.logger')
def test_all_videos_connection_error(self, logger):
exception = ConnectionError('LMS is dead')
responses.add(responses.GET, 'http://example.com/blocks/', body=exception)
videos = self.client.all_videos('course_id')
logger.warning.assert_called_with('Course Blocks API request failed. Is the LMS running?: ' + str(exception))
self.assertEqual(videos, None)
@responses.activate
def test_all_videos_pass_through_bad_id(self):
responses.add(responses.GET, 'http://example.com/blocks/', body=json.dumps({'blocks': {
'block-v1:edX+DemoX+Demo_Course+type@video+block@5c90cffecd9b48b188cbfea176bf7fe9': {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment