Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ Frances Botsford <frances@edx.org>
Jonah Stanley <Jonah_Stanley@brown.edu>
Slater Victoroff <slater.r.victoroff@gmail.com>
Peter Fogg <peter.p.fogg@gmail.com>
Bethany LaPenta <lapentab@mit.edu>
4 changes: 2 additions & 2 deletions common/lib/xmodule/xmodule/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
}


def test_system():
def system_test():
"""
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 = system_test()
system.render_template = my_render_func

where `my_render_func` is a function of the form my_render_func(template, context).
Expand Down
4 changes: 2 additions & 2 deletions common/lib/xmodule/xmodule/tests/test_annotatable_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from xmodule.annotatable_module import AnnotatableModule
from xmodule.modulestore import Location

from . import test_system
from . import system_test

class AnnotatableModuleTestCase(unittest.TestCase):
location = Location(["i4x", "edX", "toy", "annotatable", "guided_discussion"])
Expand All @@ -32,7 +32,7 @@ class AnnotatableModuleTestCase(unittest.TestCase):
module_data = {'data': sample_xml}

def setUp(self):
self.annotatable = AnnotatableModule(test_system(), self.location, self.descriptor, self.module_data)
self.annotatable = AnnotatableModule(system_test(), 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>')
Expand Down
6 changes: 3 additions & 3 deletions common/lib/xmodule/xmodule/tests/test_capa_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from django.http import QueryDict

from . import test_system
from . import system_test


class CapaFactory(object):
Expand Down Expand Up @@ -110,7 +110,7 @@ def create(graceperiod=None,
# since everything else is a string.
model_data['attempts'] = int(attempts)

system = test_system()
system = system_test()
system.render_template = Mock(return_value="<div>Test Template HTML</div>")
module = CapaModule(system, location, descriptor, model_data)

Expand Down Expand Up @@ -921,7 +921,7 @@ def test_get_problem_html_error(self):
# 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 system_test rendering function
module.system.render_template = Mock(return_value="<div>Test Template HTML</div>")

# Turn off DEBUG
Expand Down
48 changes: 24 additions & 24 deletions common/lib/xmodule/xmodule/tests/test_combined_open_ended.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

log = logging.getLogger(__name__)

from . import test_system
from . import system_test

ORG = 'edX'
COURSE = 'open_ended' # name of directory with course data
Expand Down Expand Up @@ -68,8 +68,8 @@ class OpenEndedChildTest(unittest.TestCase):
descriptor = Mock()

def setUp(self):
self.test_system = test_system()
self.openendedchild = OpenEndedChild(self.test_system, self.location,
self.system_test = system_test()
self.openendedchild = OpenEndedChild(self.system_test, self.location,
self.definition, self.descriptor, self.static_data, self.metadata)

def test_latest_answer_empty(self):
Expand All @@ -81,7 +81,7 @@ def test_latest_score_empty(self):
self.assertEqual(answer, None)

def test_latest_post_assessment_empty(self):
answer = self.openendedchild.latest_post_assessment(self.test_system)
answer = self.openendedchild.latest_post_assessment(self.system_test)
self.assertEqual(answer, "")

def test_new_history_entry(self):
Expand Down Expand Up @@ -116,7 +116,7 @@ def test_record_latest_post_assessment(self):
post_assessment = "Post assessment"
self.openendedchild.record_latest_post_assessment(post_assessment)
self.assertEqual(post_assessment,
self.openendedchild.latest_post_assessment(self.test_system))
self.openendedchild.latest_post_assessment(self.system_test))

def test_get_score(self):
new_answer = "New Answer"
Expand All @@ -134,7 +134,7 @@ def test_get_score(self):
self.assertEqual(score['total'], self.static_data['max_score'])

def test_reset(self):
self.openendedchild.reset(self.test_system)
self.openendedchild.reset(self.system_test)
state = json.loads(self.openendedchild.get_instance_state())
self.assertEqual(state['child_state'], OpenEndedChild.INITIAL)

Expand Down Expand Up @@ -193,19 +193,19 @@ class OpenEndedModuleTest(unittest.TestCase):
descriptor = Mock()

def setUp(self):
self.test_system = test_system()
self.system_test = system_test()

self.test_system.location = self.location
self.system_test.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.test_system.xqueue = {'interface': self.mock_xqueue, 'construct_callback': constructed_callback,
self.system_test.xqueue = {'interface': self.mock_xqueue, 'construct_callback': constructed_callback,
'default_queuename': 'testqueue',
'waittime': 1}
self.openendedmodule = OpenEndedModule(self.test_system, self.location,
self.openendedmodule = OpenEndedModule(self.system_test, self.location,
self.definition, self.descriptor, self.static_data, self.metadata)

def test_message_post(self):
Expand All @@ -214,7 +214,7 @@ def test_message_post(self):
'grader_id': '1',
'score': 3}
qtime = datetime.strftime(datetime.now(), xqueue_interface.dateformat)
student_info = {'anonymous_student_id': self.test_system.anonymous_student_id,
student_info = {'anonymous_student_id': self.system_test.anonymous_student_id,
'submission_time': qtime}
contents = {
'feedback': get['feedback'],
Expand All @@ -224,7 +224,7 @@ def test_message_post(self):
'student_info': json.dumps(student_info)
}

result = self.openendedmodule.message_post(get, self.test_system)
result = self.openendedmodule.message_post(get, self.system_test)
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)
Expand All @@ -235,15 +235,15 @@ def test_message_post(self):
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.test_system.anonymous_student_id,
student_info = {'anonymous_student_id': self.system_test.anonymous_student_id,
'submission_time': qtime}
contents = self.openendedmodule.payload.copy()
contents.update({
'student_info': json.dumps(student_info),
'student_response': submission,
'max_score': self.max_score
})
result = self.openendedmodule.send_to_grader(submission, self.test_system)
result = self.openendedmodule.send_to_grader(submission, self.system_test)
self.assertTrue(result)
self.mock_xqueue.send_to_queue.assert_called_with(body=json.dumps(contents), header=ANY)

Expand All @@ -257,7 +257,7 @@ def update_score_single(self):
}
get = {'queuekey': "abcd",
'xqueue_body': score_msg}
self.openendedmodule.update_score(get, self.test_system)
self.openendedmodule.update_score(get, self.system_test)

def update_score_single(self):
self.openendedmodule.new_history_entry("New Entry")
Expand All @@ -280,11 +280,11 @@ def update_score_single(self):
}
get = {'queuekey': "abcd",
'xqueue_body': json.dumps(score_msg)}
self.openendedmodule.update_score(get, self.test_system)
self.openendedmodule.update_score(get, self.system_test)

def test_latest_post_assessment(self):
self.update_score_single()
assessment = self.openendedmodule.latest_post_assessment(self.test_system)
assessment = self.openendedmodule.latest_post_assessment(self.system_test)
self.assertFalse(assessment == '')
# check for errors
self.assertFalse('errors' in assessment)
Expand Down Expand Up @@ -369,16 +369,16 @@ 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()
combinedoe_container = CombinedOpenEndedModule(test_system,
system_test = system_test()
combinedoe_container = CombinedOpenEndedModule(system_test,
location,
descriptor,
model_data={'data': full_definition, 'weight': '1'})

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.test_system,
self.combinedoe = CombinedOpenEndedV1Module(self.system_test,
self.location,
self.definition,
self.descriptor,
Expand Down Expand Up @@ -438,7 +438,7 @@ def test_alternate_orderings(self):
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.test_system,
combinedoe = CombinedOpenEndedV1Module(self.system_test,
self.location,
definition,
descriptor,
Expand Down Expand Up @@ -468,7 +468,7 @@ def test_get_score_realistic(self):
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.test_system,
combinedoe = CombinedOpenEndedV1Module(self.system_test,
self.location,
definition,
descriptor,
Expand All @@ -490,8 +490,8 @@ class OpenEndedModuleXmlTest(unittest.TestCase, DummyModulestore):
hint = "blah"

def setUp(self):
self.test_system = test_system()
self.test_system.xqueue['interface'] = Mock(
self.system_test = system_test()
self.system_test.xqueue['interface'] = Mock(
send_to_queue=Mock(side_effect=[1, "queued"])
)
self.setup_modulestore(COURSE)
Expand Down
28 changes: 14 additions & 14 deletions common/lib/xmodule/xmodule/tests/test_conditional.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
ORG = 'test_org'
COURSE = 'conditional' # name of directory with course data

from . import test_system
from . import system_test


class DummySystem(ImportSystem):
Expand Down Expand Up @@ -60,9 +60,9 @@ def create(system, source_is_error_module=False):
source_location = Location(["i4x", "edX", "conditional_test", "problem", "SampleProblem"])
if source_is_error_module:
# Make an error descriptor and module
source_descriptor = NonStaffErrorDescriptor.from_xml('some random xml data',
source_descriptor = NonStaffErrorDescriptor.from_xml('some random xml data',
system,
org=source_location.org,
org=source_location.org,
course=source_location.course,
error_msg='random error message')
source_module = source_descriptor.xmodule(system)
Expand Down Expand Up @@ -103,11 +103,11 @@ class ConditionalModuleBasicTest(unittest.TestCase):
"""

