Commit cf3e2c86 by Alexander Kryklia

Fix flaky video tests: speed up youtube api loading and wait for controls.

parent fab43e1a
...@@ -5,7 +5,7 @@ Feature: CMS Video Component ...@@ -5,7 +5,7 @@ Feature: CMS Video Component
# 1 # 1
Scenario: YouTube stub server proxies YouTube API correctly Scenario: YouTube stub server proxies YouTube API correctly
Given youtube stub server proxies YouTube API 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" Then I can see video button "play"
And I click video button "play" And I click video button "play"
Then I can see video button "pause" Then I can see video button "pause"
...@@ -13,8 +13,8 @@ Feature: CMS Video Component ...@@ -13,8 +13,8 @@ Feature: CMS Video Component
# 2 # 2
Scenario: YouTube stub server can block YouTube API Scenario: YouTube stub server can block YouTube API
Given youtube stub server blocks YouTube API Given youtube stub server blocks YouTube API
Given I have created a Video component And I have created a Video component
Given We explicitly wait for YouTube API to not load And I wait for "3" seconds
Then I do not see video button "play" Then I do not see video button "play"
# 3 # 3
......
# pylint: disable=C0111 # pylint: disable=C0111
from lettuce import world, step from lettuce import world, step
from nose.tools import assert_less
from xmodule.modulestore import Location from xmodule.modulestore import Location
from contentstore.utils import get_modulestore from contentstore.utils import get_modulestore
from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.keys import Keys
...@@ -32,13 +33,11 @@ def configure_youtube_api(_step, action): ...@@ -32,13 +33,11 @@ def configure_youtube_api(_step, action):
raise ValueError('Parameter `action` should be one of "proxies" or "blocks".') 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$') @step('I have created a Video component$')
def i_created_a_video_component(_step): 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_course_with_unit()
world.create_component_instance( world.create_component_instance(
step=_step, step=_step,
...@@ -51,7 +50,8 @@ def i_created_a_video_component(_step): ...@@ -51,7 +50,8 @@ def i_created_a_video_component(_step):
world.wait_for_present('.is-initialized') world.wait_for_present('.is-initialized')
world.wait(DELAY) world.wait(DELAY)
world.wait_for_invisible(SELECTORS['spinner']) 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$') @step('I have created a Video component with subtitles$')
def i_created_a_video_with_subs(_step): def i_created_a_video_with_subs(_step):
......
""" """
Initialize and teardown fake HTTP services for use in acceptance tests. Initialize and teardown fake HTTP services for use in acceptance tests.
""" """
import requests
from lettuce import before, after, world from lettuce import before, after, world
from django.conf import settings from django.conf import settings
from terrain.stubs.youtube import StubYouTubeService from terrain.stubs.youtube import StubYouTubeService
...@@ -14,6 +14,8 @@ SERVICES = { ...@@ -14,6 +14,8 @@ SERVICES = {
"lti": {"port": settings.LTI_PORT, "class": StubLtiService}, "lti": {"port": settings.LTI_PORT, "class": StubLtiService},
} }
YOUTUBE_API_RESPONSE = requests.get('http://www.youtube.com/iframe_api')
@before.each_scenario @before.each_scenario
def start_stubs(_): def start_stubs(_):
...@@ -22,6 +24,8 @@ def start_stubs(_): ...@@ -22,6 +24,8 @@ def start_stubs(_):
""" """
for name, service in SERVICES.iteritems(): for name, service in SERVICES.iteritems():
fake_server = service['class'](port_num=service['port']) 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) setattr(world, name, fake_server)
......
...@@ -80,7 +80,7 @@ class StubYouTubeHandler(StubHttpRequestHandler): ...@@ -80,7 +80,7 @@ class StubYouTubeHandler(StubHttpRequestHandler):
if self.server.config.get('youtube_api_blocked'): if self.server.config.get('youtube_api_blocked'):
self.send_response(404, content='', headers={'Content-type': 'text/plain'}) self.send_response(404, content='', headers={'Content-type': 'text/plain'})
else: 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'}) self.send_response(200, content=response.text, headers={'Content-type': 'text/html'})
else: else:
......
...@@ -6,6 +6,7 @@ import json ...@@ -6,6 +6,7 @@ import json
import os import os
import time import time
import requests import requests
from nose.tools import assert_less
from common import i_am_registered_for_the_course, visit_scenario_item from common import i_am_registered_for_the_course, visit_scenario_item
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.conf import settings from django.conf import settings
...@@ -159,6 +160,9 @@ def add_videos_to_course(course, player_mode=None, display_names=None, hashes=No ...@@ -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'): 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: if not parent_location:
parent_location = add_vertical_to_course(course) parent_location = add_vertical_to_course(course)
kwargs = get_metadata(parent_location, player_mode, data, display_name=display_name) kwargs = get_metadata(parent_location, player_mode, data, display_name=display_name)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment