Commit 411a13b5 by Muhammad Ammar

Convert lettuce video tests specifically using youtube stub

parent e25bbde4
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
Acceptance tests for Video. Acceptance tests for Video.
""" """
import json
import requests
from .helpers import UniqueCourseTest from .helpers import UniqueCourseTest
from ..pages.lms.video import VideoPage from ..pages.lms.video import VideoPage
from ..pages.lms.tab_nav import TabNavPage from ..pages.lms.tab_nav import TabNavPage
...@@ -13,6 +15,8 @@ from ..pages.lms.course_info import CourseInfoPage ...@@ -13,6 +15,8 @@ from ..pages.lms.course_info import CourseInfoPage
from ..fixtures.course import CourseFixture, XBlockFixtureDesc from ..fixtures.course import CourseFixture, XBlockFixtureDesc
VIDEO_SOURCE_PORT = 8777 VIDEO_SOURCE_PORT = 8777
YOUTUBE_STUB_PORT = 9080
YOUTUBE_STUB_URL = 'http://127.0.0.1:{}/'.format(YOUTUBE_STUB_PORT)
HTML5_SOURCES = [ HTML5_SOURCES = [
'http://localhost:{0}/gizmo.mp4'.format(VIDEO_SOURCE_PORT), 'http://localhost:{0}/gizmo.mp4'.format(VIDEO_SOURCE_PORT),
...@@ -25,6 +29,13 @@ HTML5_SOURCES_INCORRECT = [ ...@@ -25,6 +29,13 @@ HTML5_SOURCES_INCORRECT = [
] ]
class YouTubeConfigError(Exception):
"""
Error occurred while configuring YouTube Stub Server.
"""
pass
class VideoBaseTest(UniqueCourseTest): class VideoBaseTest(UniqueCourseTest):
""" """
Base class for tests of the Video Player Base class for tests of the Video Player
...@@ -50,6 +61,10 @@ class VideoBaseTest(UniqueCourseTest): ...@@ -50,6 +61,10 @@ class VideoBaseTest(UniqueCourseTest):
self.metadata = None self.metadata = None
self.assets = [] self.assets = []
self.verticals = None self.verticals = None
self.youtube_configuration = {}
# reset youtube stub server
self.addCleanup(self._reset_youtube_stub_server)
def navigate_to_video(self): def navigate_to_video(self):
""" Prepare the course and get to the video and render it """ """ Prepare the course and get to the video and render it """
...@@ -76,6 +91,9 @@ class VideoBaseTest(UniqueCourseTest): ...@@ -76,6 +91,9 @@ class VideoBaseTest(UniqueCourseTest):
self.course_fixture.add_children(chapter) self.course_fixture.add_children(chapter)
self.course_fixture.install() self.course_fixture.install()
if len(self.youtube_configuration) > 0:
self._configure_youtube_stub_server(self.youtube_configuration)
def _add_course_verticals(self): def _add_course_verticals(self):
""" """
Create XBlockFixtureDesc verticals Create XBlockFixtureDesc verticals
...@@ -126,6 +144,39 @@ class VideoBaseTest(UniqueCourseTest): ...@@ -126,6 +144,39 @@ class VideoBaseTest(UniqueCourseTest):
self._navigate_to_courseware_video() self._navigate_to_courseware_video()
self.video.wait_for_video_class() self.video.wait_for_video_class()
def _configure_youtube_stub_server(self, config):
"""
Allow callers to configure the stub server using the /set_config URL.
:param config: Configuration dictionary.
The request should have PUT data, such that:
Each PUT parameter is the configuration key.
Each PUT value is a JSON-encoded string value for the configuration.
:raise YouTubeConfigError:
"""
youtube_stub_config_url = YOUTUBE_STUB_URL + 'set_config'
config_data = {param: json.dumps(value) for param, value in config.items()}
response = requests.put(youtube_stub_config_url, data=config_data)
if not response.ok:
raise YouTubeConfigError(
'YouTube Server Configuration Failed. URL {0}, Configuration Data: {1}, Status was {2}'.format(
youtube_stub_config_url, config, response.status_code))
def _reset_youtube_stub_server(self):
"""
Reset YouTube Stub Server Configurations using the /del_config URL.
:raise YouTubeConfigError:
"""
youtube_stub_config_url = YOUTUBE_STUB_URL + 'del_config'
response = requests.delete(youtube_stub_config_url)
if not response.ok:
raise YouTubeConfigError(
'YouTube Server Configuration Failed. URL: {0} Status was {1}'.format(
youtube_stub_config_url, response.status_code))
def metadata_for_mode(self, player_mode, additional_data=None): def metadata_for_mode(self, player_mode, additional_data=None):
""" """
Create a dictionary for video player configuration according to `player_mode` Create a dictionary for video player configuration according to `player_mode`
...@@ -337,6 +388,55 @@ class YouTubeVideoTest(VideoBaseTest): ...@@ -337,6 +388,55 @@ class YouTubeVideoTest(VideoBaseTest):
# check if video aligned correctly without enabled transcript # check if video aligned correctly without enabled transcript
self.assertTrue(self.video.is_aligned(False)) self.assertTrue(self.video.is_aligned(False))
def test_video_rendering_with_default_response_time(self):
"""
Scenario: Video is rendered in Youtube mode when the YouTube Server responds quickly
Given the YouTube server response time less than 1.5 seconds
And the course has a Video component in "Youtube_HTML5" mode
Then the video has rendered in "Youtube" mode
"""
# configure youtube server
self.youtube_configuration['time_to_response'] = 0.4
self.metadata = self.metadata_for_mode('youtube_html5')
self.navigate_to_video()
self.assertTrue(self.video.is_video_rendered('youtube'))
def test_video_rendering_wo_default_response_time(self):
"""
Scenario: Video is rendered in HTML5 when the YouTube Server responds slowly
Given the YouTube server response time is greater than 1.5 seconds
And the course has a Video component in "Youtube_HTML5" mode
Then the video has rendered in "HTML5" mode
"""
# configure youtube server
self.youtube_configuration['time_to_response'] = 2.0
self.metadata = self.metadata_for_mode('youtube_html5')
self.navigate_to_video()
self.assertTrue(self.video.is_video_rendered('html5'))
def test_video_with_youtube_blocked(self):
"""
Scenario: Video is rendered in HTML5 mode when the YouTube API is blocked
Given the YouTube server response time is greater than 1.5 seconds
And the YouTube API is blocked
And the course has a Video component in "Youtube_HTML5" mode
Then the video has rendered in "HTML5" mode
"""
# configure youtube server
self.youtube_configuration.update({
'time_to_response': 2.0,
'youtube_api_blocked': True,
})
self.metadata = self.metadata_for_mode('youtube_html5')
self.navigate_to_video()
self.assertTrue(self.video.is_video_rendered('html5'))
class YouTubeHtml5VideoTest(VideoBaseTest): class YouTubeHtml5VideoTest(VideoBaseTest):
""" Test YouTube HTML5 Video Player """ """ Test YouTube HTML5 Video Player """
......
...@@ -9,27 +9,6 @@ Feature: LMS.Video component ...@@ -9,27 +9,6 @@ Feature: LMS.Video component
And all sources are correct And all sources are correct
# 2 # 2
# Youtube testing
Scenario: Video component is fully rendered in the LMS in Youtube mode with HTML5 sources
Given youtube server is up and response time is 0.4 seconds
And the course has a Video component in "Youtube_HTML5" mode
When the video has rendered in "Youtube" mode
# 3
Scenario: Video component is not rendered in the LMS in Youtube mode with HTML5 sources
Given youtube server is up and response time is 2 seconds
And the course has a Video component in "Youtube_HTML5" mode
When the video has rendered in "HTML5" mode
# 4
Scenario: Video component is not rendered in the LMS in Youtube mode with HTML5 sources when YouTube API is blocked
Given youtube server is up and response time is 2 seconds
And youtube stub server blocks YouTube API
And the course has a Video component in "Youtube_HTML5" mode
And I wait "3" seconds
Then the video has rendered in "HTML5" mode
# 5
Scenario: Multiple videos in sequentials all load and work, switching between sequentials Scenario: Multiple videos in sequentials all load and work, switching between sequentials
Given I am registered for the course "test_course" Given I am registered for the course "test_course"
And it has a video "A" in "Youtube" mode in position "1" of sequential And it has a video "A" in "Youtube" mode in position "1" of sequential
...@@ -51,7 +30,7 @@ Feature: LMS.Video component ...@@ -51,7 +30,7 @@ Feature: LMS.Video component
When I open video "A" When I open video "A"
Then video "A" should start playing at speed "2.0" Then video "A" should start playing at speed "2.0"
# 6 # 3
Scenario: Video component stores speed correctly when each video is in separate sequence Scenario: Video component stores speed correctly when each video is in separate sequence
Given I am registered for the course "test_course" Given I am registered for the course "test_course"
And it has a video "A" in "Youtube" mode in position "1" of sequential And it has a video "A" in "Youtube" mode in position "1" of sequential
...@@ -73,7 +52,7 @@ Feature: LMS.Video component ...@@ -73,7 +52,7 @@ Feature: LMS.Video component
When I open video "C" When I open video "C"
Then video "C" should start playing at speed "1.0" Then video "C" should start playing at speed "1.0"
# 7 # 4
Scenario: Language menu works correctly in Video component Scenario: Language menu works correctly in Video component
Given I am registered for the course "test_course" Given I am registered for the course "test_course"
And I have a "chinese_transcripts.srt" transcript file in assets And I have a "chinese_transcripts.srt" transcript file in assets
...@@ -88,7 +67,7 @@ Feature: LMS.Video component ...@@ -88,7 +67,7 @@ Feature: LMS.Video component
And I select language with code "en" And I select language with code "en"
And I see "Hi, welcome to Edx." text in the captions And I see "Hi, welcome to Edx." text in the captions
# 8 # 5
Scenario: Download Transcript button works correctly in Video component Scenario: Download Transcript button works correctly in Video component
Given I am registered for the course "test_course" Given I am registered for the course "test_course"
And I have a "subs_OEoXaMPEzfM.srt.sjson" transcript file in assets And I have a "subs_OEoXaMPEzfM.srt.sjson" transcript file in assets
...@@ -128,7 +107,7 @@ Feature: LMS.Video component ...@@ -128,7 +107,7 @@ Feature: LMS.Video component
# "1:56" is the duration in the VCR timer before the video plays. # "1:56" is the duration in the VCR timer before the video plays.
# And I see duration "1:56" # And I see duration "1:56"
# 9 # 6
Scenario: Verify that each video in each sub-section includes a transcript for non-Youtube countries Scenario: Verify that each video in each sub-section includes a transcript for non-Youtube countries
Given youtube server is up and response time is 2 seconds Given youtube server is up and response time is 2 seconds
And I am registered for the course "test_course" And I am registered for the course "test_course"
...@@ -169,7 +148,7 @@ Feature: LMS.Video component ...@@ -169,7 +148,7 @@ Feature: LMS.Video component
# And I click video button "play" # And I click video button "play"
# Then I see video slider at "0:10" position # Then I see video slider at "0:10" position
# 10 # 7
Scenario: End time works for Youtube video Scenario: End time works for Youtube video
Given I am registered for the course "test_course" Given I am registered for the course "test_course"
And it has a video in "Youtube" mode: And it has a video in "Youtube" mode:
...@@ -179,7 +158,7 @@ Feature: LMS.Video component ...@@ -179,7 +158,7 @@ Feature: LMS.Video component
And I wait "5" seconds And I wait "5" seconds
Then I see video slider at "0:02" position Then I see video slider at "0:02" position
# 11 # 8
Scenario: Youtube video with end-time at 1:00 and the video starts playing at 0:58 Scenario: Youtube video with end-time at 1:00 and the video starts playing at 0:58
Given I am registered for the course "test_course" Given I am registered for the course "test_course"
And it has a video in "Youtube" mode: And it has a video in "Youtube" mode:
...@@ -191,7 +170,7 @@ Feature: LMS.Video component ...@@ -191,7 +170,7 @@ Feature: LMS.Video component
And I wait "5" seconds And I wait "5" seconds
Then I see video slider at "1:00" position Then I see video slider at "1:00" position
# 12 # 9
Scenario: Start time and end time work together for Youtube video Scenario: Start time and end time work together for Youtube video
Given I am registered for the course "test_course" Given I am registered for the course "test_course"
And it has a video in "Youtube" mode: And it has a video in "Youtube" mode:
...@@ -202,7 +181,7 @@ Feature: LMS.Video component ...@@ -202,7 +181,7 @@ Feature: LMS.Video component
And I wait "5" seconds And I wait "5" seconds
Then I see video slider at "0:12" position Then I see video slider at "0:12" position
# 13 # 10
Scenario: Youtube video after pausing at end time video plays to the end from end time Scenario: Youtube video after pausing at end time video plays to the end from end time
Given I am registered for the course "test_course" Given I am registered for the course "test_course"
And it has a video in "Youtube" mode: And it has a video in "Youtube" mode:
...@@ -217,7 +196,7 @@ Feature: LMS.Video component ...@@ -217,7 +196,7 @@ Feature: LMS.Video component
# The default video length is 00:01:55. # The default video length is 00:01:55.
Then I see video slider at "1:55" position Then I see video slider at "1:55" position
# 14 # 11
Scenario: Youtube video with end-time at 0:32 and start-time at 0:30, the video starts playing from 0:28 Scenario: Youtube video with end-time at 0:32 and start-time at 0:30, the video starts playing from 0:28
Given I am registered for the course "test_course" Given I am registered for the course "test_course"
And it has a video in "Youtube" mode: And it has a video in "Youtube" mode:
...@@ -229,7 +208,7 @@ Feature: LMS.Video component ...@@ -229,7 +208,7 @@ Feature: LMS.Video component
And I wait "8" seconds And I wait "8" seconds
Then I see video slider at "0:32" position Then I see video slider at "0:32" position
# 15 # 12
Scenario: Youtube video with end-time at 1:00, the video starts playing from 1:52 Scenario: Youtube video with end-time at 1:00, the video starts playing from 1:52
Given I am registered for the course "test_course" Given I am registered for the course "test_course"
And it has a video in "Youtube" mode: And it has a video in "Youtube" mode:
...@@ -242,7 +221,7 @@ Feature: LMS.Video component ...@@ -242,7 +221,7 @@ Feature: LMS.Video component
# Video stops at the end. # Video stops at the end.
Then I see video slider at "1:55" position Then I see video slider at "1:55" position
# 16 # 13
@skip_firefox @skip_firefox
Scenario: Quality button appears on play Scenario: Quality button appears on play
Given the course has a Video component in "Youtube" mode Given the course has a Video component in "Youtube" mode
...@@ -250,7 +229,7 @@ Feature: LMS.Video component ...@@ -250,7 +229,7 @@ Feature: LMS.Video component
And I click video button "play" And I click video button "play"
Then I see video button "quality" is visible Then I see video button "quality" is visible
# 17 # 14
@skip_firefox @skip_firefox
Scenario: Quality button works correctly Scenario: Quality button works correctly
Given the course has a Video component in "Youtube" mode Given the course has a Video component in "Youtube" mode
......
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