Commit b93f00e0 by lapentab

Rename system_test to get_test_system

parent 7516fb56
......@@ -29,14 +29,14 @@ open_ended_grading_interface = {
}
def system_test():
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 = system_test()
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).
......
......@@ -8,7 +8,7 @@ from mock import Mock
from xmodule.annotatable_module import AnnotatableModule
from xmodule.modulestore import Location
from . import system_test
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}
def setUp(self):
self.annotatable = AnnotatableModule(system_test(), self.location, self.descriptor, self.module_data)
self.annotatable = AnnotatableModule(get_test_system(), self.location, self.descriptor, self.module_data)
def test_annotation_data_attr(self):
el = etree.fromstring('<annotation title="bar" body="foo" problem="0">test</annotation>')
......
......@@ -17,7 +17,7 @@ from xmodule.modulestore import Location
from django.http import QueryDict
from . import system_test
from . import get_test_system
class CapaFactory(object):
......@@ -110,7 +110,7 @@ class CapaFactory(object):
# since everything else is a string.
model_data['attempts'] = int(attempts)
system = system_test()
system = get_test_system()
system.render_template = Mock(return_value="<div>Test Template HTML</div>")
module = CapaModule(system, location, descriptor, model_data)
......@@ -921,7 +921,7 @@ class CapaModuleTest(unittest.TestCase):
# is asked to render itself as HTML
module.lcp.get_html = Mock(side_effect=Exception("Test"))
# Stub out the system_test rendering function
# Stub out the get_test_system rendering function
module.system.render_template = Mock(return_value="<div>Test Template HTML</div>")
# Turn off DEBUG
......
......@@ -18,7 +18,7 @@ import logging
log = logging.getLogger(__name__)
from . import system_test
from . import get_test_system
ORG = 'edX'
COURSE = 'open_ended' # name of directory with course data
......@@ -68,8 +68,8 @@ class OpenEndedChildTest(unittest.TestCase):
descriptor = Mock()
def setUp(self):
self.system_test = system_test()
self.openendedchild = OpenEndedChild(self.system_test, self.location,
self.get_test_system = get_test_system()
self.openendedchild = OpenEndedChild(self.get_test_system, self.location,
self.definition, self.descriptor, self.static_data, self.metadata)
def test_latest_answer_empty(self):
......@@ -81,7 +81,7 @@ class OpenEndedChildTest(unittest.TestCase):
self.assertEqual(answer, None)
def test_latest_post_assessment_empty(self):
answer = self.openendedchild.latest_post_assessment(self.system_test)
answer = self.openendedchild.latest_post_assessment(self.get_test_system)
self.assertEqual(answer, "")
def test_new_history_entry(self):
......@@ -116,7 +116,7 @@ class OpenEndedChildTest(unittest.TestCase):
post_assessment = "Post assessment"
self.openendedchild.record_latest_post_assessment(post_assessment)
self.assertEqual(post_assessment,
self.openendedchild.latest_post_assessment(self.system_test))
self.openendedchild.latest_post_assessment(self.get_test_system))
def test_get_score(self):
new_answer = "New Answer"
......@@ -134,7 +134,7 @@ class OpenEndedChildTest(unittest.TestCase):
self.assertEqual(score['total'], self.static_data['max_score'])
def test_reset(self):
self.openendedchild.reset(self.system_test)
self.openendedchild.reset(self.get_test_system)
state = json.loads(self.openendedchild.get_instance_state())
self.assertEqual(state['child_state'], OpenEndedChild.INITIAL)
......@@ -193,19 +193,19 @@ class OpenEndedModuleTest(unittest.TestCase):
descriptor = Mock()
def setUp(self):
self.system_test = system_test()
self.get_test_system = get_test_system()
self.system_test.location = self.location
self.get_test_system.location = self.location
self.mock_xqueue = MagicMock()
self.mock_xqueue.send_to_queue.return_value = (None, "Message")
def constructed_callback(dispatch="score_update"):
return dispatch
self.system_test.xqueue = {'interface': self.mock_xqueue, 'construct_callback': constructed_callback,
self.get_test_system.xqueue = {'interface': self.mock_xqueue, 'construct_callback': constructed_callback,
'default_queuename': 'testqueue',
'waittime': 1}
self.openendedmodule = OpenEndedModule(self.system_test, self.location,
self.openendedmodule = OpenEndedModule(self.get_test_system, self.location,
self.definition, self.descriptor, self.static_data, self.metadata)
def test_message_post(self):
......@@ -214,7 +214,7 @@ class OpenEndedModuleTest(unittest.TestCase):
'grader_id': '1',
'score': 3}
qtime = datetime.strftime(datetime.now(), xqueue_interface.dateformat)
student_info = {'anonymous_student_id': self.system_test.anonymous_student_id,
student_info = {'anonymous_student_id': self.get_test_system.anonymous_student_id,
'submission_time': qtime}
contents = {
'feedback': get['feedback'],
......@@ -224,7 +224,7 @@ class OpenEndedModuleTest(unittest.TestCase):
'student_info': json.dumps(student_info)
}
result = self.openendedmodule.message_post(get, self.system_test)
result = self.openendedmodule.message_post(get, self.get_test_system)
self.assertTrue(result['success'])
# make sure it's actually sending something we want to the queue
self.mock_xqueue.send_to_queue.assert_called_with(body=json.dumps(contents), header=ANY)
......@@ -235,7 +235,7 @@ class OpenEndedModuleTest(unittest.TestCase):
def test_send_to_grader(self):
submission = "This is a student submission"
qtime = datetime.strftime(datetime.now(), xqueue_interface.dateformat)
student_info = {'anonymous_student_id': self.system_test.anonymous_student_id,
student_info = {'anonymous_student_id': self.get_test_system.anonymous_student_id,
'submission_time': qtime}
contents = self.openendedmodule.payload.copy()
contents.update({
......@@ -243,7 +243,7 @@ class OpenEndedModuleTest(unittest.TestCase):
'student_response': submission,
'max_score': self.max_score
})
result = self.openendedmodule.send_to_grader(submission, self.system_test)
result = self.openendedmodule.send_to_grader(submission, self.get_test_system)
self.assertTrue(result)
self.mock_xqueue.send_to_queue.assert_called_with(body=json.dumps(contents), header=ANY)
......@@ -257,7 +257,7 @@ class OpenEndedModuleTest(unittest.TestCase):
}
get = {'queuekey': "abcd",
'xqueue_body': score_msg}
self.openendedmodule.update_score(get, self.system_test)
self.openendedmodule.update_score(get, self.get_test_system)
def update_score_single(self):
self.openendedmodule.new_history_entry("New Entry")
......@@ -280,11 +280,11 @@ class OpenEndedModuleTest(unittest.TestCase):
}
get = {'queuekey': "abcd",
'xqueue_body': json.dumps(score_msg)}
self.openendedmodule.update_score(get, self.system_test)
self.openendedmodule.update_score(get, self.get_test_system)
def test_latest_post_assessment(self):
self.update_score_single()
assessment = self.openendedmodule.latest_post_assessment(self.system_test)
assessment = self.openendedmodule.latest_post_assessment(self.get_test_system)
self.assertFalse(assessment == '')
# check for errors
self.assertFalse('errors' in assessment)
......@@ -369,8 +369,8 @@ 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)
system_test = system_test()
combinedoe_container = CombinedOpenEndedModule(system_test,
get_test_system = get_test_system()
combinedoe_container = CombinedOpenEndedModule(get_test_system,
location,
descriptor,
model_data={'data': full_definition, 'weight': '1'})
......@@ -378,7 +378,7 @@ class CombinedOpenEndedModuleTest(unittest.TestCase):
def setUp(self):
# TODO: this constructor call is definitely wrong, but neither branch
# of the merge matches the module constructor. Someone (Vik?) should fix this.
self.combinedoe = CombinedOpenEndedV1Module(self.system_test,
self.combinedoe = CombinedOpenEndedV1Module(self.get_test_system,
self.location,
self.definition,
self.descriptor,
......@@ -438,7 +438,7 @@ class CombinedOpenEndedModuleTest(unittest.TestCase):
for xml in xml_to_test:
definition = {'prompt': etree.XML(self.prompt), 'rubric': etree.XML(self.rubric), 'task_xml': xml}
descriptor = Mock(data=definition)
combinedoe = CombinedOpenEndedV1Module(self.system_test,
combinedoe = CombinedOpenEndedV1Module(self.get_test_system,
self.location,
definition,
descriptor,
......@@ -468,7 +468,7 @@ class CombinedOpenEndedModuleTest(unittest.TestCase):
definition = {'prompt': etree.XML(self.prompt), 'rubric': etree.XML(rubric),
'task_xml': [self.task_xml1, self.task_xml2]}
descriptor = Mock(data=definition)
combinedoe = CombinedOpenEndedV1Module(self.system_test,
combinedoe = CombinedOpenEndedV1Module(self.get_test_system,
self.location,
definition,
descriptor,
......@@ -490,8 +490,8 @@ class OpenEndedModuleXmlTest(unittest.TestCase, DummyModulestore):
hint = "blah"
def setUp(self):
self.system_test = system_test()
self.system_test.xqueue['interface'] = Mock(
self.get_test_system = get_test_system()
self.get_test_system.xqueue['interface'] = Mock(
send_to_queue=Mock(side_effect=[1, "queued"])
)
self.setup_modulestore(COURSE)
......
......@@ -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 system_test
from . import get_test_system
class DummySystem(ImportSystem):
......@@ -103,11 +103,11 @@ class ConditionalModuleBasicTest(unittest.TestCase):
"""
def setUp(self):
self.system_test = system_test()
self.get_test_system = get_test_system()
def test_icon_class(self):
'''verify that get_icon_class works independent of condition satisfaction'''
modules = ConditionalFactory.create(self.system_test)
modules = ConditionalFactory.create(self.get_test_system)
for attempted in ["false", "true"]:
for icon_class in [ 'other', 'problem', 'video']:
modules['source_module'].is_attempted = attempted
......@@ -116,8 +116,8 @@ class ConditionalModuleBasicTest(unittest.TestCase):
def test_get_html(self):
modules = ConditionalFactory.create(self.system_test)
# because system_test returns the repr of the context dict passed to render_template,
modules = ConditionalFactory.create(self.get_test_system)
# 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)
......@@ -126,7 +126,7 @@ class ConditionalModuleBasicTest(unittest.TestCase):
self.assertEqual(html_dict['depends'], 'i4x-edX-conditional_test-problem-SampleProblem')
def test_handle_ajax(self):
modules = ConditionalFactory.create(self.system_test)
modules = ConditionalFactory.create(self.get_test_system)
modules['source_module'].is_attempted = "false"
ajax = json.loads(modules['cond_module'].handle_ajax('', ''))
print "ajax: ", ajax
......@@ -145,7 +145,7 @@ class ConditionalModuleBasicTest(unittest.TestCase):
Check that handle_ajax works properly if the source is really an ErrorModule,
and that the condition is not satisfied.
'''
modules = ConditionalFactory.create(self.system_test, source_is_error_module=True)
modules = ConditionalFactory.create(self.get_test_system, source_is_error_module=True)
ajax = json.loads(modules['cond_module'].handle_ajax('', ''))
html = ajax['html']
self.assertFalse(any(['This is a secret' in item for item in html]))
......@@ -161,7 +161,7 @@ class ConditionalModuleXmlTest(unittest.TestCase):
return DummySystem(load_error_modules)
def setUp(self):
self.system_test = system_test()
self.get_test_system = get_test_system()
def get_course(self, name):
"""Get a test course by directory name. If there's more than one, error."""
......@@ -187,7 +187,7 @@ class ConditionalModuleXmlTest(unittest.TestCase):
location = descriptor
descriptor = self.modulestore.get_instance(course.id, location, depth=None)
location = descriptor.location
return descriptor.xmodule(self.system_test)
return descriptor.xmodule(self.get_test_system)
# edx - HarvardX
# cond_test - ER22x
......@@ -195,8 +195,8 @@ class ConditionalModuleXmlTest(unittest.TestCase):
def replace_urls(text, staticfiles_prefix=None, replace_prefix='/static/', course_namespace=None):
return text
self.system_test.replace_urls = replace_urls
self.system_test.get_module = inner_get_module
self.get_test_system.replace_urls = replace_urls
self.get_test_system.get_module = inner_get_module
module = inner_get_module(location)
print "module: ", module
......
......@@ -2,7 +2,7 @@
Tests for ErrorModule and NonStaffErrorModule
"""
import unittest
from xmodule.tests import system_test
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
......@@ -14,7 +14,7 @@ class TestErrorModule(unittest.TestCase):
Tests for ErrorModule and ErrorDescriptor
"""
def setUp(self):
self.system = system_test()
self.system = get_test_system()
self.org = "org"
self.course = "course"
self.location = Location(['i4x', self.org, self.course, None, None])
......@@ -50,7 +50,7 @@ class TestNonStaffErrorModule(unittest.TestCase):
Tests for NonStaffErrorModule and NonStaffErrorDescriptor
"""
def setUp(self):
self.system = system_test()
self.system = get_test_system()
self.org = "org"
self.course = "course"
self.location = Location(['i4x', self.org, self.course, None, None])
......
......@@ -5,7 +5,7 @@ from mock import Mock
from xmodule.html_module import HtmlModule
from xmodule.modulestore import Location
from . import system_test
from . import get_test_system
class HtmlModuleSubstitutionTestCase(unittest.TestCase):
location = Location(["i4x", "edX", "toy", "html", "simple_html"])
......@@ -14,7 +14,7 @@ class HtmlModuleSubstitutionTestCase(unittest.TestCase):
def test_substitution_works(self):
sample_xml = '''%%USER_ID%%'''
module_data = {'data': sample_xml}
module_system = system_test()
module_system = get_test_system()
module = HtmlModule(module_system, self.location, self.descriptor, module_data)
self.assertEqual(module.get_html(), str(module_system.anonymous_student_id))
......@@ -26,14 +26,14 @@ class HtmlModuleSubstitutionTestCase(unittest.TestCase):
</html>
'''
module_data = {'data': sample_xml}
module = HtmlModule(system_test(), self.location, self.descriptor, module_data)
module = HtmlModule(get_test_system(), self.location, 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 = system_test()
module_system = get_test_system()
module_system.anonymous_student_id = None
module = HtmlModule(module_system, self.location, self.descriptor, module_data)
self.assertEqual(module.get_html(), sample_xml)
......
import unittest
from xmodule.modulestore import Location
from .import system_test
from .import get_test_system
from test_util_open_ended import MockQueryDict, DummyModulestore
import json
......@@ -39,8 +39,8 @@ class PeerGradingModuleTest(unittest.TestCase, DummyModulestore):
Create a peer grading module from a test system
@return:
"""
self.system_test = system_test()
self.system_test.open_ended_grading_interface = None
self.get_test_system = get_test_system()
self.get_test_system.open_ended_grading_interface = None
self.setup_modulestore(COURSE)
self.peer_grading = self.get_module_from_location(self.problem_location, COURSE)
......@@ -151,8 +151,8 @@ class PeerGradingModuleScoredTest(unittest.TestCase, DummyModulestore):
Create a peer grading module from a test system
@return:
"""
self.system_test = system_test()
self.system_test.open_ended_grading_interface = None
self.get_test_system = get_test_system()
self.get_test_system.open_ended_grading_interface = None
self.setup_modulestore(COURSE)
def test_metadata_load(self):
......
......@@ -5,7 +5,7 @@ import unittest
from xmodule.progress import Progress
from xmodule import x_module
from . import system_test
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(system_test(), 'a://b/c/d/e', None, {})
xm = x_module.XModule(get_test_system(), 'a://b/c/d/e', None, {})
p = xm.get_progress()
self.assertEqual(p, None)
......@@ -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 system_test
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(system_test(), self.location,
self.module = SelfAssessmentModule(get_test_system(), self.location,
self.definition,
self.descriptor,
static_data)
......
from .import system_test
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
"""
system_test = system_test()
get_test_system = get_test_system()
def setup_modulestore(self, name):
self.modulestore = XMLModuleStore(DATA_DIR, course_dirs=[name])
......@@ -52,4 +52,4 @@ class DummyModulestore(object):
if not isinstance(location, Location):
location = Location(location)
descriptor = self.modulestore.get_instance(course.id, location, depth=None)
return descriptor.xmodule(self.system_test)
return descriptor.xmodule(self.get_test_system)
......@@ -6,7 +6,7 @@ from xblock.core import Scope, String, Object, Boolean
from xmodule.fields import Date, StringyInteger, StringyFloat
from xmodule.xml_module import XmlDescriptor
import unittest
from .import system_test
from .import get_test_system
from mock import Mock
......@@ -139,7 +139,7 @@ class EditableMetadataFieldsTest(unittest.TestCase):
# Start of helper methods
def get_xml_editable_fields(self, model_data):
system = system_test()
system = get_test_system()
system.render_template = Mock(return_value="<div>Test Template HTML</div>")
return XmlDescriptor(system=system, location=None, model_data=model_data).editable_metadata_fields
......@@ -151,7 +151,7 @@ class EditableMetadataFieldsTest(unittest.TestCase):
non_editable_fields.append(TestModuleDescriptor.due)
return non_editable_fields
system = system_test()
system = get_test_system()
system.render_template = Mock(return_value="<div>Test Template HTML</div>")
return TestModuleDescriptor(system=system, location=None, model_data=model_data)
......
......@@ -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 system_test
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
......@@ -78,7 +78,7 @@ class BaseTestXmodule(ModuleStoreTestCase):
)
location = self.item_descriptor.location
system = system_test()
system = get_test_system()
system.render_template = lambda template, context: context
self.item_module = self.item_descriptor.module_class(
......
......@@ -20,7 +20,7 @@ from lxml import etree
from xmodule.video_module import VideoDescriptor, VideoModule
from xmodule.modulestore import Location
from xmodule.tests import system_test
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 = system_test()
system = get_test_system()
system.render_template = lambda template, context: context
module = VideoModule(system, location, descriptor, model_data)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment