From 74f3595d545d95ca0cf2413dd3cc5bdbef99556a Mon Sep 17 00:00:00 2001 From: Anton Stupak Date: Mon, 12 Aug 2013 14:14:28 +0300 Subject: [PATCH] Add acceptance tests for checking rendering. --- cms/envs/common.py | 3 -- .../courseware/features/video.feature | 14 ++++- lms/djangoapps/courseware/features/video.py | 53 ++++++++++++++++--- lms/envs/acceptance.py | 4 -- lms/envs/acceptance_static.py | 4 -- lms/envs/common.py | 2 - lms/templates/video.html | 12 ++--- 7 files changed, 62 insertions(+), 30 deletions(-) diff --git a/cms/envs/common.py b/cms/envs/common.py index 40084c20ae..9cdd7a4410 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -39,9 +39,6 @@ MITX_FEATURES = { 'AUTH_USE_MIT_CERTIFICATES': False, - # do not display video when running automated acceptance tests - 'STUB_VIDEO_FOR_TESTING': False, - # email address for studio staff (eg to request course creation) 'STUDIO_REQUEST_EMAIL': '', diff --git a/lms/djangoapps/courseware/features/video.feature b/lms/djangoapps/courseware/features/video.feature index bffba97cf5..74cd9cbcbb 100644 --- a/lms/djangoapps/courseware/features/video.feature +++ b/lms/djangoapps/courseware/features/video.feature @@ -1,6 +1,16 @@ Feature: Video component As a student, I want to view course videos in LMS. + + Scenario: Video component is fully rendered in the LMS in HTML5 mode + Given the course has a Video component in HTML5 mode + Then when I view the video it has rendered in HTML5 mode + And all sources are correct + + Scenario: Video component is fully rendered in the LMS in Youtube mode + Given the course has a Video component in Youtube mode + Then when I view the video it has rendered in Youtube mode + Scenario: Autoplay is enabled in LMS for a Video component - Given the course has a Video component - Then when I view the video it has autoplay enabled + Given the course has a Video component in HTML5 mode + Then when I view the video it has autoplay enabled \ No newline at end of file diff --git a/lms/djangoapps/courseware/features/video.py b/lms/djangoapps/courseware/features/video.py index 21993d0f63..b546669803 100644 --- a/lms/djangoapps/courseware/features/video.py +++ b/lms/djangoapps/courseware/features/video.py @@ -6,19 +6,24 @@ from common import i_am_registered_for_the_course, section_location ############### ACTIONS #################### +HTML5_SOURCES = [ + 'https://s3.amazonaws.com/edx-course-videos/edx-intro/edX-FA12-cware-1_100.mp4', + 'https://s3.amazonaws.com/edx-course-videos/edx-intro/edX-FA12-cware-1_100.webm', + 'https://s3.amazonaws.com/edx-course-videos/edx-intro/edX-FA12-cware-1_100.ogv' +] @step('when I view the (.*) it has autoplay enabled') def does_autoplay_video(_step, video_type): assert(world.css_find('.%s' % video_type)[0]['data-autoplay'] == 'True') -@step('the course has a Video component') -def view_video(_step): +@step('the course has a Video component in (.*) mode') +def view_video(_step, player_mode): coursenum = 'test_course' i_am_registered_for_the_course(step, coursenum) # Make sure we have a video - add_video_to_course(coursenum) + add_video_to_course(coursenum, player_mode.lower()) chapter_name = world.scenario_dict['SECTION'].display_name.replace(" ", "_") section_name = chapter_name url = django_url('/courses/%s/%s/%s/courseware/%s/%s' % @@ -27,9 +32,43 @@ def view_video(_step): world.browser.visit(url) -def add_video_to_course(course): - world.ItemFactory.create(parent_location=section_location(course), - category='video', - display_name='Video') +def add_video_to_course(course, player_mode): + category = 'video' + + kwargs = { + 'parent_location': section_location(course), + 'category': category, + 'display_name': 'Video' + } + + if player_mode == 'html5': + kwargs.update({ + 'metadata': { + 'youtube_id_1_0': '', + 'youtube_id_0_75': '', + 'youtube_id_1_25': '', + 'youtube_id_1_5': '', + 'html5_sources': HTML5_SOURCES + } + }) + + world.ItemFactory.create(**kwargs) + + +@step('when I view the video it has rendered in (.*) mode') +def video_is_rendered(_step, mode): + modes = { + 'html5': 'video', + 'youtube': 'iframe' + } + if mode.lower() in modes: + assert world.css_find('.video {0}'.format(modes[mode.lower()])).first + else: + assert False + +@step('all sources are correct') +def all_sources_are_correct(_step): + sources = world.css_find('.video video source') + assert set(source['src'] for source in sources) == set(HTML5_SOURCES) diff --git a/lms/envs/acceptance.py b/lms/envs/acceptance.py index a58420ab1e..e9ac9762c2 100644 --- a/lms/envs/acceptance.py +++ b/lms/envs/acceptance.py @@ -75,10 +75,6 @@ XQUEUE_INTERFACE = { "basic_auth": ('anant', 'agarwal'), } -# Do not display the YouTube videos in the browser while running the -# acceptance tests. This makes them faster and more reliable -MITX_FEATURES['STUB_VIDEO_FOR_TESTING'] = True - # Forums are disabled in test.py to speed up unit tests, but we do not have # per-test control for acceptance tests MITX_FEATURES['ENABLE_DISCUSSION_SERVICE'] = True diff --git a/lms/envs/acceptance_static.py b/lms/envs/acceptance_static.py index 5672ea5bf5..27efb6160d 100644 --- a/lms/envs/acceptance_static.py +++ b/lms/envs/acceptance_static.py @@ -70,10 +70,6 @@ XQUEUE_INTERFACE = { "basic_auth": ('anant', 'agarwal'), } -# Do not display the YouTube videos in the browser while running the -# acceptance tests. This makes them faster and more reliable -MITX_FEATURES['STUB_VIDEO_FOR_TESTING'] = True - # Include the lettuce app for acceptance testing, including the 'harvest' django-admin command INSTALLED_APPS += ('lettuce.django',) LETTUCE_APPS = ('courseware',) diff --git a/lms/envs/common.py b/lms/envs/common.py index 0cbcbb774a..8734288598 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -86,8 +86,6 @@ MITX_FEATURES = { 'DISABLE_LOGIN_BUTTON': False, # used in systems where login is automatic, eg MIT SSL - 'STUB_VIDEO_FOR_TESTING': False, # do not display video when running automated acceptance tests - # extrernal access methods 'ACCESS_REQUIRE_STAFF_FOR_COURSE': False, 'AUTH_USE_OPENID': False, diff --git a/lms/templates/video.html b/lms/templates/video.html index f5f8ed29c6..ab3fd08d0c 100644 --- a/lms/templates/video.html +++ b/lms/templates/video.html @@ -8,18 +8,14 @@ id="video_${id}" class="video" - % if not settings.MITX_FEATURES['STUB_VIDEO_FOR_TESTING']: - data-streams="${youtube_streams}" - % endif + data-streams="${youtube_streams}" ${'data-sub="{}"'.format(sub) if sub else ''} ${'data-autoplay="{}"'.format(autoplay) if autoplay else ''} - % if not settings.MITX_FEATURES['STUB_VIDEO_FOR_TESTING']: - ${'data-mp4-source="{}"'.format(sources.get('mp4')) if sources.get('mp4') else ''} - ${'data-webm-source="{}"'.format(sources.get('webm')) if sources.get('webm') else ''} - ${'data-ogg-source="{}"'.format(sources.get('ogv')) if sources.get('ogv') else ''} - % endif + ${'data-mp4-source="{}"'.format(sources.get('mp4')) if sources.get('mp4') else ''} + ${'data-webm-source="{}"'.format(sources.get('webm')) if sources.get('webm') else ''} + ${'data-ogg-source="{}"'.format(sources.get('ogv')) if sources.get('ogv') else ''} data-caption-data-dir="${data_dir}" data-show-captions="${show_captions}"