Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions cms/djangoapps/contentstore/tests/test_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@
#pylint: disable=W0621
#pylint: disable=W0212

from datetime import datetime, timedelta
from datetime import datetime
from io import BytesIO
from pytz import UTC
import json
import re
from unittest import TestCase, skip
from .utils import CourseTestCase
from contentstore.views import assets
from xmodule.contentstore.content import StaticContent, XASSET_LOCATION_TAG
from xmodule.contentstore.content import StaticContent
from xmodule.modulestore import Location
from xmodule.contentstore.django import contentstore
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.xml_importer import import_from_xml
from xmodule.modulestore.django import loc_mapper
from xmodule.modulestore.mongo.base import location_to_query


class AssetsTestCase(CourseTestCase):
Expand Down
15 changes: 9 additions & 6 deletions common/lib/xmodule/xmodule/modulestore/tests/django_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.test import TestCase
from xmodule.modulestore.django import editable_modulestore, \
clear_existing_modulestores
from xmodule.contentstore.django import contentstore


def mixed_store_config(data_dir, mappings):
Expand Down Expand Up @@ -211,17 +212,19 @@ def update_course(course, data):
return updated_course

@staticmethod
def drop_mongo_collection():
def drop_mongo_collections():
"""
If using a Mongo-backed modulestore, drop the collection.
If using a Mongo-backed modulestore & contentstore, drop the collections.
"""

# This will return the mongo-backed modulestore
# even if we're using a mixed modulestore
store = editable_modulestore()

if hasattr(store, 'collection'):
store.collection.drop()
if contentstore().fs_files:
db = contentstore().fs_files.database
db.connection.drop_database(db)

@classmethod
def setUpClass(cls):
Expand All @@ -241,7 +244,7 @@ def tearDownClass(cls):
Clean up any data stored in Mongo.
"""
# Clean up by flushing the Mongo modulestore
cls.drop_mongo_collection()
cls.drop_mongo_collections()

# Clear out the existing modulestores,
# which will cause them to be re-created
Expand All @@ -257,7 +260,7 @@ def _pre_setup(self):
"""

# Flush the Mongo modulestore
ModuleStoreTestCase.drop_mongo_collection()
ModuleStoreTestCase.drop_mongo_collections()

# Call superclass implementation
super(ModuleStoreTestCase, self)._pre_setup()
Expand All @@ -266,7 +269,7 @@ def _post_teardown(self):
"""
Flush the ModuleStore after each test.
"""
ModuleStoreTestCase.drop_mongo_collection()
ModuleStoreTestCase.drop_mongo_collections()

# Call superclass implementation
super(ModuleStoreTestCase, self)._post_teardown()