From b25710346f44c3e0bdbc69928eba39fc8abc3106 Mon Sep 17 00:00:00 2001 From: Vasyl Nakvasiuk Date: Thu, 30 May 2013 11:22:20 +0300 Subject: [PATCH] add python video tests --- lms/djangoapps/courseware/tests/__init__.py | 97 +++++++++++++ .../courseware/tests/test_video_mongo.py | 49 +++++++ .../courseware/tests/test_video_xml.py | 137 ++++++++++++++++++ 3 files changed, 283 insertions(+) create mode 100644 lms/djangoapps/courseware/tests/test_video_mongo.py create mode 100644 lms/djangoapps/courseware/tests/test_video_xml.py diff --git a/lms/djangoapps/courseware/tests/__init__.py b/lms/djangoapps/courseware/tests/__init__.py index e69de29bb2..dd3c4dc2b3 100644 --- a/lms/djangoapps/courseware/tests/__init__.py +++ b/lms/djangoapps/courseware/tests/__init__.py @@ -0,0 +1,97 @@ +""" +integration tests for xmodule + +Contains: + + 1. BaseTestXmodule class provides course and users + for testing Xmodules with mongo store. +""" + +from django.test.utils import override_settings +from django.core.urlresolvers import reverse +from django.test.client import Client + +from student.tests.factories import UserFactory, CourseEnrollmentFactory +from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE +from xmodule.modulestore import Location +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase + + +@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +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 + + Any xmodule should overwrite only next parameters for test: + 1. TEMPLATE_NAME + 2. DATA + 3. COURSE_DATA and USER_COUNT if needed + + This class should not contain any tests, because TEMPLATE_NAME + should be defined in child class. + """ + USER_COUNT = 2 + COURSE_DATA = {} + + # Data from YAML common/lib/xmodule/xmodule/templates/NAME/default.yaml + TEMPLATE_NAME = "" + DATA = {} + + def setUp(self): + + self.course = CourseFactory.create(data=self.COURSE_DATA) + + # Turn off cache. + modulestore().request_cache = None + modulestore().metadata_inheritance_cache_subsystem = None + + chapter = ItemFactory.create( + parent_location=self.course.location, + template="i4x://edx/templates/sequential/Empty", + ) + section = ItemFactory.create( + parent_location=chapter.location, + template="i4x://edx/templates/sequential/Empty" + ) + + # username = robot{0}, password = 'test' + self.users = [ + UserFactory.create(username='robot%d' % i, email='robot+test+%d@edx.org' % i) + for i in range(self.USER_COUNT) + ] + + for user in self.users: + CourseEnrollmentFactory.create(user=user, course_id=self.course.id) + + item = ItemFactory.create( + parent_location=section.location, + template=self.TEMPLATE_NAME, + data=self.DATA + ) + self.item_url = Location(item.location).url() + + # login all users for acces to Xmodule + self.clients = {user.username: Client() for user in self.users} + self.login_statuses = [ + self.clients[user.username].login( + username=user.username, password='test') + for user in self.users + ] + + self.assertTrue(all(self.login_statuses)) + + def get_url(self, dispatch): + """Return word cloud url with dispatch.""" + return reverse( + 'modx_dispatch', + args=(self.course.id, self.item_url, dispatch) + ) + + def tearDown(self): + for user in self.users: + user.delete() diff --git a/lms/djangoapps/courseware/tests/test_video_mongo.py b/lms/djangoapps/courseware/tests/test_video_mongo.py new file mode 100644 index 0000000000..f979ae2686 --- /dev/null +++ b/lms/djangoapps/courseware/tests/test_video_mongo.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +"""Video xmodule tests in mongo.""" + +import json + +from . import BaseTestXmodule + + +class TestVideo(BaseTestXmodule): + """Integration tests: web client + mongo.""" + + TEMPLATE_NAME = "i4x://edx/templates/video/default" + DATA = '