This repository was archived by the owner on May 1, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import logging
22
3+ from requests .exceptions import RequestException
4+
35from edx_rest_api_client .client import EdxRestApiClient
46from edx_rest_api_client .exceptions import HttpClientError
57from 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).
Original file line number Diff line number Diff line change 1111from django .test import TestCase
1212from django .test .utils import override_settings
1313from rest_framework .authtoken .models import Token
14+ from requests .exceptions import ConnectionError
1415
1516from analytics_data_api .v0 .models import CourseEnrollmentDaily , CourseEnrollmentByBirthYear
1617from 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' : {
You can’t perform that action at this time.
0 commit comments