diff --git a/AUTHORS b/AUTHORS index 7d6397629f..1af7349491 100644 --- a/AUTHORS +++ b/AUTHORS @@ -75,4 +75,5 @@ Frances Botsford Jonah Stanley Slater Victoroff Peter Fogg -Renzo Lucioni \ No newline at end of file +Bethany LaPenta +Renzo Lucioni diff --git a/common/lib/xmodule/xmodule/tests/__init__.py b/common/lib/xmodule/xmodule/tests/__init__.py index 4bcf2caa6d..d310110844 100644 --- a/common/lib/xmodule/xmodule/tests/__init__.py +++ b/common/lib/xmodule/xmodule/tests/__init__.py @@ -29,14 +29,14 @@ open_ended_grading_interface = { } -def test_system(): +def get_test_system(): """ Construct a test ModuleSystem instance. By default, the render_template() method simply returns the repr of the context it is passed. You can override this behavior by monkey patching:: - system = test_system() + system = get_test_system() system.render_template = my_render_func where `my_render_func` is a function of the form my_render_func(template, context). diff --git a/common/lib/xmodule/xmodule/tests/test_annotatable_module.py b/common/lib/xmodule/xmodule/tests/test_annotatable_module.py index 268f743421..6993841ab2 100644 --- a/common/lib/xmodule/xmodule/tests/test_annotatable_module.py +++ b/common/lib/xmodule/xmodule/tests/test_annotatable_module.py @@ -8,7 +8,7 @@ from mock import Mock from xmodule.annotatable_module import AnnotatableModule from xmodule.modulestore import Location -from . import test_system +from . import get_test_system class AnnotatableModuleTestCase(unittest.TestCase): location = Location(["i4x", "edX", "toy", "annotatable", "guided_discussion"]) @@ -32,7 +32,7 @@ class AnnotatableModuleTestCase(unittest.TestCase): module_data = {'data': sample_xml, 'location': location} def setUp(self): - self.annotatable = AnnotatableModule(test_system(), self.descriptor, self.module_data) + self.annotatable = AnnotatableModule(get_test_system(), self.descriptor, self.module_data) def test_annotation_data_attr(self): el = etree.fromstring('test') diff --git a/common/lib/xmodule/xmodule/tests/test_capa_module.py b/common/lib/xmodule/xmodule/tests/test_capa_module.py index deb6f13e20..696ef58268 100644 --- a/common/lib/xmodule/xmodule/tests/test_capa_module.py +++ b/common/lib/xmodule/xmodule/tests/test_capa_module.py @@ -17,7 +17,7 @@ from xmodule.modulestore import Location from django.http import QueryDict -from . import test_system +from . import get_test_system from pytz import UTC from capa.correctmap import CorrectMap @@ -112,7 +112,7 @@ class CapaFactory(object): # since everything else is a string. model_data['attempts'] = int(attempts) - system = test_system() + system = get_test_system() system.render_template = Mock(return_value="
Test Template HTML
") module = CapaModule(system, descriptor, model_data) @@ -1002,7 +1002,7 @@ class CapaModuleTest(unittest.TestCase): # is asked to render itself as HTML module.lcp.get_html = Mock(side_effect=Exception("Test")) - # Stub out the test_system rendering function + # Stub out the get_test_system rendering function module.system.render_template = Mock(return_value="
Test Template HTML
") # Turn off DEBUG diff --git a/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py b/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py index 7dbaf6fe3d..e1f8d135de 100644 --- a/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py +++ b/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py @@ -18,7 +18,7 @@ import logging log = logging.getLogger(__name__) -from . import test_system +from . import get_test_system ORG = 'edX' COURSE = 'open_ended' # name of directory with course data @@ -68,7 +68,7 @@ class OpenEndedChildTest(unittest.TestCase): descriptor = Mock() def setUp(self): - self.test_system = test_system() + self.test_system = get_test_system() self.openendedchild = OpenEndedChild(self.test_system, self.location, self.definition, self.descriptor, self.static_data, self.metadata) @@ -192,7 +192,7 @@ class OpenEndedModuleTest(unittest.TestCase): descriptor = Mock() def setUp(self): - self.test_system = test_system() + self.test_system = get_test_system() self.test_system.location = self.location self.mock_xqueue = MagicMock() @@ -367,7 +367,7 @@ class CombinedOpenEndedModuleTest(unittest.TestCase): definition = {'prompt': etree.XML(prompt), 'rubric': etree.XML(rubric), 'task_xml': [task_xml1, task_xml2]} full_definition = definition_template.format(prompt=prompt, rubric=rubric, task1=task_xml1, task2=task_xml2) descriptor = Mock(data=full_definition) - test_system = test_system() + test_system = get_test_system() combinedoe_container = CombinedOpenEndedModule( test_system, descriptor, @@ -493,7 +493,7 @@ class OpenEndedModuleXmlTest(unittest.TestCase, DummyModulestore): hint = "blah" def setUp(self): - self.test_system = test_system() + self.test_system = get_test_system() self.test_system.xqueue['interface'] = Mock( send_to_queue=Mock(side_effect=[1, "queued"]) ) @@ -569,6 +569,7 @@ class OpenEndedModuleXmlTest(unittest.TestCase, DummyModulestore): #Mock a student submitting an assessment assessment_dict = MockQueryDict() assessment_dict.update({'assessment': sum(assessment), 'score_list[]': assessment}) + #from nose.tools import set_trace; set_trace() module.handle_ajax("save_assessment", assessment_dict) task_one_json = json.loads(module.task_states[0]) self.assertEqual(json.loads(task_one_json['child_history'][0]['post_assessment']), assessment) diff --git a/common/lib/xmodule/xmodule/tests/test_conditional.py b/common/lib/xmodule/xmodule/tests/test_conditional.py index fed40b690f..abb8b4941a 100644 --- a/common/lib/xmodule/xmodule/tests/test_conditional.py +++ b/common/lib/xmodule/xmodule/tests/test_conditional.py @@ -15,7 +15,7 @@ from xmodule.tests.test_export import DATA_DIR ORG = 'test_org' COURSE = 'conditional' # name of directory with course data -from . import test_system +from . import get_test_system class DummySystem(ImportSystem): @@ -104,7 +104,7 @@ class ConditionalModuleBasicTest(unittest.TestCase): """ def setUp(self): - self.test_system = test_system() + self.test_system = get_test_system() def test_icon_class(self): '''verify that get_icon_class works independent of condition satisfaction''' @@ -117,7 +117,7 @@ class ConditionalModuleBasicTest(unittest.TestCase): def test_get_html(self): modules = ConditionalFactory.create(self.test_system) - # because test_system returns the repr of the context dict passed to render_template, + # because get_test_system returns the repr of the context dict passed to render_template, # we reverse it here html = modules['cond_module'].get_html() html_dict = literal_eval(html) @@ -161,7 +161,7 @@ class ConditionalModuleXmlTest(unittest.TestCase): return DummySystem(load_error_modules) def setUp(self): - self.test_system = test_system() + self.test_system = get_test_system() def get_course(self, name): """Get a test course by directory name. If there's more than one, error.""" diff --git a/common/lib/xmodule/xmodule/tests/test_error_module.py b/common/lib/xmodule/xmodule/tests/test_error_module.py index b980107dd9..f91bf7cb37 100644 --- a/common/lib/xmodule/xmodule/tests/test_error_module.py +++ b/common/lib/xmodule/xmodule/tests/test_error_module.py @@ -2,25 +2,30 @@ Tests for ErrorModule and NonStaffErrorModule """ import unittest -from xmodule.tests import test_system +from xmodule.tests import get_test_system import xmodule.error_module as error_module from xmodule.modulestore import Location from xmodule.x_module import XModuleDescriptor from mock import MagicMock -class TestErrorModule(unittest.TestCase): - """ - Tests for ErrorModule and ErrorDescriptor - """ +class SetupTestErrorModules(): def setUp(self): - self.system = test_system() + self.system = get_test_system() self.org = "org" self.course = "course" self.location = Location(['i4x', self.org, self.course, None, None]) self.valid_xml = u"ABC \N{SNOWMAN}" self.error_msg = "Error" + +class TestErrorModule(unittest.TestCase, SetupTestErrorModules): + """ + Tests for ErrorModule and ErrorDescriptor + """ + def setUp(self): + SetupTestErrorModules.setUp(self) + def test_error_module_xml_rendering(self): descriptor = error_module.ErrorDescriptor.from_xml( self.valid_xml, self.system, self.org, self.course, self.error_msg) @@ -45,10 +50,12 @@ class TestErrorModule(unittest.TestCase): self.assertIn(repr(descriptor), context_repr) -class TestNonStaffErrorModule(TestErrorModule): +class TestNonStaffErrorModule(unittest.TestCase, SetupTestErrorModules): """ Tests for NonStaffErrorModule and NonStaffErrorDescriptor """ + def setUp(self): + SetupTestErrorModules.setUp(self) def test_non_staff_error_module_create(self): descriptor = error_module.NonStaffErrorDescriptor.from_xml( diff --git a/common/lib/xmodule/xmodule/tests/test_html_module.py b/common/lib/xmodule/xmodule/tests/test_html_module.py index ea6b358f3b..e0a49ed98f 100644 --- a/common/lib/xmodule/xmodule/tests/test_html_module.py +++ b/common/lib/xmodule/xmodule/tests/test_html_module.py @@ -5,7 +5,7 @@ from mock import Mock from xmodule.html_module import HtmlModule from xmodule.modulestore import Location -from . import test_system +from . import get_test_system class HtmlModuleSubstitutionTestCase(unittest.TestCase): descriptor = Mock() @@ -13,7 +13,7 @@ class HtmlModuleSubstitutionTestCase(unittest.TestCase): def test_substitution_works(self): sample_xml = '''%%USER_ID%%''' module_data = {'data': sample_xml} - module_system = test_system() + module_system = get_test_system() module = HtmlModule(module_system, self.descriptor, module_data) self.assertEqual(module.get_html(), str(module_system.anonymous_student_id)) @@ -25,14 +25,14 @@ class HtmlModuleSubstitutionTestCase(unittest.TestCase): ''' module_data = {'data': sample_xml} - module = HtmlModule(test_system(), self.descriptor, module_data) + module = HtmlModule(get_test_system(), self.descriptor, module_data) self.assertEqual(module.get_html(), sample_xml) def test_substitution_without_anonymous_student_id(self): sample_xml = '''%%USER_ID%%''' module_data = {'data': sample_xml} - module_system = test_system() + module_system = get_test_system() module_system.anonymous_student_id = None module = HtmlModule(module_system, self.descriptor, module_data) self.assertEqual(module.get_html(), sample_xml) diff --git a/common/lib/xmodule/xmodule/tests/test_logic.py b/common/lib/xmodule/xmodule/tests/test_logic.py index 6fb331b3cf..e62b9a1cee 100644 --- a/common/lib/xmodule/xmodule/tests/test_logic.py +++ b/common/lib/xmodule/xmodule/tests/test_logic.py @@ -8,7 +8,7 @@ import unittest from xmodule.poll_module import PollDescriptor from xmodule.conditional_module import ConditionalDescriptor from xmodule.word_cloud_module import WordCloudDescriptor -from xmodule.tests import test_system +from xmodule.tests import get_test_system class PostData: """Class which emulate postdata.""" @@ -30,7 +30,7 @@ class LogicTest(unittest.TestCase): """Empty object.""" pass - self.system = test_system() + self.system = get_test_system() self.descriptor = EmptyClass() self.xmodule_class = self.descriptor_class.module_class diff --git a/common/lib/xmodule/xmodule/tests/test_peer_grading.py b/common/lib/xmodule/xmodule/tests/test_peer_grading.py index a0877eab81..3e1a578118 100644 --- a/common/lib/xmodule/xmodule/tests/test_peer_grading.py +++ b/common/lib/xmodule/xmodule/tests/test_peer_grading.py @@ -1,6 +1,6 @@ import unittest from xmodule.modulestore import Location -from .import test_system +from .import get_test_system from test_util_open_ended import MockQueryDict, DummyModulestore import json @@ -39,7 +39,7 @@ class PeerGradingModuleTest(unittest.TestCase, DummyModulestore): Create a peer grading module from a test system @return: """ - self.test_system = test_system() + self.test_system = get_test_system() self.test_system.open_ended_grading_interface = None self.setup_modulestore(COURSE) self.peer_grading = self.get_module_from_location(self.problem_location, COURSE) @@ -151,10 +151,10 @@ class PeerGradingModuleScoredTest(unittest.TestCase, DummyModulestore): Create a peer grading module from a test system @return: """ - self.test_system = test_system() + self.test_system = get_test_system() self.test_system.open_ended_grading_interface = None self.setup_modulestore(COURSE) def test_metadata_load(self): peer_grading = self.get_module_from_location(self.problem_location, COURSE) - self.assertEqual(peer_grading.closed(), False) \ No newline at end of file + self.assertEqual(peer_grading.closed(), False) diff --git a/common/lib/xmodule/xmodule/tests/test_progress.py b/common/lib/xmodule/xmodule/tests/test_progress.py index 97ec00b13e..d1a32d5de5 100644 --- a/common/lib/xmodule/xmodule/tests/test_progress.py +++ b/common/lib/xmodule/xmodule/tests/test_progress.py @@ -5,7 +5,7 @@ import unittest from xmodule.progress import Progress from xmodule import x_module -from . import test_system +from . import get_test_system class ProgressTest(unittest.TestCase): @@ -134,6 +134,6 @@ class ModuleProgressTest(unittest.TestCase): ''' def test_xmodule_default(self): '''Make sure default get_progress exists, returns None''' - xm = x_module.XModule(test_system(), None, {'location': 'a://b/c/d/e'}) + xm = x_module.XModule(get_test_system(), None, {'location': 'a://b/c/d/e'}) p = xm.get_progress() self.assertEqual(p, None) diff --git a/common/lib/xmodule/xmodule/tests/test_self_assessment.py b/common/lib/xmodule/xmodule/tests/test_self_assessment.py index 593b3fea01..0ccc6864cd 100644 --- a/common/lib/xmodule/xmodule/tests/test_self_assessment.py +++ b/common/lib/xmodule/xmodule/tests/test_self_assessment.py @@ -6,7 +6,7 @@ from xmodule.open_ended_grading_classes.self_assessment_module import SelfAssess from xmodule.modulestore import Location from lxml import etree -from . import test_system +from . import get_test_system import test_util_open_ended @@ -51,7 +51,7 @@ class SelfAssessmentTest(unittest.TestCase): 'skip_basic_checks': False, } - self.module = SelfAssessmentModule(test_system(), self.location, + self.module = SelfAssessmentModule(get_test_system(), self.location, self.definition, self.descriptor, static_data) diff --git a/common/lib/xmodule/xmodule/tests/test_util_open_ended.py b/common/lib/xmodule/xmodule/tests/test_util_open_ended.py index 8f3ad5b980..9dbb17ae2f 100644 --- a/common/lib/xmodule/xmodule/tests/test_util_open_ended.py +++ b/common/lib/xmodule/xmodule/tests/test_util_open_ended.py @@ -1,4 +1,4 @@ -from .import test_system +from .import get_test_system from xmodule.modulestore import Location from xmodule.modulestore.xml import ImportSystem, XMLModuleStore from xmodule.tests.test_export import DATA_DIR @@ -37,7 +37,7 @@ class DummyModulestore(object): """ A mixin that allows test classes to have convenience functions to get a module given a location """ - test_system = test_system() + get_test_system = get_test_system() def setup_modulestore(self, name): self.modulestore = XMLModuleStore(DATA_DIR, course_dirs=[name]) diff --git a/common/lib/xmodule/xmodule/tests/test_video_xml.py b/common/lib/xmodule/xmodule/tests/test_video_xml.py index fae1580323..54606bafb7 100644 --- a/common/lib/xmodule/xmodule/tests/test_video_xml.py +++ b/common/lib/xmodule/xmodule/tests/test_video_xml.py @@ -20,7 +20,7 @@ from lxml import etree from xmodule.video_module import VideoDescriptor, VideoModule from xmodule.modulestore import Location -from xmodule.tests import test_system +from xmodule.tests import get_test_system from xmodule.tests.test_logic import LogicTest @@ -51,7 +51,7 @@ class VideoFactory(object): descriptor = Mock(weight="1") - system = test_system() + system = get_test_system() system.render_template = lambda template, context: context module = VideoModule(system, descriptor, model_data) diff --git a/common/lib/xmodule/xmodule/tests/test_xml_module.py b/common/lib/xmodule/xmodule/tests/test_xml_module.py index 46410def8e..6ec82275af 100644 --- a/common/lib/xmodule/xmodule/tests/test_xml_module.py +++ b/common/lib/xmodule/xmodule/tests/test_xml_module.py @@ -6,7 +6,7 @@ from xblock.core import Scope, String, Dict, Boolean, Integer, Float, Any, List from xmodule.fields import Date, Timedelta from xmodule.xml_module import XmlDescriptor, serialize_field, deserialize_field import unittest -from .import test_system +from .import get_test_system from nose.tools import assert_equals from mock import Mock @@ -140,7 +140,7 @@ class EditableMetadataFieldsTest(unittest.TestCase): # Start of helper methods def get_xml_editable_fields(self, model_data): - system = test_system() + system = get_test_system() system.render_template = Mock(return_value="
Test Template HTML
") return XmlDescriptor(runtime=system, model_data=model_data).editable_metadata_fields @@ -152,7 +152,7 @@ class EditableMetadataFieldsTest(unittest.TestCase): non_editable_fields.append(TestModuleDescriptor.due) return non_editable_fields - system = test_system() + system = get_test_system() system.render_template = Mock(return_value="
Test Template HTML
") return TestModuleDescriptor(runtime=system, model_data=model_data) diff --git a/lms/djangoapps/courseware/tests/__init__.py b/lms/djangoapps/courseware/tests/__init__.py index 1cb403018c..bde0c89542 100644 --- a/lms/djangoapps/courseware/tests/__init__.py +++ b/lms/djangoapps/courseware/tests/__init__.py @@ -13,7 +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.tests import get_test_system from xmodule.modulestore import Location from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory @@ -77,7 +77,7 @@ class BaseTestXmodule(ModuleStoreTestCase): data=self.DATA ) - system = test_system() + system = get_test_system() system.render_template = lambda template, context: context model_data = {'location': self.item_descriptor.location} model_data.update(self.MODEL_DATA) diff --git a/lms/djangoapps/courseware/tests/test_videoalpha_xml.py b/lms/djangoapps/courseware/tests/test_videoalpha_xml.py index 44e0a7811a..a14fc6cac6 100644 --- a/lms/djangoapps/courseware/tests/test_videoalpha_xml.py +++ b/lms/djangoapps/courseware/tests/test_videoalpha_xml.py @@ -22,7 +22,7 @@ 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 import get_test_system from xmodule.tests.test_logic import LogicTest @@ -58,7 +58,7 @@ class VideoAlphaFactory(object): descriptor = Mock(weight="1") - system = test_system() + system = get_test_system() system.render_template = lambda template, context: context VideoAlphaModule.location = location module = VideoAlphaModule(system, descriptor, model_data)