From 615ce23930c17746a30cb7642f3bfecd3ed320e0 Mon Sep 17 00:00:00 2001 From: Valera Rozuvan Date: Fri, 11 Apr 2014 08:23:46 +0000 Subject: [PATCH] Update acceptance tests to use real duration of YouTube video. --- common/djangoapps/terrain/stubs/tests/test_youtube_stub.py | 6 +++++- common/djangoapps/terrain/stubs/youtube.py | 7 ++++++- lms/djangoapps/courseware/features/video.feature | 5 ++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/common/djangoapps/terrain/stubs/tests/test_youtube_stub.py b/common/djangoapps/terrain/stubs/tests/test_youtube_stub.py index 7a6b617a95..e2603a82fe 100644 --- a/common/djangoapps/terrain/stubs/tests/test_youtube_stub.py +++ b/common/djangoapps/terrain/stubs/tests/test_youtube_stub.py @@ -24,7 +24,11 @@ class StubYouTubeServiceTest(unittest.TestCase): self.url + 'test_youtube/OEoXaMPEzfM?v=2&alt=jsonc&callback=callback_func' ) - self.assertEqual('callback_func({"data": {"duration": 60, "message": "I\'m youtube.", "id": "OEoXaMPEzfM"}})', response.content) + # YouTube metadata for video `OEoXaMPEzfM` states that duration is 116. + self.assertEqual( + 'callback_func({"data": {"duration": 116, "message": "I\'m youtube.", "id": "OEoXaMPEzfM"}})', + response.content + ) def test_transcript_url_equal(self): response = requests.get( diff --git a/common/djangoapps/terrain/stubs/youtube.py b/common/djangoapps/terrain/stubs/youtube.py index 15489c9fb8..a5b5db8644 100644 --- a/common/djangoapps/terrain/stubs/youtube.py +++ b/common/djangoapps/terrain/stubs/youtube.py @@ -98,11 +98,16 @@ class StubYouTubeHandler(StubHttpRequestHandler): # Construct the response content callback = self.get_params['callback'] + youtube_metadata = json.loads( + requests.get( + "http://gdata.youtube.com/feeds/api/videos/{id}?v=2&alt=jsonc".format(id=youtube_id) + ).text + ) data = OrderedDict({ 'data': OrderedDict({ 'id': youtube_id, 'message': message, - 'duration': 60 if youtube_id == 'OEoXaMPEzfM' else 77, + 'duration': youtube_metadata['data']['duration'], }) }) response = "{cb}({data})".format(cb=callback, data=json.dumps(data)) diff --git a/lms/djangoapps/courseware/features/video.feature b/lms/djangoapps/courseware/features/video.feature index d1a9e78911..e4b2972e78 100644 --- a/lms/djangoapps/courseware/features/video.feature +++ b/lms/djangoapps/courseware/features/video.feature @@ -185,7 +185,10 @@ Feature: LMS.Video component And I select the "1.50" speed And I reload the page with video Then I see "Hi, welcome to Edx." text in the captions - And I see duration "1:00" + # The 1:56 time is the duration from metadata. 1:54 time is the duration reported + # by the video API once the video starts playing. The next step is correct because + # "1:56" is the duration in the VCR timer before the video plays. + And I see duration "1:56" # 15 Scenario: Download button works correctly for non-english transcript in Youtube mode of Video component