Commit 7c48f9a5 by Chris Dodge

add unit test to verify that the store updated signal actually fired. Also fix…

add unit test to verify that the store updated signal actually fired. Also fix bug where cloning item doesn't update the inherited metadata caches
parent a3de4ff6
...@@ -13,6 +13,7 @@ import copy ...@@ -13,6 +13,7 @@ import copy
from json import loads from json import loads
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.dispatch import Signal
from contentstore.utils import get_modulestore from contentstore.utils import get_modulestore
from .utils import ModuleStoreTestCase, parse_json from .utils import ModuleStoreTestCase, parse_json
...@@ -591,6 +592,32 @@ class ContentStoreTest(ModuleStoreTestCase): ...@@ -591,6 +592,32 @@ class ContentStoreTest(ModuleStoreTestCase):
self.assertNotEquals(new_discussion_item.discussion_id, '$$GUID$$') self.assertNotEquals(new_discussion_item.discussion_id, '$$GUID$$')
def test_update_modulestore_signal_did_fire(self):
import_from_xml(modulestore(), 'common/test/data/', ['full'])
module_store = modulestore('direct')
try:
module_store.modulestore_update_signal = Signal(providing_args=['modulestore', 'course_id', 'location'])
self.got_signal = False
def _signal_hander(modulestore=None, course_id=None, location=None, **kwargs):
self.got_signal = True
module_store.modulestore_update_signal.connect(_signal_hander)
new_component_location = Location('i4x', 'edX', 'full', 'html', 'new_component')
source_template_location = Location('i4x', 'edx', 'templates', 'html', 'Blank_HTML_Page')
# crate a new module
module_store.clone_item(source_template_location, new_component_location)
finally:
module_store.modulestore_update_signal = None
self.assertTrue(self.got_signal)
def test_metadata_inheritance(self): def test_metadata_inheritance(self):
import_from_xml(modulestore(), 'common/test/data/', ['full']) import_from_xml(modulestore(), 'common/test/data/', ['full'])
......
...@@ -537,6 +537,7 @@ class MongoModuleStore(ModuleStoreBase): ...@@ -537,6 +537,7 @@ class MongoModuleStore(ModuleStoreBase):
Clone a new item that is a copy of the item at the location `source` Clone a new item that is a copy of the item at the location `source`
and writes it to `location` and writes it to `location`
""" """
item = None
try: try:
source_item = self.collection.find_one(location_to_query(source)) source_item = self.collection.find_one(location_to_query(source))
...@@ -568,7 +569,6 @@ class MongoModuleStore(ModuleStoreBase): ...@@ -568,7 +569,6 @@ class MongoModuleStore(ModuleStoreBase):
course.tabs = existing_tabs course.tabs = existing_tabs
self.update_metadata(course.location, course._model_data._kvs._metadata) self.update_metadata(course.location, course._model_data._kvs._metadata)
return item
except pymongo.errors.DuplicateKeyError: except pymongo.errors.DuplicateKeyError:
raise DuplicateItemError(location) raise DuplicateItemError(location)
...@@ -576,6 +576,8 @@ class MongoModuleStore(ModuleStoreBase): ...@@ -576,6 +576,8 @@ class MongoModuleStore(ModuleStoreBase):
self.refresh_cached_metadata_inheritance_tree(Location(location)) self.refresh_cached_metadata_inheritance_tree(Location(location))
self.fire_updated_modulestore_signal(get_course_id_no_run(Location(location)), Location(location)) self.fire_updated_modulestore_signal(get_course_id_no_run(Location(location)), Location(location))
return item
def fire_updated_modulestore_signal(self, course_id, location): def fire_updated_modulestore_signal(self, course_id, location):
if self.modulestore_update_signal is not None: if self.modulestore_update_signal is not None:
self.modulestore_update_signal.send(self, modulestore=self, course_id=course_id, self.modulestore_update_signal.send(self, modulestore=self, course_id=course_id,
......
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