def setUp(self):
self.test_system = test_system()
self.system_test = system_test()

def test_icon_class(self):
'''verify that get_icon_class works independent of condition satisfaction'''
modules = ConditionalFactory.create(self.test_system)
'''verify that get_icon_class works independent of condition satisfaction'''
modules = ConditionalFactory.create(self.system_test)
for attempted in ["false", "true"]:
for icon_class in [ 'other', 'problem', 'video']:
modules['source_module'].is_attempted = attempted
Expand All @@ -116,8 +116,8 @@ def test_icon_class(self):


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,
modules = ConditionalFactory.create(self.system_test)
# because system_test 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)
Expand All @@ -126,7 +126,7 @@ def test_get_html(self):
self.assertEqual(html_dict['depends'], 'i4x-edX-conditional_test-problem-SampleProblem')

def test_handle_ajax(self):
modules = ConditionalFactory.create(self.test_system)
modules = ConditionalFactory.create(self.system_test)
modules['source_module'].is_attempted = "false"
ajax = json.loads(modules['cond_module'].handle_ajax('', ''))
print "ajax: ", ajax
Expand All @@ -145,7 +145,7 @@ def test_error_as_source(self):
Check that handle_ajax works properly if the source is really an ErrorModule,
and that the condition is not satisfied.
'''
modules = ConditionalFactory.create(self.test_system, source_is_error_module=True)
modules = ConditionalFactory.create(self.system_test, 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]))
Expand All @@ -161,7 +161,7 @@ def get_system(load_error_modules=True):
return DummySystem(load_error_modules)

def setUp(self):
self.test_system = test_system()
self.system_test = system_test()

def get_course(self, name):
"""Get a test course by directory name. If there's more than one, error."""
Expand All @@ -187,16 +187,16 @@ def inner_get_module(descriptor):
location = descriptor
descriptor = self.modulestore.get_instance(course.id, location, depth=None)
location = descriptor.location
return descriptor.xmodule(self.test_system)
return descriptor.xmodule(self.system_test)

# edx - HarvardX
# cond_test - ER22x
location = Location(["i4x", "HarvardX", "ER22x", "conditional", "condone"])

def replace_urls(text, staticfiles_prefix=None, replace_prefix='/static/', course_namespace=None):
return text
self.test_system.replace_urls = replace_urls
self.test_system.get_module = inner_get_module
self.system_test.replace_urls = replace_urls
self.system_test.get_module = inner_get_module

module = inner_get_module(location)
print "module: ", module
Expand Down
13 changes: 10 additions & 3 deletions common/lib/xmodule/xmodule/tests/test_error_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Tests for ErrorModule and NonStaffErrorModule
"""
import unittest
from xmodule.tests import test_system
from xmodule.tests import system_test
import xmodule.error_module as error_module
from xmodule.modulestore import Location
from xmodule.x_module import XModuleDescriptor
Expand All @@ -14,7 +14,7 @@ class TestErrorModule(unittest.TestCase):
Tests for ErrorModule and ErrorDescriptor
"""
def setUp(self):
self.system = test_system()
self.system = system_test()
self.org = "org"
self.course = "course"
self.location = Location(['i4x', self.org, self.course, None, None])
Expand Down Expand Up @@ -45,10 +45,17 @@ def test_error_module_from_descriptor(self):
self.assertIn(repr(descriptor), context_repr)


class TestNonStaffErrorModule(TestErrorModule):
class TestNonStaffErrorModule(unittest.TestCase):
"""
Tests for NonStaffErrorModule and NonStaffErrorDescriptor
"""
def setUp(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicating this setUp function is unfortunate. Can't we move this code somewhere we can share it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two possibilities for this:

  1. Create a base class that both test cases inherit from
  2. Define an external helper function that both test cases call in their setUp() methods.

self.system = system_test()
self.org = "org"
self.course = "course"
self.location = Location(['i4x', self.org, self.course, None, None])
self.valid_xml = u"<problem>ABC \N{SNOWMAN}</problem>"
self.error_msg = "Error"

def test_non_staff_error_module_create(self):
descriptor = error_module.NonStaffErrorDescriptor.from_xml(
Expand Down
Loading