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

Lettuce YouTube Check Improvements #3949

Merged
Merged
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
26 changes: 16 additions & 10 deletions common/djangoapps/terrain/setup_prereqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import re
import requests

from logging import getLogger

LOGGER = getLogger(__name__)

SERVICES = {
"youtube": {"port": settings.YOUTUBE_PORT, "class": StubYouTubeService},
Expand Down Expand Up @@ -77,7 +80,9 @@ def process_requires_tags(scenario):

if requires:
if requires.group('server') == 'youtube':
if not is_youtube_available(scenario, YOUTUBE_API_URLS):
if not is_youtube_available(YOUTUBE_API_URLS):
# A hackish way to skip a test in lettuce as there is no proper way to skip a test conditionally
scenario.steps = []
return

start_stub(requires.group('server'))
Expand All @@ -96,21 +101,22 @@ def start_stub(name):
setattr(world, name, fake_server)


def is_youtube_available(scenario, urls):
def is_youtube_available(urls):
"""
Check if the required youtube urls are available.
If they are not, then skip the scenario.
"""
for name, url in urls.iteritems():
response = requests.get(url, allow_redirects=False)
status = response.status_code
if status != 200:
print "ERROR: YouTube {0} service not available. Status code: {1}".format(
name, status)
try:
response = requests.get(url, allow_redirects=False)
except requests.exceptions.ConnectionError:
LOGGER.warning("Connection Error. YouTube {0} service not available. Skipping this test.".format(name))
return False

# This is a hackish way to skip a test in lettuce as there is
# no proper way to skip a test conditionally
scenario.steps = []
status = response.status_code
if status >= 300:
LOGGER.warning(
"YouTube {0} service not available. Status code: {1}. Skipping this test.".format(name, status))

# No need to check all the URLs
return False
Expand Down