Commit 835f1879 by Victor Shnayder

Make tests pass again

parent d28cd4f4
...@@ -38,7 +38,7 @@ class MockStaffGradingService(object): ...@@ -38,7 +38,7 @@ class MockStaffGradingService(object):
'rubric': 'A rubric'}) 'rubric': 'A rubric'})
def save_grade(self, course_id, grader_id, submission_id, score, feedback): def save_grade(self, course_id, grader_id, submission_id, score, feedback):
return self.get_next(course_id) return self.get_next(course_id, grader_id)
class StaffGradingService(object): class StaffGradingService(object):
...@@ -140,8 +140,28 @@ class StaffGradingService(object): ...@@ -140,8 +140,28 @@ class StaffGradingService(object):
return r.text return r.text
_service = StaffGradingService(settings.STAFF_GRADING_INTERFACE) # don't initialize until grading_service() is called--means that just
#_service = MockStaffGradingService() # importing this file doesn't create objects that may not have the right config
_service = None
def grading_service():
"""
Return a staff grading service instance--if settings.MOCK_STAFF_GRADING is True,
returns a mock one, otherwise a real one.
Caches the result, so changing the setting after the first call to this
function will have no effect.
"""
global _service
if _service is not None:
return _service
if settings.MOCK_STAFF_GRADING:
_service = MockStaffGradingService()
else:
_service = StaffGradingService(settings.STAFF_GRADING_INTERFACE)
return _service
def _err_response(msg): def _err_response(msg):
""" """
...@@ -194,7 +214,7 @@ def _get_next(course_id, grader_id): ...@@ -194,7 +214,7 @@ def _get_next(course_id, grader_id):
""" """
try: try:
return _service.get_next(course_id, grader_id) return grading_service().get_next(course_id, grader_id)
except GradingServiceError: except GradingServiceError:
log.exception("Error from grading service") log.exception("Error from grading service")
return json.dumps({'success': False, 'error': 'Could not connect to grading service'}) return json.dumps({'success': False, 'error': 'Could not connect to grading service'})
...@@ -228,7 +248,7 @@ def save_grade(request, course_id): ...@@ -228,7 +248,7 @@ def save_grade(request, course_id):
p = request.POST p = request.POST
try: try:
result_json = _service.save_grade(course_id, result_json = grading_service().save_grade(course_id,
grader_id, grader_id,
p['submission_id'], p['submission_id'],
p['score'], p['score'],
......
...@@ -233,6 +233,14 @@ class TestStaffGradingService(ct.PageLoader): ...@@ -233,6 +233,14 @@ class TestStaffGradingService(ct.PageLoader):
def setUp(self): def setUp(self):
xmodule.modulestore.django._MODULESTORES = {} xmodule.modulestore.django._MODULESTORES = {}
self.student = 'view@test.com'
self.instructor = 'view2@test.com'
self.password = 'foo'
self.create_account('u1', self.student, self.password)
self.create_account('u2', self.instructor, self.password)
self.activate_user(self.student)
self.activate_user(self.instructor)
self.course_id = "edX/toy/2012_Fall" self.course_id = "edX/toy/2012_Fall"
self.toy = modulestore().get_course(self.course_id) self.toy = modulestore().get_course(self.course_id)
def make_instructor(course): def make_instructor(course):
...@@ -242,6 +250,8 @@ class TestStaffGradingService(ct.PageLoader): ...@@ -242,6 +250,8 @@ class TestStaffGradingService(ct.PageLoader):
make_instructor(self.toy) make_instructor(self.toy)
self.mock_service = staff_grading_service.grading_service()
self.logout() self.logout()
def test_access(self): def test_access(self):
...@@ -257,7 +267,6 @@ class TestStaffGradingService(ct.PageLoader): ...@@ -257,7 +267,6 @@ class TestStaffGradingService(ct.PageLoader):
self.check_for_post_code(404, url) self.check_for_post_code(404, url)
@patch.object(staff_grading_service, '_service', _mock_service)
def test_get_next(self): def test_get_next(self):
self.login(self.instructor, self.password) self.login(self.instructor, self.password)
...@@ -266,10 +275,9 @@ class TestStaffGradingService(ct.PageLoader): ...@@ -266,10 +275,9 @@ class TestStaffGradingService(ct.PageLoader):
r = self.check_for_get_code(200, url) r = self.check_for_get_code(200, url)
d = json.loads(r.content) d = json.loads(r.content)
self.assertTrue(d['success']) self.assertTrue(d['success'])
self.assertEquals(d['submission_id'], _mock_service.cnt) self.assertEquals(d['submission_id'], self.mock_service.cnt)
@patch.object(staff_grading_service, '_service', _mock_service)
def test_save_grade(self): def test_save_grade(self):
self.login(self.instructor, self.password) self.login(self.instructor, self.password)
...@@ -281,6 +289,6 @@ class TestStaffGradingService(ct.PageLoader): ...@@ -281,6 +289,6 @@ class TestStaffGradingService(ct.PageLoader):
r = self.check_for_post_code(200, url, data) r = self.check_for_post_code(200, url, data)
d = json.loads(r.content) d = json.loads(r.content)
self.assertTrue(d['success'], str(d)) self.assertTrue(d['success'], str(d))
self.assertEquals(d['submission_id'], _mock_service.cnt) self.assertEquals(d['submission_id'], self.mock_service.cnt)
...@@ -325,6 +325,9 @@ WIKI_LINK_DEFAULT_LEVEL = 2 ...@@ -325,6 +325,9 @@ WIKI_LINK_DEFAULT_LEVEL = 2
################################# Staff grading config ##################### ################################# Staff grading config #####################
STAFF_GRADING_INTERFACE = None STAFF_GRADING_INTERFACE = None
# Used for testing, debugging
MOCK_STAFF_GRADING = False
################################# Jasmine ################################### ################################# Jasmine ###################################
JASMINE_TEST_DIRECTORY = PROJECT_ROOT + '/static/coffee' JASMINE_TEST_DIRECTORY = PROJECT_ROOT + '/static/coffee'
......
...@@ -65,6 +65,10 @@ XQUEUE_INTERFACE = { ...@@ -65,6 +65,10 @@ XQUEUE_INTERFACE = {
} }
XQUEUE_WAITTIME_BETWEEN_REQUESTS = 5 # seconds XQUEUE_WAITTIME_BETWEEN_REQUESTS = 5 # seconds
# Don't rely on a real staff grading backend
MOCK_STAFF_GRADING = True
# TODO (cpennington): We need to figure out how envs/test.py can inject things # TODO (cpennington): We need to figure out how envs/test.py can inject things
# into common.py so that we don't have to repeat this sort of thing # into common.py so that we don't have to repeat this sort of thing
STATICFILES_DIRS = [ STATICFILES_DIRS = [
...@@ -99,7 +103,7 @@ DATABASES = { ...@@ -99,7 +103,7 @@ DATABASES = {
} }
CACHES = { CACHES = {
# This is the cache used for most things. # This is the cache used for most things.
# In staging/prod envs, the sessions also live here. # In staging/prod envs, the sessions also live here.
'default': { 'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
......
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