From 3a71901f93ce03b94f0a6761fbfb68a7a6293566 Mon Sep 17 00:00:00 2001 From: Waheed Ahmed Date: Thu, 6 Nov 2014 13:00:55 +0500 Subject: [PATCH] Fixed youtube stub server and removed unused variable. TNL-778 --- common/djangoapps/terrain/stubs/tests/test_youtube_stub.py | 2 +- common/djangoapps/terrain/stubs/youtube.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/common/djangoapps/terrain/stubs/tests/test_youtube_stub.py b/common/djangoapps/terrain/stubs/tests/test_youtube_stub.py index 3afe6308d4..aded4808f0 100644 --- a/common/djangoapps/terrain/stubs/tests/test_youtube_stub.py +++ b/common/djangoapps/terrain/stubs/tests/test_youtube_stub.py @@ -4,7 +4,7 @@ Unit test for stub YouTube implementation. import unittest import requests -from ..youtube import StubYouTubeService, IFRAME_API_RESPONSE +from ..youtube import StubYouTubeService class StubYouTubeServiceTest(unittest.TestCase): diff --git a/common/djangoapps/terrain/stubs/youtube.py b/common/djangoapps/terrain/stubs/youtube.py index 83e997f1e2..823b78fd02 100644 --- a/common/djangoapps/terrain/stubs/youtube.py +++ b/common/djangoapps/terrain/stubs/youtube.py @@ -24,7 +24,7 @@ from urlparse import urlparse from collections import OrderedDict -IFRAME_API_RESPONSE = requests.get('https://www.youtube.com/iframe_api').content.strip("\n") +IFRAME_API_RESPONSE = None class StubYouTubeHandler(StubHttpRequestHandler): @@ -51,6 +51,11 @@ class StubYouTubeHandler(StubHttpRequestHandler): Handle a GET request from the client and sends response back. """ + # Initialize only once if IFRAME_API_RESPONSE is none. + global IFRAME_API_RESPONSE # pylint: disable=W0603 + if IFRAME_API_RESPONSE is None: + IFRAME_API_RESPONSE = requests.get('https://www.youtube.com/iframe_api').content.strip("\n") + self.log_message( "Youtube provider received GET request to path {}".format(self.path) )