diff --git a/cms/djangoapps/contentstore/features/video.feature b/cms/djangoapps/contentstore/features/video.feature index bb4672c499d3..e465dc6b5bdf 100644 --- a/cms/djangoapps/contentstore/features/video.feature +++ b/cms/djangoapps/contentstore/features/video.feature @@ -5,7 +5,7 @@ Feature: CMS Video Component # 1 Scenario: YouTube stub server proxies YouTube API correctly Given youtube stub server proxies YouTube API - Given I have created a Video component + And I have created a Video component Then I can see video button "play" And I click video button "play" Then I can see video button "pause" @@ -13,8 +13,8 @@ Feature: CMS Video Component # 2 Scenario: YouTube stub server can block YouTube API Given youtube stub server blocks YouTube API - Given I have created a Video component - Given We explicitly wait for YouTube API to not load + And I have created a Video component + And I wait for "3" seconds Then I do not see video button "play" # 3 diff --git a/cms/djangoapps/contentstore/features/video.py b/cms/djangoapps/contentstore/features/video.py index ef48014da6a5..d2e7c81b585f 100644 --- a/cms/djangoapps/contentstore/features/video.py +++ b/cms/djangoapps/contentstore/features/video.py @@ -1,6 +1,7 @@ # pylint: disable=C0111 from lettuce import world, step +from nose.tools import assert_less from xmodule.modulestore import Location from contentstore.utils import get_modulestore from selenium.webdriver.common.keys import Keys @@ -32,13 +33,11 @@ def configure_youtube_api(_step, action): raise ValueError('Parameter `action` should be one of "proxies" or "blocks".') -@step('We explicitly wait for YouTube API to not load$') -def wait_for_youtube_api_fail(_step): - world.wait(3) - - @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, @@ -51,7 +50,8 @@ def i_created_a_video_component(_step): world.wait_for_present('.is-initialized') world.wait(DELAY) world.wait_for_invisible(SELECTORS['spinner']) - + if not world.youtube.config.get('youtube_api_blocked'): + world.wait_for_visible(SELECTORS['controls']) @step('I have created a Video component with subtitles$') def i_created_a_video_with_subs(_step): diff --git a/common/djangoapps/terrain/start_stubs.py b/common/djangoapps/terrain/start_stubs.py index 3e663364e7cf..b859e95df44e 100644 --- a/common/djangoapps/terrain/start_stubs.py +++ b/common/djangoapps/terrain/start_stubs.py @@ -1,7 +1,7 @@ """ Initialize and teardown fake 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 @@ -14,6 +14,8 @@ "lti": {"port": settings.LTI_PORT, "class": StubLtiService}, } +YOUTUBE_API_RESPONSE = requests.get('http://www.youtube.com/iframe_api') + @before.each_scenario def start_stubs(_): @@ -22,6 +24,8 @@ def start_stubs(_): """ 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) diff --git a/common/djangoapps/terrain/stubs/youtube.py b/common/djangoapps/terrain/stubs/youtube.py index 5e7a0de8ce35..15489c9fb892 100644 --- a/common/djangoapps/terrain/stubs/youtube.py +++ b/common/djangoapps/terrain/stubs/youtube.py @@ -80,7 +80,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 = requests.get('http://www.youtube.com/iframe_api') + response = self.server.config['youtube_api_response'] self.send_response(200, content=response.text, headers={'Content-type': 'text/html'}) else: diff --git a/lms/djangoapps/courseware/features/video.py b/lms/djangoapps/courseware/features/video.py index 35cf6fed2b49..fc1f41c49272 100644 --- a/lms/djangoapps/courseware/features/video.py +++ b/lms/djangoapps/courseware/features/video.py @@ -6,6 +6,7 @@ import os import time import requests +from nose.tools import assert_less from common import i_am_registered_for_the_course, visit_scenario_item from django.utils.translation import ugettext as _ from django.conf import settings @@ -159,6 +160,9 @@ 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)