Commit 9d34767e by Ned Batchelder

Fix the remaining module storage tests.

parent 08acf435
......@@ -25,7 +25,7 @@ def chunks(items, chunk_size):
class ModelDataCache(object):
"""
A cache of django model objects needed to supply the data
for a module and its decendents
for a module and its decendants
"""
def __init__(self, descriptors, course_id, user, select_for_update=False):
'''
......@@ -35,10 +35,10 @@ class ModelDataCache(object):
state will have a StudentModule.
Arguments
descriptors: An array of XModuleDescriptors.
descriptors: A list of XModuleDescriptors.
course_id: The id of the current course
user: The user for which to cache data
select_for_update: Flag indicating whether the rows should be locked until end of transaction
select_for_update: True if rows should be locked until end of transaction
'''
self.cache = {}
self.descriptors = descriptors
......
......@@ -131,7 +131,8 @@ class TestStudentModuleStorage(TestCase):
def setUp(self):
self.desc_md = {}
self.user = UserFactory.create()
student_module = StudentModuleFactory(state=json.dumps({'a_field': 'a_value'}))
self.user = student_module.student
self.mdc = ModelDataCache([mock_descriptor([mock_field(Scope.student_state, 'a_field')])], course_id, self.user)
self.kvs = LmsKeyValueStore(self.desc_md, self.mdc)
......@@ -159,7 +160,7 @@ class TestStudentModuleStorage(TestCase):
"Test that deleting an existing field removes it from the StudentModule"
self.kvs.delete(student_state_key('a_field'))
self.assertEquals(1, StudentModule.objects.all().count())
self.assertEquals({}, self.mdc.find.return_value.state)
self.assertRaises(KeyError, self.kvs.get, student_state_key('not_a_field'))
def test_delete_missing_field(self):
"Test that deleting a missing field from an existing StudentModule raises a KeyError"
......
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