Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alex/fix more flaky tests #3169

Merged
merged 1 commit into from
Apr 3, 2014
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
6 changes: 3 additions & 3 deletions cms/djangoapps/contentstore/features/video.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ 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"

# 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
Expand Down
12 changes: 6 additions & 6 deletions cms/djangoapps/contentstore/features/video.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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):
Expand Down
6 changes: 5 additions & 1 deletion common/djangoapps/terrain/start_stubs.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,6 +14,8 @@
"lti": {"port": settings.LTI_PORT, "class": StubLtiService},
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible not to use external service and mock this request?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need real youtube API to initialize videos. In case we will stub it, we need to update when youtube update it. And this is not possible.



@before.each_scenario
def start_stubs(_):
Expand All @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion common/djangoapps/terrain/stubs/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions lms/djangoapps/courseware/features/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down