Commit abf4ad36 by Jay Zoldak

Move modulestore unique naming in tests from the settings.py file into the…

Move modulestore unique naming in tests from the settings.py file into the ModuleStoreTestCase class.
parent fde6d1ba
from django.test.testcases import TestCase
from cache_toolbox.core import get_cached_content, set_cached_content, del_cached_content from cache_toolbox.core import get_cached_content, set_cached_content, del_cached_content
from xmodule.modulestore import Location from xmodule.modulestore import Location
from xmodule.contentstore.content import StaticContent from xmodule.contentstore.content import StaticContent
from django.test import TestCase
class Content: class Content:
def __init__(self, location, content): def __init__(self, location, content):
...@@ -32,7 +32,3 @@ class CachingTestCase(TestCase): ...@@ -32,7 +32,3 @@ class CachingTestCase(TestCase):
'should not be stored in cache with unicodeLocation') 'should not be stored in cache with unicodeLocation')
self.assertEqual(None, get_cached_content(self.nonUnicodeLocation), self.assertEqual(None, get_cached_content(self.nonUnicodeLocation),
'should not be stored in cache with nonUnicodeLocation') 'should not be stored in cache with nonUnicodeLocation')
...@@ -6,7 +6,6 @@ import copy ...@@ -6,7 +6,6 @@ import copy
from util import converters from util import converters
from util.converters import jsdate_to_time from util.converters import jsdate_to_time
from django.test.testcases import TestCase
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.test.client import Client from django.test.client import Client
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
...@@ -19,6 +18,7 @@ from cms.djangoapps.models.settings.course_details import (CourseDetails, ...@@ -19,6 +18,7 @@ from cms.djangoapps.models.settings.course_details import (CourseDetails,
from cms.djangoapps.models.settings.course_grading import CourseGradingModel from cms.djangoapps.models.settings.course_grading import CourseGradingModel
from cms.djangoapps.contentstore.utils import get_modulestore from cms.djangoapps.contentstore.utils import get_modulestore
from django.test import TestCase
from utils import ModuleStoreTestCase from utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
......
from django.test.testcases import TestCase
from cms.djangoapps.contentstore import utils from cms.djangoapps.contentstore import utils
import mock import mock
from django.test import TestCase
class LMSLinksTestCase(TestCase): class LMSLinksTestCase(TestCase):
def about_page_test(self): def about_page_test(self):
......
import json import json
import shutil import shutil
from django.test import TestCase
from django.test.client import Client from django.test.client import Client
from override_settings import override_settings from override_settings import override_settings
from django.conf import settings from django.conf import settings
...@@ -29,7 +28,7 @@ from xmodule.seq_module import SequenceDescriptor ...@@ -29,7 +28,7 @@ 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 ModuleStoreTestCase, parse_json, user, registration from utils import ModuleStoreTestCase, parse_json, user, registration
class ContentStoreTestCase(TestCase): class ContentStoreTestCase(ModuleStoreTestCase):
def _login(self, email, pw): def _login(self, email, pw):
"""Login. View should always return 200. The success/fail is in the """Login. View should always return 200. The success/fail is in the
returned json""" returned json"""
......
from django.test import TestCase
import json import json
import copy
from time import time
from django.test import TestCase
from override_settings import override_settings
from django.conf import settings
from student.models import Registration from student.models import Registration
from django.contrib.auth.models import User from django.contrib.auth.models import User
...@@ -7,14 +11,23 @@ from django.contrib.auth.models import User ...@@ -7,14 +11,23 @@ from django.contrib.auth.models import User
import xmodule.modulestore.django import xmodule.modulestore.django
from xmodule.templates import update_templates from xmodule.templates import update_templates
# Subclass TestCase and use to initialize the contentstore
class ModuleStoreTestCase(TestCase): class ModuleStoreTestCase(TestCase):
""" Subclass for any test case that uses the mongodb """ Subclass for any test case that uses the mongodb
module store. This clears it out before running the TestCase module store. This clears it out before running the TestCase
and reinitilizes it with the templates afterwards. """ and reinitilizes it with the templates afterwards. """
def _pre_setup(self): def _pre_setup(self):
super(ModuleStoreTestCase, self)._pre_setup() super(ModuleStoreTestCase, self)._pre_setup()
# Use the current seconds since epoch to differentiate
# the mongo collections on jenkins.
sec_since_epoch = '%s' % int(time()*100)
self.orig_MODULESTORE = copy.deepcopy(settings.MODULESTORE)
self.test_MODULESTORE = self.orig_MODULESTORE
self.test_MODULESTORE['default']['OPTIONS']['collection'] = 'modulestore_%s' % sec_since_epoch
self.test_MODULESTORE['direct']['OPTIONS']['collection'] = 'modulestore_%s' % sec_since_epoch
settings.MODULESTORE = self.test_MODULESTORE
# Flush and initialize the module store # Flush and initialize the module store
# It needs the templates because it creates new records # It needs the templates because it creates new records
# by cloning from the template. # by cloning from the template.
...@@ -27,12 +40,14 @@ class ModuleStoreTestCase(TestCase): ...@@ -27,12 +40,14 @@ class ModuleStoreTestCase(TestCase):
update_templates() update_templates()
def _post_teardown(self): def _post_teardown(self):
# Make sure you flush out the test modulestore after the end # Make sure you flush out the modulestore.
# of the last test so the collection will be deleted. # Drop the collection at the end of the test,
# Otherwise there will be lingering collections leftover # otherwise there will be lingering collections leftover
# from executing the tests. # from executing the tests.
xmodule.modulestore.django._MODULESTORES = {} xmodule.modulestore.django._MODULESTORES = {}
xmodule.modulestore.django.modulestore().collection.drop() xmodule.modulestore.django.modulestore().collection.drop()
settings.MODULESTORE = self.orig_MODULESTORE
super(ModuleStoreTestCase, self)._post_teardown() super(ModuleStoreTestCase, self)._post_teardown()
def parse_json(response): def parse_json(response):
......
...@@ -10,7 +10,6 @@ sessions. Assumes structure: ...@@ -10,7 +10,6 @@ sessions. Assumes structure:
from .common import * from .common import *
import os import os
from path import path from path import path
from time import time
# Nose Test Runner # Nose Test Runner
INSTALLED_APPS += ('django_nose',) INSTALLED_APPS += ('django_nose',)
...@@ -39,14 +38,11 @@ STATICFILES_DIRS += [ ...@@ -39,14 +38,11 @@ STATICFILES_DIRS += [
if os.path.isdir(COMMON_TEST_DATA_ROOT / course_dir) if os.path.isdir(COMMON_TEST_DATA_ROOT / course_dir)
] ]
# Use the current seconds since epoch to differentiate
# the mongo collections on jenkins.
sec_since_epoch = '%s' % int(time()*100)
modulestore_options = { modulestore_options = {
'default_class': 'xmodule.raw_module.RawDescriptor', 'default_class': 'xmodule.raw_module.RawDescriptor',
'host': 'localhost', 'host': 'localhost',
'db': 'test_xmodule', 'db': 'test_xmodule',
'collection': 'modulestore_%s' % sec_since_epoch, 'collection': 'modulestore',
'fs_root': GITHUB_REPO_ROOT, 'fs_root': GITHUB_REPO_ROOT,
'render_template': 'mitxmako.shortcuts.render_to_string', 'render_template': 'mitxmako.shortcuts.render_to_string',
} }
......
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