Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions cms/djangoapps/contentstore/features/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ def configure_youtube_api(_step, action):
@step('I have created a Video component$')
def i_created_a_video_component(_step):

assert_less(world.youtube.config['youtube_api_response'].status_code, 400, "Real Youtube server is unavailable")

world.create_course_with_unit()
world.create_component_instance(
step=_step,
Expand Down
6 changes: 6 additions & 0 deletions cms/envs/bok_choy.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@

# Unfortunately, we need to use debug mode to serve staticfiles
DEBUG = True

# Point the URL used to test YouTube availability to our stub YouTube server
YOUTUBE_PORT = 9080
YOUTUBE['API'] = "127.0.0.1:{0}/get_youtube_api/".format(YOUTUBE_PORT)
YOUTUBE['TEST_URL'] = "127.0.0.1:{0}/test_youtube/".format(YOUTUBE_PORT)
YOUTUBE['TEXT_API']['url'] = "127.0.0.1:{0}/test_transcripts_youtube/".format(YOUTUBE_PORT)
5 changes: 0 additions & 5 deletions common/djangoapps/terrain/start_stubs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Initialize and teardown stub and video HTTP services for use in acceptance tests.
"""
import requests
from lettuce import before, after, world
from django.conf import settings
from terrain.stubs.youtube import StubYouTubeService
Expand All @@ -16,8 +15,6 @@
"lti": {"port": settings.LTI_PORT, "class": StubLtiService},
}

YOUTUBE_API_RESPONSE = requests.get('http://www.youtube.com/iframe_api')


@before.all # pylint: disable=E1101
def start_video_server():
Expand Down Expand Up @@ -49,8 +46,6 @@ def start_stubs(_scenario):
"""
for name, service in SERVICES.iteritems():
fake_server = service['class'](port_num=service['port'])
if name == 'youtube':
fake_server.config['youtube_api_response'] = YOUTUBE_API_RESPONSE
setattr(world, name, fake_server)


Expand Down
14 changes: 14 additions & 0 deletions common/djangoapps/terrain/stubs/tests/test_youtube_stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,17 @@ def test_transcript_url_not_equal(self):
def test_transcript_not_found(self):
response = requests.get(self.url + 'test_transcripts_youtube/some_id')
self.assertEqual(404, response.status_code)

def test_reset_configuration(self):

reset_config_url = self.url + 'del_config'

# add some configuration data
self.server.config['test_reset'] = 'This is a reset config test'

# reset server configuration
response = requests.delete(reset_config_url)
self.assertEqual(response.status_code, 200)

# ensure that server config dict is empty after successful reset
self.assertEqual(self.server.config, {})
26 changes: 24 additions & 2 deletions common/djangoapps/terrain/stubs/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
you get "Unused url" message inside the browser.
"""

import textwrap
from .http import StubHttpRequestHandler, StubHttpService
import json
import time
Expand All @@ -25,6 +26,17 @@
from collections import OrderedDict


IFRAME_API_RESPONSE = textwrap.dedent(
"if (!window['YT']) {var YT = {loading: 0,loaded: 0};}if (!window['YTConfig']) {var YTConfig"
" = {};}if (!YT.loading) {YT.loading = 1;(function(){var l = [];YT.ready = function(f) {if ("
"YT.loaded) {f();} else {l.push(f);}};window.onYTReady = function() {YT.loaded = 1;for (var "
"i = 0; i < l.length; i++) {try {l[i]();} catch (e) {}}};YT.setConfig = function(c) {for (var"
" k in c) {if (c.hasOwnProperty(k)) {YTConfig[k] = c[k];}}};var a = document.createElement"
"('script');a.id = 'www-widgetapi-script';a.src = 'http:' + '"
"//s.ytimg.com/yts/jsbin/www-widgetapi-vflxHr_AR.js';a.async = true;var b = "
"document.getElementsByTagName('script')[0];b.parentNode.insertBefore(a, b);})();}")


class StubYouTubeHandler(StubHttpRequestHandler):
"""
A handler for Youtube GET requests.
Expand All @@ -33,6 +45,17 @@ class StubYouTubeHandler(StubHttpRequestHandler):
# Default number of seconds to delay the response to simulate network latency.
DEFAULT_DELAY_SEC = 0.5

def do_DELETE(self): # pylint: disable=C0103
"""
Allow callers to delete all the server configurations using the /del_config URL.
"""
if self.path == "/del_config" or self.path == "/del_config/":
self.server.config = dict()
self.log_message("Reset Server Configuration.")
self.send_response(200)
else:
self.send_response(404)

def do_GET(self):
"""
Handle a GET request from the client and sends response back.
Expand Down Expand Up @@ -80,8 +103,7 @@ def do_GET(self):
if self.server.config.get('youtube_api_blocked'):
self.send_response(404, content='', headers={'Content-type': 'text/plain'})
else:
response = self.server.config['youtube_api_response']
self.send_response(200, content=response.text, headers={'Content-type': 'text/html'})
self.send_response(200, content=IFRAME_API_RESPONSE, headers={'Content-type': 'text/html'})

else:
self.send_response(
Expand Down
1 change: 0 additions & 1 deletion common/test/acceptance/pages/lms/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
}



@js_defined('window.Video', 'window.RequireJS.require', 'window.jQuery')
class VideoPage(PageObject):
"""
Expand Down
2 changes: 0 additions & 2 deletions lms/djangoapps/courseware/features/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ def add_videos_to_course(course, player_mode=None, display_names=None, hashes=No

def add_video_to_course(course, parent_location=None, player_mode=None, data=None, display_name='Video'):

assert_less(world.youtube.config['youtube_api_response'].status_code, 400, "Real Youtube server is unavailable")

if not parent_location:
parent_location = add_vertical_to_course(course)
kwargs = get_metadata(parent_location, player_mode, data, display_name=display_name)
Expand Down
2 changes: 1 addition & 1 deletion lms/envs/acceptance.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,6 @@ def seed():
}

# Point the URL used to test YouTube availability to our stub YouTube server
YOUTUBE['API'] = 'youtube.com/iframe_api'
YOUTUBE['API'] = "127.0.0.1:{0}/get_youtube_api/".format(YOUTUBE_PORT)
YOUTUBE['TEST_URL'] = "127.0.0.1:{0}/test_youtube/".format(YOUTUBE_PORT)
YOUTUBE['TEXT_API']['url'] = "127.0.0.1:{0}/test_transcripts_youtube/".format(YOUTUBE_PORT)
7 changes: 7 additions & 0 deletions lms/envs/bok_choy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
from path import path


CONFIG_ROOT = path(__file__).abspath().dirname() # pylint: disable=E1120
TEST_ROOT = CONFIG_ROOT.dirname().dirname() / "test_root"

Expand Down Expand Up @@ -60,3 +61,9 @@

# Unfortunately, we need to use debug mode to serve staticfiles
DEBUG = True

# Point the URL used to test YouTube availability to our stub YouTube server
YOUTUBE_PORT = 9080
YOUTUBE['API'] = "127.0.0.1:{0}/get_youtube_api/".format(YOUTUBE_PORT)
YOUTUBE['TEST_URL'] = "127.0.0.1:{0}/test_youtube/".format(YOUTUBE_PORT)
YOUTUBE['TEXT_API']['url'] = "127.0.0.1:{0}/test_transcripts_youtube/".format(YOUTUBE_PORT)
6 changes: 6 additions & 0 deletions rakelib/bok_choy.rake
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ BOK_CHOY_STUBS = {
:port => 8777,
:log => File.join(BOK_CHOY_LOG_DIR, "bok_choy_video_sources.log"),
:config => "root_dir=#{VIDEO_SOURCE_DIR}"
},

:youtube => {
:port => 9080,
:log => File.join(BOK_CHOY_LOG_DIR, "bok_choy_youtube.log")
}

}

# For the time being, stubs are used by both the bok-choy and lettuce acceptance tests
Expand Down