python tests for videoalpha
This commit is contained in:
@@ -25,8 +25,8 @@ class BaseTestXmodule(ModuleStoreTestCase):
|
||||
"""Base class for testing Xmodules with mongo store.
|
||||
|
||||
This class prepares course and users for tests:
|
||||
1. create test course
|
||||
2. create, enrol and login users for this course
|
||||
1. create test course;
|
||||
2. create, enrol and login users for this course;
|
||||
|
||||
Any xmodule should overwrite only next parameters for test:
|
||||
1. TEMPLATE_NAME
|
||||
|
||||
54
lms/djangoapps/courseware/tests/test_videoalpha_mongo.py
Normal file
54
lms/djangoapps/courseware/tests/test_videoalpha_mongo.py
Normal file
@@ -0,0 +1,54 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Video xmodule tests in mongo."""
|
||||
|
||||
from . import BaseTestXmodule
|
||||
from .test_videoalpha_xml import SOURCE_XML
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class TestVideo(BaseTestXmodule):
|
||||
"""Integration tests: web client + mongo."""
|
||||
|
||||
TEMPLATE_NAME = "i4x://edx/templates/videoalpha/Video_Alpha"
|
||||
DATA = SOURCE_XML
|
||||
MODEL_DATA = {
|
||||
'data': DATA
|
||||
}
|
||||
|
||||
def test_handle_ajax_dispatch(self):
|
||||
responses = {
|
||||
user.username: self.clients[user.username].post(
|
||||
self.get_url('whatever'),
|
||||
{},
|
||||
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
for user in self.users
|
||||
}
|
||||
|
||||
self.assertEqual(
|
||||
set([
|
||||
response.status_code
|
||||
for _, response in responses.items()
|
||||
]).pop(),
|
||||
404)
|
||||
|
||||
def test_videoalpha_constructor(self):
|
||||
"""Make sure that all parameters extracted correclty from xml"""
|
||||
|
||||
# `get_html` return only context, cause we
|
||||
# overwrite `system.render_template`
|
||||
context = self.item_module.get_html()
|
||||
expected_context = {
|
||||
'data_dir': getattr(self, 'data_dir', None),
|
||||
'caption_asset_path': '/c4x/MITx/999/asset/subs_',
|
||||
'show_captions': self.item_module.show_captions,
|
||||
'display_name': self.item_module.display_name_with_default,
|
||||
'end': self.item_module.end_time,
|
||||
'id': self.item_module.location.html_id(),
|
||||
'sources': self.item_module.sources,
|
||||
'start': self.item_module.start_time,
|
||||
'sub': self.item_module.sub,
|
||||
'track': self.item_module.track,
|
||||
'youtube_streams': self.item_module.youtube_streams,
|
||||
'autoplay': settings.MITX_FEATURES.get('AUTOPLAY_VIDEOS', True)
|
||||
}
|
||||
self.assertDictEqual(context, expected_context)
|
||||
129
lms/djangoapps/courseware/tests/test_videoalpha_xml.py
Normal file
129
lms/djangoapps/courseware/tests/test_videoalpha_xml.py
Normal file
@@ -0,0 +1,129 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Test for VideoAlpha Xmodule functional logic.
|
||||
These tests data readed from xml, not from mongo.
|
||||
|
||||
We have a ModuleStoreTestCase class defined in
|
||||
common/lib/xmodule/xmodule/modulestore/tests/django_utils.py.
|
||||
You can search for usages of this in the cms and lms tests for examples.
|
||||
You use this so that it will do things like point the modulestore
|
||||
setting to mongo, flush the contentstore before and after, load the
|
||||
templates, etc.
|
||||
You can then use the CourseFactory and XModuleItemFactory as defined in
|
||||
common/lib/xmodule/xmodule/modulestore/tests/factories.py to create the
|
||||
course, section, subsection, unit, etc.
|
||||
"""
|
||||
|
||||
import json
|
||||
import unittest
|
||||
from mock import Mock
|
||||
from lxml import etree
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from xmodule.videoalpha_module import VideoAlphaDescriptor, VideoAlphaModule
|
||||
from xmodule.modulestore import Location
|
||||
from xmodule.tests import test_system
|
||||
from xmodule.tests.test_logic import LogicTest
|
||||
|
||||
|
||||
SOURCE_XML = """
|
||||
<videoalpha show_captions="true"
|
||||
youtube="0.75:jNCf2gIqpeE,1.0:ZwkTiUPN0mg,1.25:rsq9auxASqI,1.50:kMyNdzVHHgg"
|
||||
data_dir=""
|
||||
caption_asset_path=""
|
||||
autoplay="true"
|
||||
start_time="01:00:03" end_time="01:00:10"
|
||||
>
|
||||
<source src=".../mit-3091x/M-3091X-FA12-L21-3_100.mp4"/>
|
||||
<source src=".../mit-3091x/M-3091X-FA12-L21-3_100.webm"/>
|
||||
<source src=".../mit-3091x/M-3091X-FA12-L21-3_100.ogv"/>
|
||||
</videoalpha>
|
||||
"""
|
||||
|
||||
|
||||
class VideoAlphaFactory(object):
|
||||
"""A helper class to create videoalpha modules with various parameters
|
||||
for testing.
|
||||
"""
|
||||
|
||||
# tag that uses youtube videos
|
||||
sample_problem_xml_youtube = SOURCE_XML
|
||||
|
||||
@staticmethod
|
||||
def create():
|
||||
"""Method return VideoAlpha Xmodule instance."""
|
||||
location = Location(["i4x", "edX", "videoalpha", "default",
|
||||
"SampleProblem1"])
|
||||
model_data = {'data': VideoAlphaFactory.sample_problem_xml_youtube}
|
||||
|
||||
descriptor = Mock(weight="1")
|
||||
|
||||
system = test_system()
|
||||
system.render_template = lambda template, context: context
|
||||
VideoAlphaModule.location = location
|
||||
module = VideoAlphaModule(system, descriptor, model_data)
|
||||
|
||||
return module
|
||||
|
||||
|
||||
class VideoAlphaModuleTest(LogicTest):
|
||||
"""Tests for logic of VideoAlpha Xmodule."""
|
||||
|
||||
descriptor_class = VideoAlphaDescriptor
|
||||
|
||||
raw_model_data = {
|
||||
'data': '<videoalpha />'
|
||||
}
|
||||
|
||||
def test_get_timeframe_no_parameters(self):
|
||||
xmltree = etree.fromstring('<videoalpha>test</videoalpha>')
|
||||
output = self.xmodule.get_timeframe(xmltree)
|
||||
self.assertEqual(output, ('', ''))
|
||||
|
||||
def test_get_timeframe_with_one_parameter(self):
|
||||
xmltree = etree.fromstring(
|
||||
'<videoalpha start_time="00:04:07">test</videoalpha>'
|
||||
)
|
||||
output = self.xmodule.get_timeframe(xmltree)
|
||||
self.assertEqual(output, (247, ''))
|
||||
|
||||
def test_get_timeframe_with_two_parameters(self):
|
||||
xmltree = etree.fromstring(
|
||||
'''<videoalpha
|
||||
start_time="00:04:07"
|
||||
end_time="13:04:39"
|
||||
>test</videoalpha>'''
|
||||
)
|
||||
output = self.xmodule.get_timeframe(xmltree)
|
||||
self.assertEqual(output, (247, 47079))
|
||||
|
||||
|
||||
class VideoAlphaModuleUnitTest(unittest.TestCase):
|
||||
"""Unit tests for VideoAlpha Xmodule."""
|
||||
|
||||
def test_videoalpha_constructor(self):
|
||||
"""Make sure that all parameters extracted correclty from xml"""
|
||||
module = VideoAlphaFactory.create()
|
||||
|
||||
# `get_html` return only context, cause we
|
||||
# overwrite `system.render_template`
|
||||
context = module.get_html()
|
||||
expected_context = {
|
||||
'caption_asset_path': '/static/subs/',
|
||||
'sub': module.sub,
|
||||
'data_dir': getattr(self, 'data_dir', None),
|
||||
'display_name': module.display_name_with_default,
|
||||
'end': module.end_time,
|
||||
'start': module.start_time,
|
||||
'id': module.location.html_id(),
|
||||
'show_captions': module.show_captions,
|
||||
'sources': module.sources,
|
||||
'youtube_streams': module.youtube_streams,
|
||||
'track': module.track,
|
||||
'autoplay': settings.MITX_FEATURES.get('AUTOPLAY_VIDEOS', True)
|
||||
}
|
||||
self.assertDictEqual(context, expected_context)
|
||||
|
||||
self.assertDictEqual(
|
||||
json.loads(module.get_instance_state()),
|
||||
{'position': 0})
|
||||
Reference in New Issue
Block a user