Commit 8323cc7c by Vik Paruchuri

Refactor tests

parent 7b8b168f
from . import test_system
import unittest
from xmodule.modulestore import Location
from xmodule.modulestore.xml import ImportSystem, XMLModuleStore
from xmodule.tests.test_export import DATA_DIR
from fs.memoryfs import MemoryFS
from mock import patch, Mock
class DummySystem(ImportSystem):
@patch('xmodule.modulestore.xml.OSFS', lambda dir: MemoryFS())
def __init__(self, load_error_modules, org, course):
xmlstore = XMLModuleStore("data_dir", course_dirs=[], load_error_modules=load_error_modules)
course_id = "/".join([org, course, 'test_run'])
course_dir = "test_dir"
policy = {}
error_tracker = Mock()
parent_tracker = Mock()
super(DummySystem, self).__init__(
xmlstore,
course_id,
course_dir,
policy,
error_tracker,
parent_tracker,
load_error_modules=load_error_modules,
)
def render_template(self, template, context):
raise Exception("Shouldn't be called")
class DummySystemUser(object):
test_system = test_system()
@staticmethod
def get_import_system(org, course, load_error_modules=True):
'''Get a dummy system'''
return DummySystem(load_error_modules, org, course)
def get_course(self, name):
"""Get a test course by directory name. If there's more than one, error."""
modulestore = XMLModuleStore(DATA_DIR, course_dirs=[name])
courses = modulestore.get_courses()
self.modulestore = modulestore
return courses[0]
def get_module_from_location(self, location, course):
course = self.get_course(course)
if not isinstance(location, Location):
location = Location(location)
descriptor = self.modulestore.get_instance(course.id, location, depth=None)
return descriptor.xmodule(self.test_system)
\ No newline at end of file
import unittest
from xmodule.modulestore import Location
import json
from lxml import etree
from mock import Mock
from . import test_system
from dummy_system import DummySystem, DummySystemUser
from test_util_open_ended import MockQueryDict
from .import test_system
from test_util_open_ended import MockQueryDict, DummyModulestore
from xmodule.peer_grading_module import PeerGradingModule, PeerGradingDescriptor
from xmodule.open_ended_grading_classes.grading_service_module import GradingServiceError
import logging
log = logging.getLogger(__name__)
ORG = "edX"
COURSE="open_ended"
COURSE = "open_ended"
class PeerGradingModuleTest(unittest.TestCase, DummySystemUser):
class PeerGradingModuleTest(unittest.TestCase, DummyModulestore):
problem_location = Location(["i4x", "edX", "open_ended", "peergrading",
"PeerGradingSample"])
calibrated_dict = {'location' : "blah"}
"PeerGradingSample"])
calibrated_dict = {'location': "blah"}
save_dict = MockQueryDict()
save_dict.update({
'location' : "blah",
'submission_id' : 1,
'submission_key' : "",
'location': "blah",
'submission_id': 1,
'submission_key': "",
'score': 1,
'feedback' : "",
'rubric_scores[]' : [0,1],
'feedback': "",
'rubric_scores[]': [0, 1],
'submission_flagged': False,
})
})
def setUp(self):
self.test_system = test_system()
......@@ -54,17 +54,16 @@ class PeerGradingModuleTest(unittest.TestCase, DummySystemUser):
max_score = self.peer_grading.max_score()
def get_next_submission(self):
success, next_submission = self.peer_grading.get_next_submission({'location' : 'blah'})
success, next_submission = self.peer_grading.get_next_submission({'location': 'blah'})
def test_save_grade(self):
self.peer_grading.save_grade(self.save_dict)
def test_is_student_calibrated(self):
calibrated_dict = {'location' : "blah"}
calibrated_dict = {'location': "blah"}
self.peer_grading.is_student_calibrated(self.calibrated_dict)
def test_show_calibration_essay(self):
self.peer_grading.show_calibration_essay(self.calibrated_dict)
def test_save_calibration_essay(self):
......
from .import test_system
from xmodule.modulestore import Location
from xmodule.modulestore.xml import ImportSystem, XMLModuleStore
from xmodule.tests.test_export import DATA_DIR
OPEN_ENDED_GRADING_INTERFACE = {
'url': 'blah/',
'username': 'incorrect',
......@@ -17,10 +22,30 @@ class MockQueryDict(dict):
"""
Mock a query set so that it can be used with default authorization
"""
def getlist(self, key, default=None):
try:
return super(MockQueryDict, self).__getitem__(key)
except KeyError:
if default is None:
return []
return default
\ No newline at end of file
return default
class DummyModulestore(object):
test_system = test_system()
def get_course(self, name):
"""Get a test course by directory name. If there's more than one, error."""
modulestore = XMLModuleStore(DATA_DIR, course_dirs=[name])
courses = modulestore.get_courses()
self.modulestore = modulestore
return courses[0]
def get_module_from_location(self, location, course):
course = self.get_course(course)
if not isinstance(location, Location):
location = Location(location)
descriptor = self.modulestore.get_instance(course.id, location, depth=None)
return descriptor.xmodule(self.test_system)
\ No newline at end of file
......@@ -2,5 +2,6 @@
<chapter url_name="Overview">
<combinedopenended url_name="SampleQuestion"/>
<peergrading url_name="PeerGradingSample"/>
<peergrading url_name="PeerGradingScored"/>
</chapter>
</course>
<peergrading is_graded="True" max_grade="1" use_for_single_location="True" link_to_location="i4x://edX/open_ended/combinedopenended/SampleQuestion"/>
\ No newline at end of file
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