Commit ba673f8f by muhammad-ammar

Merge pull request #3949 from edx/ammar/improve-lettuce-youtube-availability-check

Lettuce YouTube Check Improvements
parents ba0bad1d 84ac5628
...@@ -15,6 +15,9 @@ from terrain.stubs.video_source import VideoSourceHttpService ...@@ -15,6 +15,9 @@ from terrain.stubs.video_source import VideoSourceHttpService
import re import re
import requests import requests
from logging import getLogger
LOGGER = getLogger(__name__)
SERVICES = { SERVICES = {
"youtube": {"port": settings.YOUTUBE_PORT, "class": StubYouTubeService}, "youtube": {"port": settings.YOUTUBE_PORT, "class": StubYouTubeService},
...@@ -77,7 +80,9 @@ def process_requires_tags(scenario): ...@@ -77,7 +80,9 @@ def process_requires_tags(scenario):
if requires: if requires:
if requires.group('server') == 'youtube': 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 return
start_stub(requires.group('server')) start_stub(requires.group('server'))
...@@ -96,21 +101,22 @@ def start_stub(name): ...@@ -96,21 +101,22 @@ def start_stub(name):
setattr(world, name, fake_server) setattr(world, name, fake_server)
def is_youtube_available(scenario, urls): def is_youtube_available(urls):
""" """
Check if the required youtube urls are available. Check if the required youtube urls are available.
If they are not, then skip the scenario. If they are not, then skip the scenario.
""" """
for name, url in urls.iteritems(): for name, url in urls.iteritems():
try:
response = requests.get(url, allow_redirects=False) response = requests.get(url, allow_redirects=False)
status = response.status_code except requests.exceptions.ConnectionError:
if status != 200: LOGGER.warning("Connection Error. YouTube {0} service not available. Skipping this test.".format(name))
print "ERROR: YouTube {0} service not available. Status code: {1}".format( return False
name, status)
# This is a hackish way to skip a test in lettuce as there is status = response.status_code
# no proper way to skip a test conditionally if status >= 300:
scenario.steps = [] LOGGER.warning(
"YouTube {0} service not available. Status code: {1}. Skipping this test.".format(name, status))
# No need to check all the URLs # No need to check all the URLs
return False return False
......
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