Move some functions, make notification tests more robust
This commit is contained in:
@@ -44,7 +44,6 @@ class DummySystemUser(object):
|
||||
modulestore = XMLModuleStore(DATA_DIR, course_dirs=[name])
|
||||
courses = modulestore.get_courses()
|
||||
self.modulestore = modulestore
|
||||
self.assertEquals(len(courses), 1)
|
||||
return courses[0]
|
||||
|
||||
def get_module_from_location(self, location, course):
|
||||
@@ -52,4 +51,16 @@ class DummySystemUser(object):
|
||||
if not isinstance(location, Location):
|
||||
location = Location(location)
|
||||
descriptor = self.modulestore.get_instance(course.id, location, depth=None)
|
||||
return descriptor.xmodule(self.test_system)
|
||||
return descriptor.xmodule(self.test_system)
|
||||
|
||||
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
|
||||
@@ -2,21 +2,14 @@ import json
|
||||
from mock import Mock, MagicMock, ANY
|
||||
import unittest
|
||||
|
||||
from fs.memoryfs import MemoryFS
|
||||
from mock import patch
|
||||
|
||||
from dummy_system import DummySystemUser
|
||||
from dummy_system import DummySystemUser, MockQueryDict
|
||||
|
||||
from xmodule.open_ended_grading_classes.openendedchild import OpenEndedChild
|
||||
from xmodule.open_ended_grading_classes.open_ended_module import OpenEndedModule
|
||||
from xmodule.open_ended_grading_classes.combined_open_ended_modulev1 import CombinedOpenEndedV1Module
|
||||
from xmodule.open_ended_grading_classes.grading_service_module import GradingServiceError
|
||||
from xmodule.combined_open_ended_module import CombinedOpenEndedModule
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from xmodule.modulestore import Location
|
||||
from xmodule.modulestore.xml import ImportSystem, XMLModuleStore
|
||||
|
||||
from xmodule.tests.test_export import DATA_DIR
|
||||
|
||||
from lxml import etree
|
||||
import capa.xqueue_interface as xqueue_interface
|
||||
@@ -27,23 +20,11 @@ log = logging.getLogger(__name__)
|
||||
|
||||
from . import test_system
|
||||
|
||||
ORG = 'test_org'
|
||||
ORG = 'edX'
|
||||
COURSE = 'open_ended' # name of directory with course data
|
||||
|
||||
import test_util_open_ended
|
||||
|
||||
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
|
||||
|
||||
"""
|
||||
Tests for the various pieces of the CombinedOpenEndedGrading system
|
||||
|
||||
@@ -492,7 +473,7 @@ class CombinedOpenEndedModuleTest(unittest.TestCase):
|
||||
self.assertEqual(score_dict['total'], 15.0)
|
||||
|
||||
class OpenEndedModuleXmlTest(unittest.TestCase, DummySystemUser):
|
||||
problem_location = Location(["i4x", "edX", "oe_test", "combinedopenended", "SampleQuestion"])
|
||||
problem_location = Location(["i4x", "edX", "open_ended", "combinedopenended", "SampleQuestion"])
|
||||
answer = "blah blah"
|
||||
assessment = [0,1]
|
||||
hint = "blah"
|
||||
|
||||
@@ -14,17 +14,13 @@ COURSE="open_ended"
|
||||
|
||||
|
||||
class PeerGradingModuleTest(unittest.TestCase, DummySystemUser):
|
||||
location = Location(["i4x", "edX", "open_ended", "peergrading",
|
||||
"SampleQuestion"])
|
||||
max_score = 1
|
||||
|
||||
definition = "<peergrading/>"
|
||||
descriptor = Mock(data=definition)
|
||||
problem_location = Location(["i4x", "edX", "open_ended", "peergrading",
|
||||
"PeerGradingSample"])
|
||||
|
||||
def setUp(self):
|
||||
self.test_system = test_system()
|
||||
self.test_system.open_ended_grading_interface = None
|
||||
self.peer_grading = PeerGradingModule(self.test_system, self.location,self.descriptor, model_data={'data': self.definition})
|
||||
self.peer_grading = self.get_module_from_location(self.problem_location, COURSE)
|
||||
|
||||
def test_module_closed(self):
|
||||
closed = self.peer_grading.closed()
|
||||
|
||||
@@ -1 +1 @@
|
||||
<course org="edX" course="oe_test" url_name="2012_Fall"/>
|
||||
<course org="edX" course="open_ended" url_name="2012_Fall"/>
|
||||
|
||||
@@ -84,7 +84,13 @@ class TestStaffGradingService(LoginEnrollmentTestCase):
|
||||
data = {'location': self.location}
|
||||
|
||||
r = self.check_for_post_code(200, url, data)
|
||||
d = json.loads(r.content)
|
||||
|
||||
d = r.content
|
||||
try:
|
||||
d = json.loads(d)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
self.assertTrue(d['success'])
|
||||
self.assertEquals(d['submission_id'], self.mock_service.cnt)
|
||||
self.assertIsNotNone(d['submission'])
|
||||
@@ -112,7 +118,11 @@ class TestStaffGradingService(LoginEnrollmentTestCase):
|
||||
data.update({'skipped' : True})
|
||||
|
||||
r = self.check_for_post_code(200, url, data)
|
||||
d = json.loads(r.content)
|
||||
d = r.content
|
||||
try:
|
||||
d = json.loads(d)
|
||||
except Exception:
|
||||
pass
|
||||
self.assertTrue(d['success'], str(d))
|
||||
self.assertEquals(d['submission_id'], self.mock_service.cnt)
|
||||
|
||||
@@ -129,7 +139,11 @@ class TestStaffGradingService(LoginEnrollmentTestCase):
|
||||
data = {}
|
||||
|
||||
r = self.check_for_post_code(200, url, data)
|
||||
d = json.loads(r.content)
|
||||
d = r.content
|
||||
try:
|
||||
d = json.loads(d)
|
||||
except Exception:
|
||||
pass
|
||||
self.assertTrue(d['success'], str(d))
|
||||
self.assertIsNotNone(d['problem_list'])
|
||||
|
||||
@@ -179,7 +193,11 @@ class TestPeerGradingService(LoginEnrollmentTestCase):
|
||||
data = {'location': self.location}
|
||||
|
||||
r = self.peer_module.get_next_submission(data)
|
||||
d = json.loads(r)
|
||||
d = r
|
||||
try:
|
||||
d = json.loads(d)
|
||||
except Exception:
|
||||
pass
|
||||
self.assertTrue(d['success'])
|
||||
self.assertIsNotNone(d['submission_id'])
|
||||
self.assertIsNotNone(d['prompt'])
|
||||
@@ -213,7 +231,11 @@ class TestPeerGradingService(LoginEnrollmentTestCase):
|
||||
qdict.keys = data.keys
|
||||
|
||||
r = self.peer_module.save_grade(qdict)
|
||||
d = json.loads(r)
|
||||
d = r
|
||||
try:
|
||||
d = json.loads(d)
|
||||
except Exception:
|
||||
pass
|
||||
self.assertTrue(d['success'])
|
||||
|
||||
def test_save_grade_missing_keys(self):
|
||||
@@ -225,7 +247,11 @@ class TestPeerGradingService(LoginEnrollmentTestCase):
|
||||
def test_is_calibrated_success(self):
|
||||
data = {'location': self.location}
|
||||
r = self.peer_module.is_student_calibrated(data)
|
||||
d = json.loads(r)
|
||||
d = r
|
||||
try:
|
||||
d = json.loads(d)
|
||||
except Exception:
|
||||
pass
|
||||
self.assertTrue(d['success'])
|
||||
self.assertTrue('calibrated' in d)
|
||||
|
||||
@@ -239,9 +265,11 @@ class TestPeerGradingService(LoginEnrollmentTestCase):
|
||||
data = {'location': self.location}
|
||||
|
||||
r = self.peer_module.show_calibration_essay(data)
|
||||
d = json.loads(r)
|
||||
log.debug(d)
|
||||
log.debug(type(d))
|
||||
d = r
|
||||
try:
|
||||
d = json.loads(r)
|
||||
except Exception:
|
||||
pass
|
||||
self.assertTrue(d['success'])
|
||||
self.assertIsNotNone(d['submission_id'])
|
||||
self.assertIsNotNone(d['prompt'])
|
||||
|
||||
Reference in New Issue
Block a user