From d0e3f99e775652b3d943408f2b5d5e96e19dc522 Mon Sep 17 00:00:00 2001 From: Vasyl Nakvasiuk Date: Mon, 3 Jun 2013 14:31:26 +0300 Subject: [PATCH] BaseTestXmodule: create module on the fly --- lms/djangoapps/courseware/tests/__init__.py | 21 ++++++++++++++----- .../courseware/tests/test_video_xml.py | 4 ++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lms/djangoapps/courseware/tests/__init__.py b/lms/djangoapps/courseware/tests/__init__.py index dd3c4dc2b3..dc61239c36 100644 --- a/lms/djangoapps/courseware/tests/__init__.py +++ b/lms/djangoapps/courseware/tests/__init__.py @@ -13,6 +13,7 @@ from django.test.client import Client from student.tests.factories import UserFactory, CourseEnrollmentFactory from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE +from xmodule.tests import test_system from xmodule.modulestore import Location from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory @@ -30,7 +31,8 @@ class BaseTestXmodule(ModuleStoreTestCase): Any xmodule should overwrite only next parameters for test: 1. TEMPLATE_NAME 2. DATA - 3. COURSE_DATA and USER_COUNT if needed + 3. MODEL_DATA + 4. COURSE_DATA and USER_COUNT if needed This class should not contain any tests, because TEMPLATE_NAME should be defined in child class. @@ -40,7 +42,8 @@ class BaseTestXmodule(ModuleStoreTestCase): # Data from YAML common/lib/xmodule/xmodule/templates/NAME/default.yaml TEMPLATE_NAME = "" - DATA = {} + DATA = '' + MODEL_DATA = {'data': ''} def setUp(self): @@ -68,12 +71,20 @@ class BaseTestXmodule(ModuleStoreTestCase): for user in self.users: CourseEnrollmentFactory.create(user=user, course_id=self.course.id) - item = ItemFactory.create( + self.item_descriptor = ItemFactory.create( parent_location=section.location, template=self.TEMPLATE_NAME, data=self.DATA ) - self.item_url = Location(item.location).url() + + location = self.item_descriptor.location + system = test_system() + system.render_template = lambda template, context: context + + self.item_module = self.item_descriptor.module_class( + system, location, self.item_descriptor, self.MODEL_DATA + ) + self.item_url = Location(location).url() # login all users for acces to Xmodule self.clients = {user.username: Client() for user in self.users} @@ -86,7 +97,7 @@ class BaseTestXmodule(ModuleStoreTestCase): self.assertTrue(all(self.login_statuses)) def get_url(self, dispatch): - """Return word cloud url with dispatch.""" + """Return item url with dispatch.""" return reverse( 'modx_dispatch', args=(self.course.id, self.item_url, dispatch) diff --git a/lms/djangoapps/courseware/tests/test_video_xml.py b/lms/djangoapps/courseware/tests/test_video_xml.py index 9b4b1d52d2..c199a0aee1 100644 --- a/lms/djangoapps/courseware/tests/test_video_xml.py +++ b/lms/djangoapps/courseware/tests/test_video_xml.py @@ -46,7 +46,7 @@ class VideoFactory(object): def create(): """Method return Video Xmodule instance.""" location = Location(["i4x", "edX", "video", "default", - "SampleProblem{0}".format(1)]) + "SampleProblem1"]) model_data = {'data': VideoFactory.sample_problem_xml_youtube} descriptor = Mock(weight="1") @@ -107,7 +107,7 @@ class VideoModuleUnitTest(unittest.TestCase): 'track': None, 'show_captions': 'true', 'display_name': 'SampleProblem1', - 'id': 'i4x-edX-video-default-SampleProblem1', + 'id': module.location.html_id(), 'end': 3610.0, 'caption_asset_path': '/static/subs/', 'source': '.../mit-3091x/M-3091X-FA12-L21-3_100.mp4',