Commit b999714e by Jesse Zoldak

Merge pull request #6111 from edx/zoldak/modulestore-test-config

Unit test speed improvements
parents cc377e8c 77bbd303
import unittest
from opaque_keys.edx.locator import LocalId
from xmodule import templates
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.tests import persistent_factories
......@@ -7,10 +9,9 @@ from xmodule.course_module import CourseDescriptor
from xmodule.modulestore.django import modulestore, clear_existing_modulestores
from xmodule.seq_module import SequenceDescriptor
from xmodule.capa_module import CapaDescriptor
from opaque_keys.edx.locator import BlockUsageLocator, LocalId
from xmodule.contentstore.django import _CONTENTSTORE
from xmodule.modulestore.exceptions import ItemNotFoundError, DuplicateCourseError
from xmodule.html_module import HtmlDescriptor
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
class TemplateTests(unittest.TestCase):
......@@ -20,10 +21,22 @@ class TemplateTests(unittest.TestCase):
def setUp(self):
clear_existing_modulestores() # redundant w/ cleanup but someone was getting errors
self.addCleanup(ModuleStoreTestCase.drop_mongo_collections)
self.addCleanup(self._drop_mongo_collections)
self.addCleanup(clear_existing_modulestores)
self.split_store = modulestore()._get_modulestore_by_type(ModuleStoreEnum.Type.split)
@staticmethod
def _drop_mongo_collections():
"""
If using a Mongo-backed modulestore & contentstore, drop the collections.
"""
module_store = modulestore()
if hasattr(module_store, '_drop_database'):
module_store._drop_database() # pylint: disable=protected-access
_CONTENTSTORE.clear()
if hasattr(module_store, 'close_connections'):
module_store.close_connections()
def test_get_templates(self):
found = templates.all_templates()
self.assertIsNotNone(found.get('course'))
......
......@@ -7,6 +7,8 @@ import pytz
from tempfile import mkdtemp
from uuid import uuid4
from mock import patch
from django.conf import settings
from django.contrib.auth.models import User
from django.test import TestCase
......@@ -276,10 +278,14 @@ class ModuleStoreTestCase(TestCase):
return updated_course
@staticmethod
def drop_mongo_collections():
@patch('xmodule.modulestore.django.create_modulestore_instance')
def drop_mongo_collections(mock_create):
"""
If using a Mongo-backed modulestore & contentstore, drop the collections.
"""
# Do not create the modulestore if it does not exist.
mock_create.return_value = None
module_store = modulestore()
if hasattr(module_store, '_drop_database'):
module_store._drop_database() # pylint: disable=protected-access
......@@ -302,7 +308,6 @@ class ModuleStoreTestCase(TestCase):
"""
Flush the ModuleStore.
"""
# Flush the Mongo modulestore
self.drop_mongo_collections()
......
......@@ -15,8 +15,9 @@ sessions. Assumes structure:
from .common import *
import os
from path import path
from warnings import filterwarnings, simplefilter
from tempfile import mkdtemp
from uuid import uuid4
from warnings import filterwarnings, simplefilter
# mongo connection settings
MONGO_PORT_NUM = int(os.environ.get('EDXAPP_TEST_MONGO_PORT', '27017'))
......@@ -130,7 +131,7 @@ update_module_store_settings(
'fs_root': TEST_ROOT / "data",
},
xml_store_options={
'data_dir': COMMON_TEST_DATA_ROOT,
'data_dir': mkdtemp(), # never inadvertently load all the XML courses
},
doc_store_settings={
'host': MONGO_HOST,
......
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