Commit 5a6b0392 by Jay Zoldak Committed by Jay Zoldak

Reorganize the CmsTestCase subclass

parent 2c5a7ccd
...@@ -29,6 +29,7 @@ from xmodule.course_module import CourseDescriptor ...@@ -29,6 +29,7 @@ from xmodule.course_module import CourseDescriptor
from xmodule.seq_module import SequenceDescriptor from xmodule.seq_module import SequenceDescriptor
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from .utils import CmsTestCase
def parse_json(response): def parse_json(response):
"""Parse response, which is assumed to be json""" """Parse response, which is assumed to be json"""
...@@ -196,7 +197,7 @@ TEST_DATA_MODULESTORE['default']['OPTIONS']['fs_root'] = path('common/test/data' ...@@ -196,7 +197,7 @@ TEST_DATA_MODULESTORE['default']['OPTIONS']['fs_root'] = path('common/test/data'
TEST_DATA_MODULESTORE['direct']['OPTIONS']['fs_root'] = path('common/test/data') TEST_DATA_MODULESTORE['direct']['OPTIONS']['fs_root'] = path('common/test/data')
@override_settings(MODULESTORE=TEST_DATA_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MODULESTORE)
class ContentStoreTest(TestCase): class ContentStoreTest(CmsTestCase):
def setUp(self): def setUp(self):
uname = 'testuser' uname = 'testuser'
...@@ -213,17 +214,6 @@ class ContentStoreTest(TestCase): ...@@ -213,17 +214,6 @@ class ContentStoreTest(TestCase):
self.user.is_staff = True self.user.is_staff = True
self.user.save() self.user.save()
# Flush and initialize the module store
# It needs the templates because it creates new records
# by cloning from the template.
# Note that if your test module gets in some weird state
# (though it shouldn't), do this manually
# from the bash shell to drop it:
# $ mongo test_xmodule --eval "db.dropDatabase()"
_MODULESTORES = {}
modulestore().collection.drop()
update_templates()
self.client = Client() self.client = Client()
self.client.login(username=uname, password=password) self.client.login(username=uname, password=password)
...@@ -234,15 +224,6 @@ class ContentStoreTest(TestCase): ...@@ -234,15 +224,6 @@ class ContentStoreTest(TestCase):
'display_name': 'Robot Super Course', 'display_name': 'Robot Super Course',
} }
def tearDown(self):
# Make sure you flush out the test modulestore after the end
# of the last test because otherwise on the next run
# cms/djangoapps/contentstore/__init__.py
# update_templates() will try to update the templates
# via upsert and it sometimes seems to be messing things up.
_MODULESTORES = {}
modulestore().collection.drop()
def test_create_course(self): def test_create_course(self):
"""Test new course creation - happy path""" """Test new course creation - happy path"""
resp = self.client.post(reverse('create_new_course'), self.course_data) resp = self.client.post(reverse('create_new_course'), self.course_data)
......
from django.test import TestCase
from xmodule.modulestore.django import modulestore, _MODULESTORES
from xmodule.templates import update_templates
# Subclass TestCase and use to initialize the contentstore
class CmsTestCase(TestCase):
""" Subclass for any test case that uses the mongodb
module store. This clears it out before running the TestCase
and reinitilizes it with the templates afterwards. """
def _pre_setup(self):
super(CmsTestCase, self)._pre_setup()
# Flush and initialize the module store
# It needs the templates because it creates new records
# by cloning from the template.
# Note that if your test module gets in some weird state
# (though it shouldn't), do this manually
# from the bash shell to drop it:
# $ mongo test_xmodule --eval "db.dropDatabase()"
_MODULESTORES = {}
modulestore().collection.drop()
update_templates()
def _post_teardown(self):
# Make sure you flush out the test modulestore after the end
# of the last test because otherwise on the next run
# cms/djangoapps/contentstore/__init__.py
# update_templates() will try to update the templates
# via upsert and it sometimes seems to be messing things up.
_MODULESTORES = {}
modulestore().collection.drop()
super(CmsTestCase, self)._post_teardown()
\ No newline at end of file
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