Commit bd65cfa8 by Will Daly

Removed outdated template logic in ModuleStoreTestCase

parent 05b34098
...@@ -110,10 +110,11 @@ def xml_store_config(data_dir): ...@@ -110,10 +110,11 @@ def xml_store_config(data_dir):
class ModuleStoreTestCase(TestCase): class ModuleStoreTestCase(TestCase):
""" Subclass for any test case that uses the mongodb """
module store. This populates a uniquely named modulestore Subclass for any test case that uses a ModuleStore.
collection with templates before running the TestCase
and drops it they are finished. """ Ensures that the ModuleStore is cleaned before/after each test.
"""
@staticmethod @staticmethod
def update_course(course, data): def update_course(course, data):
...@@ -132,24 +133,19 @@ class ModuleStoreTestCase(TestCase): ...@@ -132,24 +133,19 @@ class ModuleStoreTestCase(TestCase):
return updated_course return updated_course
@staticmethod @staticmethod
def flush_mongo_except_templates(): def drop_mongo_collection():
""" """
Delete everything in the module store except templates. If using a Mongo-backed modulestore, drop the collection.
""" """
store = modulestore() store = modulestore()
# This query means: every item in the collection if hasattr(store, 'collection'):
# that is not a template store.collection.drop()
query = {"_id.course": {"$ne": "templates"}}
# Remove everything except templates
store.collection.remove(query)
store.collection.drop()
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
""" """
Flush the mongo store and set up templates. Flush the ModuleStore.
""" """
# Use a uuid to differentiate # Use a uuid to differentiate
...@@ -173,8 +169,7 @@ class ModuleStoreTestCase(TestCase): ...@@ -173,8 +169,7 @@ class ModuleStoreTestCase(TestCase):
""" """
# Clean up by dropping the collection # Clean up by dropping the collection
store = modulestore() cls.drop_mongo_collection()
store.collection.drop()
clear_existing_modulestores() clear_existing_modulestores()
...@@ -183,21 +178,20 @@ class ModuleStoreTestCase(TestCase): ...@@ -183,21 +178,20 @@ class ModuleStoreTestCase(TestCase):
def _pre_setup(self): def _pre_setup(self):
""" """
Remove everything but the templates before each test. Flush the ModuleStore before each test.
""" """
# Flush anything that is not a template # Flush the Mongo modulestore
ModuleStoreTestCase.flush_mongo_except_templates() ModuleStoreTestCase.drop_mongo_collection()
# Call superclass implementation # Call superclass implementation
super(ModuleStoreTestCase, self)._pre_setup() super(ModuleStoreTestCase, self)._pre_setup()
def _post_teardown(self): def _post_teardown(self):
""" """
Flush everything we created except the templates. Flush the ModuleStore after each test.
""" """
# Flush anything that is not a template ModuleStoreTestCase.drop_mongo_collection()
ModuleStoreTestCase.flush_mongo_except_templates()
# Call superclass implementation # Call superclass implementation
super(ModuleStoreTestCase, self)._post_teardown() super(ModuleStoreTestCase, self)._post_teardown()
......
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