From f444d9b5e7245ca636fa1635b6f19fafbec517d1 Mon Sep 17 00:00:00 2001 From: marjev Date: Mon, 9 Feb 2015 14:31:01 +0100 Subject: [PATCH] Updated unit tests for video module --- .../lib/xmodule/xmodule/tests/test_video.py | 185 ++++++++++-------- 1 file changed, 100 insertions(+), 85 deletions(-) diff --git a/common/lib/xmodule/xmodule/tests/test_video.py b/common/lib/xmodule/xmodule/tests/test_video.py index 1daad04580..98969a7282 100644 --- a/common/lib/xmodule/xmodule/tests/test_video.py +++ b/common/lib/xmodule/xmodule/tests/test_video.py @@ -29,7 +29,6 @@ from xmodule.tests import get_test_descriptor_system from xmodule.video_module.transcripts_utils import download_youtube_subs, save_to_store from django.conf import settings -from django.test.utils import override_settings SRT_FILEDATA = ''' 0 @@ -51,38 +50,29 @@ Dobar dan! Kako ste danas? ''' - -TEST_YOU_TUBE_SETTINGS = { - # YouTube JavaScript API - 'API': 'www.youtube.com/iframe_api', - - # URL to test YouTube availability - 'TEST_URL': 'gdata.youtube.com/feeds/api/videos/', - - # Current youtube api for requesting transcripts. - # For example: http://video.google.com/timedtext?lang=en&v=j_jEn79vS3g. - 'TEXT_API': { - 'url': 'video.google.com/timedtext', - 'params': { - 'lang': 'en', - 'v': 'set_youtube_id_of_11_symbols_here', - }, - }, -} - -TEST_DATA_CONTENTSTORE = { - 'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore', - 'DOC_STORE_CONFIG': { - 'host': 'localhost', - 'db': 'test_xcontent_%s' % uuid4().hex, - }, - # allow for additional options that can be keyed on a name, e.g. 'trashcan' - 'ADDITIONAL_OPTIONS': { - 'trashcan': { - 'bucket': 'trash_fs' - } - } -} +YOUTUBE_SUBTITLES = ( + "LILA FISHER: Hi, welcome to Edx. I'm Lila Fisher, an Edx fellow helping to put together these" + " courses. As you know, our courses are entirely online. So before we start learning about the" + " subjects that brought you here, let's learn about the tools that you will use to navigate through" + " the course material. Let's start with what is on your screen right now. You are watching a video" + " of me talking. You have several tools associated with these videos. Some of them are standard" + " video buttons, like the play Pause Button on the bottom left. Like most video players, you can see" + " how far you are into this particular video segment and how long the entire video segment is." + " Something that you might not be used to is the speed option. While you are going through the" + " videos, you can speed up or slow down the video player with these buttons. Go ahead and try that" + " now. Make me talk faster and slower. If you ever get frustrated by the pace of speech, you can" + " adjust it this way. Another great feature is the transcript on the side. This will follow along" + " with everything that I am saying as I am saying it, so you can read along if you like. You can" + " also click on any of the words, and you will notice that the video jumps to that word. The video" + " slider at the bottom of the video will let you navigate through the video quickly. If you ever" + " find the transcript distracting, you can toggle the captioning button in order to make it go away" + " or reappear. Now that you know about the video player, I want to point out the sequence navigator." + " Right now you're in a lecture sequence, which interweaves many videos and practice exercises. You" + " can see how far you are in a particular sequence by observing which tab you're on. You can" + " navigate directly to any video or exercise by clicking on the appropriate tab. You can also" + " progress to the next element by pressing the Arrow button, or by clicking on the next tab. Try" + " that now. The tutorial will continue in the next video." +) def instantiate_descriptor(**field_data): @@ -130,7 +120,6 @@ class VideoModuleTest(LogicTest): def test_parse_youtube_invalid(self): """Ensure that ids that are invalid return an empty dict""" - # invalid id youtube_str = 'thisisaninvalidid' output = VideoDescriptor._parse_youtube(youtube_str) @@ -183,7 +172,6 @@ class VideoDescriptorTestBase(unittest.TestCase): """ Base class for tests for VideoDescriptor """ - def setUp(self): super(VideoDescriptorTestBase, self).setUp() self.descriptor = instantiate_descriptor() @@ -646,14 +634,70 @@ class VideoCdnTest(unittest.TestCase): self.assertIsNone(get_video_from_cdn(fake_cdn_url, original_video_url)) -@override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE) -@override_settings(YOUTUBE=TEST_YOU_TUBE_SETTINGS) class VideoDescriptorIndexingTestCase(unittest.TestCase): """ Make sure that VideoDescriptor can format data for indexing as expected. """ + def setUp(self): + """ + Overrides YOUTUBE and CONTENTSTORE settings + """ + self.youtube_setting = getattr(settings, "YOUTUBE", None) + self.contentstore_setting = getattr(settings, "CONTENTSTORE", None) + settings.YOUTUBE = { + # YouTube JavaScript API + 'API': 'www.youtube.com/iframe_api', - def test_index_dictionary(self): + # URL to test YouTube availability + 'TEST_URL': 'gdata.youtube.com/feeds/api/videos/', + + # Current youtube api for requesting transcripts. + # For example: http://video.google.com/timedtext?lang=en&v=j_jEn79vS3g. + 'TEXT_API': { + 'url': 'video.google.com/timedtext', + 'params': { + 'lang': 'en', + 'v': 'set_youtube_id_of_11_symbols_here', + }, + }, + } + + settings.CONTENTSTORE = { + 'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore', + 'DOC_STORE_CONFIG': { + 'host': 'localhost', + 'db': 'test_xcontent_%s' % uuid4().hex, + }, + # allow for additional options that can be keyed on a name, e.g. 'trashcan' + 'ADDITIONAL_OPTIONS': { + 'trashcan': { + 'bucket': 'trash_fs' + } + } + } + + self.addCleanup(self.cleanup) + + def cleanup(self): + """ + Returns YOUTUBE and CONTENTSTORE settings to a default value + """ + if self.youtube_setting: + settings.YOUTUBE = self.youtube_setting + self.youtube_setting = None + else: + del settings.YOUTUBE + + if self.contentstore_setting: + settings.CONTENTSTORE = self.contentstore_setting + self.contentstore_setting = None + else: + del settings.CONTENTSTORE + + def test_video_with_no_subs_index_dictionary(self): + """ + Test index dictionary of a video module without subtitles. + """ xml_data = '''