Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit bbb6734

Browse files
committed
Fallback to fake video ids when LMS down
1 parent b23464c commit bbb6734

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

analyticsdataserver/clients.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import logging
22

3+
from requests.exceptions import RequestException
4+
35
from edx_rest_api_client.client import EdxRestApiClient
46
from edx_rest_api_client.exceptions import HttpClientError
57
from opaque_keys.edx.keys import UsageKey
@@ -40,6 +42,9 @@ def all_videos(self, course_id):
4042
else:
4143
logger.warning("Course Blocks API failed to return video ids (%s).", e.response.status_code)
4244
return None
45+
except RequestException as e:
46+
logger.warning("Course Blocks API request failed. Is the LMS running?: " + str(e))
47+
return None
4348

4449
# Setup a terrible hack to silence mysterious flood of ImportErrors from stevedore inside edx-opaque-keys.
4550
# (The UsageKey utility still works despite the import errors, so I think the errors are not important).

analyticsdataserver/tests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from django.test import TestCase
1212
from django.test.utils import override_settings
1313
from rest_framework.authtoken.models import Token
14+
from requests.exceptions import ConnectionError
1415

1516
from analytics_data_api.v0.models import CourseEnrollmentDaily, CourseEnrollmentByBirthYear
1617
from analyticsdataserver.clients import CourseBlocksApiClient
@@ -176,6 +177,15 @@ def test_all_videos_500(self, logger):
176177
logger.warning.assert_called_with('Course Blocks API failed to return video ids (%s).', 418)
177178
self.assertEqual(videos, None)
178179

180+
@responses.activate
181+
@mock.patch('analyticsdataserver.clients.logger')
182+
def test_all_videos_connection_error(self, logger):
183+
exception = ConnectionError('LMS is dead')
184+
responses.add(responses.GET, 'http://example.com/blocks/', body=exception)
185+
videos = self.client.all_videos('course_id')
186+
logger.warning.assert_called_with('Course Blocks API request failed. Is the LMS running?: ' + str(exception))
187+
self.assertEqual(videos, None)
188+
179189
@responses.activate
180190
def test_all_videos_pass_through_bad_id(self):
181191
responses.add(responses.GET, 'http://example.com/blocks/', body=json.dumps({'blocks': {

0 commit comments

Comments
 (0)