Merge pull request #6752 from cpennington/modulestore-test-case-cleanup

Clean up ModuleStoreTestCase
This commit is contained in:
Calen Pennington
2015-02-04 15:57:01 -05:00
169 changed files with 540 additions and 448 deletions

View File

@@ -22,6 +22,8 @@ class ExportAllCourses(ModuleStoreTestCase):
"""
def setUp(self):
""" Common setup. """
super(ExportAllCourses, self).setUp()
self.content_store = contentstore()
self.module_store = modulestore()

View File

@@ -16,6 +16,8 @@ class TestArgParsing(unittest.TestCase):
Tests for parsing arguments for the `create_course` management command
"""
def setUp(self):
super(TestArgParsing, self).setUp()
self.command = Command()
def test_no_args(self):

View File

@@ -18,6 +18,7 @@ class ExportAllCourses(ModuleStoreTestCase):
"""
def setUp(self):
""" Common setup. """
super(ExportAllCourses, self).setUp()
self.store = modulestore()._get_modulestore_by_type(ModuleStoreEnum.Type.mongo)
self.temp_dir = mkdtemp()
self.first_course = CourseFactory.create(org="test", course="course1", display_name="run1")

View File

@@ -16,6 +16,8 @@ class ConvertExportFormat(TestCase):
"""
def setUp(self):
""" Common setup. """
super(ConvertExportFormat, self).setUp()
self.temp_dir = mkdtemp()
self.data_dir = path(__file__).realpath().parent / 'data'
self.version0 = self.data_dir / "Version0_drafts.tar.gz"

View File

@@ -1747,6 +1747,7 @@ class EntryPageTestCase(TestCase):
Tests entry pages that aren't specific to a course.
"""
def setUp(self):
super(EntryPageTestCase, self).setUp()
self.client = AjaxEnabledTestClient()
def _test_page(self, page, status_code=200):

View File

@@ -20,6 +20,7 @@ class TemplateTests(unittest.TestCase):
"""
def setUp(self):
super(TemplateTests, self).setUp()
clear_existing_modulestores() # redundant w/ cleanup but someone was getting errors
self.addCleanup(self._drop_mongo_collections)
self.addCleanup(clear_existing_modulestores)

View File

@@ -19,6 +19,8 @@ class InternationalizationTest(ModuleStoreTestCase):
will be cleared out before each test case execution and deleted
afterwards.
"""
super(InternationalizationTest, self).setUp(create_user=False)
self.uname = 'testuser'
self.email = 'test+courses@edx.org'
self.password = 'foo'

View File

@@ -28,6 +28,8 @@ TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().
class TestGenerateSubs(unittest.TestCase):
"""Tests for `generate_subs` function."""
def setUp(self):
super(TestGenerateSubs, self).setUp()
self.source_subs = {
'start': [100, 200, 240, 390, 1000],
'end': [200, 240, 380, 1000, 1500],
@@ -93,6 +95,7 @@ class TestSaveSubsToStore(ModuleStoreTestCase):
def setUp(self):
super(TestSaveSubsToStore, self).setUp()
self.course = CourseFactory.create(
org=self.org, number=self.number, display_name=self.display_name)
@@ -183,6 +186,7 @@ class TestDownloadYoutubeSubs(ModuleStoreTestCase):
self.clear_sub_content(subs_id)
def setUp(self):
super(TestDownloadYoutubeSubs, self).setUp()
self.course = CourseFactory.create(
org=self.org, number=self.number, display_name=self.display_name)
@@ -477,6 +481,7 @@ class TestTranscript(unittest.TestCase):
Tests for Transcript class e.g. different transcript conversions.
"""
def setUp(self):
super(TestTranscript, self).setUp()
self.srt_transcript = textwrap.dedent("""\
0

View File

@@ -12,6 +12,7 @@ from contentstore import utils
from contentstore.tests.utils import CourseTestCase
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from xmodule.modulestore.django import modulestore
@@ -164,7 +165,7 @@ class ExtraPanelTabTestCase(TestCase):
self.assertEqual(actual_tabs, expected_tabs)
class CourseImageTestCase(TestCase):
class CourseImageTestCase(ModuleStoreTestCase):
"""Tests for course image URLs."""
def test_get_image_url(self):
@@ -196,6 +197,8 @@ class XBlockVisibilityTestCase(TestCase):
"""Tests for xblock visibility for students."""
def setUp(self):
super(XBlockVisibilityTestCase, self).setUp()
self.dummy_user = ModuleStoreEnum.UserID.test
self.past = datetime(1970, 1, 1)
self.future = datetime.now(UTC) + timedelta(days=1)

View File

@@ -88,6 +88,8 @@ class AuthTestCase(ContentStoreTestCase):
"""Check that various permissions-related things work"""
def setUp(self):
super(AuthTestCase, self).setUp(create_user=False)
self.email = 'a@b.com'
self.pw = 'xyz'
self.username = 'testuser'

View File

@@ -67,7 +67,6 @@ class AjaxEnabledTestClient(Client):
return self.get(path, data or {}, follow, HTTP_ACCEPT="application/json", **extra)
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class CourseTestCase(ModuleStoreTestCase):
"""
Base class for Studio tests that require a logged in user and a course.
@@ -81,6 +80,7 @@ class CourseTestCase(ModuleStoreTestCase):
will be cleared out before each test case execution and deleted
afterwards.
"""
self.user_password = super(CourseTestCase, self).setUp()
self.client = AjaxEnabledTestClient()

View File

@@ -17,6 +17,8 @@ class RolesTest(TestCase):
"""
def setUp(self):
""" Test case setup """
super(RolesTest, self).setUp()
self.global_admin = AdminFactory()
self.instructor = User.objects.create_user('testinstructor', 'testinstructor+courses@edx.org', 'foo')
self.staff = User.objects.create_user('teststaff', 'teststaff+courses@edx.org', 'foo')

View File

@@ -1188,6 +1188,8 @@ class TestEditSplitModule(ItemTest):
@ddt.ddt
class TestComponentHandler(TestCase):
def setUp(self):
super(TestComponentHandler, self).setUp()
self.request_factory = RequestFactory()
patcher = patch('contentstore.views.component.modulestore')

View File

@@ -22,7 +22,7 @@ from cms.djangoapps.xblock_config.models import StudioConfig
from xmodule.modulestore.django import modulestore
class GetPreviewHtmlTestCase(TestCase):
class GetPreviewHtmlTestCase(ModuleStoreTestCase):
"""
Tests for get_preview_fragment.

View File

@@ -6,6 +6,7 @@ from contentstore.tests.utils import CourseTestCase
from django.test import TestCase
from xmodule.x_module import STUDENT_VIEW
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.tabs import CourseTabList, WikiTab
from contentstore.utils import reverse_course_url
from xmodule.modulestore.django import modulestore
@@ -192,7 +193,7 @@ class TabsPageTests(CourseTestCase):
self.assertIn('<span data-tooltip="Drag to reorder" class="drag-handle action"></span>', html)
class PrimitiveTabEdit(TestCase):
class PrimitiveTabEdit(ModuleStoreTestCase):
"""Tests for the primitive tab edit data manipulations"""
def test_delete(self):

View File

@@ -292,6 +292,8 @@ class TextbookValidationTestCase(TestCase):
def setUp(self):
"Set some useful content for tests"
super(TextbookValidationTestCase, self).setUp()
self.tb1 = {
"tab_title": "Hi, mom!",
"url": "/mom.pdf"

View File

@@ -17,14 +17,8 @@ from xmodule.modulestore.tests.django_utils import (
from xmodule.modulestore.tests.factories import CourseFactory, CourseAboutFactory
from student.tests.factories import UserFactory
# Since we don't need any XML course fixtures, use a modulestore configuration
# that disables the XML modulestore.
MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False)
@ddt.ddt
@override_settings(MODULESTORE=MODULESTORE_CONFIG)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class CourseInfoTest(ModuleStoreTestCase, APITestCase):
"""

View File

@@ -16,12 +16,7 @@ from course_about import data
from course_about.errors import CourseNotFoundError
from xmodule.modulestore.django import modulestore
# Since we don't need any XML course fixtures, use a modulestore configuration
# that disables the XML modulestore.
MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False)
@override_settings(MODULESTORE=MODULESTORE_CONFIG)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class CourseAboutDataTest(ModuleStoreTestCase):
"""

View File

@@ -22,14 +22,8 @@ from course_about import api
from course_about.errors import CourseNotFoundError, CourseAboutError
from xmodule.modulestore.django import modulestore
# Since we don't need any XML course fixtures, use a modulestore configuration
# that disables the XML modulestore.
MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False)
@ddt.ddt
@override_settings(MODULESTORE=MODULESTORE_CONFIG)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class CourseInfoTest(ModuleStoreTestCase, APITestCase):
"""

View File

@@ -18,13 +18,7 @@ from student.models import CourseEnrollment
from course_modes.models import CourseMode, Mode
# Since we don't need any XML course fixtures, use a modulestore configuration
# that disables the XML modulestore.
MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False)
@ddt.ddt
@override_settings(MODULESTORE=MODULESTORE_CONFIG)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class CourseModeViewTest(UrlResetMixin, ModuleStoreTestCase):
@patch.dict(settings.FEATURES, {'MODE_CREATION_FOR_TESTING': True})

View File

@@ -16,11 +16,11 @@ from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class EmbargoCourseFormTest(ModuleStoreTestCase):
"""Test the course form properly validates course IDs"""
def setUp(self):
super(EmbargoCourseFormTest, self).setUp()
self.course = CourseFactory.create()
self.true_form_data = {'course_id': self.course.id.to_deprecated_string(), 'embargoed': True}
self.false_form_data = {'course_id': self.course.id.to_deprecated_string(), 'embargoed': False}

View File

@@ -24,19 +24,15 @@ from config_models.models import cache
from embargo.models import EmbargoedCourse, EmbargoedState, IPFilter
# Since we don't need any XML course fixtures, use a modulestore configuration
# that disables the XML modulestore.
MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False)
@ddt.ddt
@override_settings(MODULESTORE=MODULESTORE_CONFIG)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class EmbargoMiddlewareTests(ModuleStoreTestCase):
"""
Tests of EmbargoMiddleware
"""
def setUp(self):
super(EmbargoMiddlewareTests, self).setUp()
self.user = UserFactory(username='fred', password='secret')
self.client.login(username='fred', password='secret')
self.embargo_course = CourseFactory.create()

View File

@@ -19,13 +19,8 @@ from student.tests.factories import UserFactory, CourseModeFactory
from student.models import CourseEnrollment, EnrollmentClosedError, CourseFullError, AlreadyEnrolledError
from enrollment import data
# Since we don't need any XML course fixtures, use a modulestore configuration
# that disables the XML modulestore.
MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False)
@ddt.ddt
@override_settings(MODULESTORE=MODULESTORE_CONFIG)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class EnrollmentDataTest(ModuleStoreTestCase):
"""

View File

@@ -20,13 +20,8 @@ from enrollment.errors import CourseEnrollmentError
from student.tests.factories import UserFactory, CourseModeFactory
from student.models import CourseEnrollment
# Since we don't need any XML course fixtures, use a modulestore configuration
# that disables the XML modulestore.
MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False)
@ddt.ddt
@override_settings(MODULESTORE=MODULESTORE_CONFIG)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class EnrollmentTest(ModuleStoreTestCase, APITestCase):
"""

View File

@@ -73,7 +73,7 @@ def gen_all_identities():
@ddt
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE, SESSION_ENGINE='django.contrib.sessions.backends.cache')
@override_settings(SESSION_ENGINE='django.contrib.sessions.backends.cache')
class ShibSPTest(ModuleStoreTestCase):
"""
Tests for the Shibboleth SP, which communicates via request.META

View File

@@ -14,12 +14,12 @@ from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from student.tests.factories import UserFactory, AnonymousUserFactory
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class CountryMiddlewareTests(TestCase):
"""
Tests of CountryMiddleware.
"""
def setUp(self):
super(CountryMiddlewareTests, self).setUp()
self.country_middleware = CountryMiddleware()
self.session_middleware = SessionMiddleware()
self.authenticated_user = UserFactory.create()

View File

@@ -14,7 +14,6 @@ from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestMidcourseReverificationWindow(ModuleStoreTestCase):
""" Tests for MidcourseReverificationWindow objects """

View File

@@ -27,6 +27,8 @@ class TestTransferStudents(ModuleStoreTestCase):
def setUp(self, **kwargs):
"""Connect a stub receiver, and analytics event tracking."""
super(TestTransferStudents, self).setUp()
UNENROLL_DONE.connect(self.assert_unenroll_signal)
patcher = patch('student.models.tracker')
self.mock_tracker = patcher.start()

View File

@@ -24,13 +24,15 @@ from xmodule.modulestore.tests.factories import CourseFactory
from bulk_email.models import CourseAuthorization # pylint: disable=import-error
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class TestStudentDashboardEmailView(ModuleStoreTestCase):
"""
Check for email view displayed with flag
"""
def setUp(self):
super(TestStudentDashboardEmailView, self).setUp()
self.course = CourseFactory.create()
# Create student account
@@ -90,12 +92,13 @@ class TestStudentDashboardEmailView(ModuleStoreTestCase):
self.assertTrue(self.email_modal_link in response.content)
@override_settings(MODULESTORE=TEST_DATA_MIXED_TOY_MODULESTORE)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class TestStudentDashboardEmailViewXMLBacked(ModuleStoreTestCase):
"""
Check for email view on student dashboard, with XML backed course.
"""
MODULESTORE = TEST_DATA_MIXED_TOY_MODULESTORE
def setUp(self):
self.course_name = 'edX/toy/2012_Fall'

View File

@@ -8,25 +8,19 @@ from mock import patch
from django.test.utils import override_settings
from django.conf import settings
from django.core.urlresolvers import reverse
from xmodule.modulestore.tests.django_utils import (
ModuleStoreTestCase, mixed_store_config
)
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from student.tests.factories import UserFactory, CourseModeFactory
from student.models import CourseEnrollment
# Since we don't need any XML course fixtures, use a modulestore configuration
# that disables the XML modulestore.
MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False)
@ddt.ddt
@override_settings(MODULESTORE=MODULESTORE_CONFIG)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class EnrollmentTest(ModuleStoreTestCase):
"""
Test student enrollment, especially with different course modes.
"""
USERNAME = "Bob"
EMAIL = "bob@example.com"
PASSWORD = "edx"

View File

@@ -319,11 +319,11 @@ class LoginTest(TestCase):
self.assertNotIn(log_string, format_string)
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class ExternalAuthShibTest(ModuleStoreTestCase):
"""
Tests how login_user() interacts with ExternalAuth, in particular Shib
"""
def setUp(self):
super(ExternalAuthShibTest, self).setUp()
self.course = CourseFactory.create(

View File

@@ -12,9 +12,7 @@ from django.test.utils import override_settings
from util.testing import UrlResetMixin
from xmodule.modulestore.tests.factories import CourseFactory
from student.tests.factories import CourseModeFactory
from xmodule.modulestore.tests.django_utils import (
ModuleStoreTestCase, mixed_store_config
)
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
# This relies on third party auth being enabled and configured
@@ -23,10 +21,6 @@ from xmodule.modulestore.tests.django_utils import (
THIRD_PARTY_AUTH_BACKENDS = ["google-oauth2", "facebook"]
THIRD_PARTY_AUTH_PROVIDERS = ["Google", "Facebook"]
# Since we don't need any XML course fixtures, use a modulestore configuration
# that disables the XML modulestore.
MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False)
def _third_party_login_url(backend_name, auth_entry, course_id=None, redirect_url=None):
"""Construct the login URL to start third party authentication. """
@@ -43,13 +37,13 @@ def _third_party_login_url(backend_name, auth_entry, course_id=None, redirect_ur
@ddt.ddt
@override_settings(MODULESTORE=MODULESTORE_CONFIG)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class LoginFormTest(UrlResetMixin, ModuleStoreTestCase):
"""Test rendering of the login form. """
@patch.dict(settings.FEATURES, {"ENABLE_COMBINED_LOGIN_REGISTRATION": False})
def setUp(self):
super(LoginFormTest, self).setUp('lms.urls')
self.url = reverse("signin_user")
self.course = CourseFactory.create()
self.course_id = unicode(self.course.id)
@@ -155,13 +149,13 @@ class LoginFormTest(UrlResetMixin, ModuleStoreTestCase):
@ddt.ddt
@override_settings(MODULESTORE=MODULESTORE_CONFIG)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class RegisterFormTest(UrlResetMixin, ModuleStoreTestCase):
"""Test rendering of the registration form. """
@patch.dict(settings.FEATURES, {"ENABLE_COMBINED_LOGIN_REGISTRATION": False})
def setUp(self):
super(RegisterFormTest, self).setUp('lms.urls')
self.url = reverse("register_user")
self.course = CourseFactory.create()
self.course_id = unicode(self.course.id)

View File

@@ -17,17 +17,13 @@ from student.helpers import (
)
from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, mixed_store_config
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from student.tests.factories import UserFactory, CourseEnrollmentFactory
from course_modes.tests.factories import CourseModeFactory
from verify_student.models import SoftwareSecurePhotoVerification # pylint: disable=F0401
from util.testing import UrlResetMixin
MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False)
@override_settings(MODULESTORE=MODULESTORE_CONFIG)
@patch.dict(settings.FEATURES, {'AUTOMATIC_VERIFY_STUDENT_IDENTITY_FOR_TESTING': True})
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
@ddt.ddt

View File

@@ -28,7 +28,6 @@ from student.views import (process_survey_link, _cert_info,
from student.tests.factories import UserFactory, CourseModeFactory
from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
# These imports refer to lms djangoapps.
# Their testcases are only run under lms.
@@ -180,7 +179,6 @@ class CourseEndingTest(TestCase):
self.assertIsNone(_cert_info(user, course2, cert_status))
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class DashboardTest(ModuleStoreTestCase):
"""
Tests for dashboard utility functions
@@ -615,7 +613,6 @@ class EnrollInCourseTest(TestCase):
self.assert_enrollment_mode_change_event_was_emitted(user, course_id, "honor")
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class ChangeEnrollmentViewTest(ModuleStoreTestCase):
"""Tests the student.views.change_enrollment view"""
@@ -698,7 +695,6 @@ class ChangeEnrollmentViewTest(ModuleStoreTestCase):
self.assertEqual(enrollment_mode, u'honor')
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class PaidRegistrationTest(ModuleStoreTestCase):
"""
Tests for paid registration functionality (not verified student), involves shoppingcart
@@ -731,7 +727,6 @@ class PaidRegistrationTest(ModuleStoreTestCase):
shoppingcart.models.Order.get_cart_for_user(self.user), self.course.id))
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class AnonymousLookupTable(ModuleStoreTestCase):
"""
Tests for anonymous_id_functions

View File

@@ -8,6 +8,9 @@ import xmodule.modulestore.tests.factories as xf
import course_modes.tests.factories as cmf
from lettuce import world
# Unlock XBlock factories, because we're randomizing the collection
# name above to prevent collisions
xf.XMODULE_FACTORY_LOCK.enable()
world.absorb(sf.UserFactory)
world.absorb(sf.UserProfileFactory)

View File

@@ -16,14 +16,10 @@ from django.test.utils import override_settings
from xmodule.modulestore.tests.factories import CourseFactory
from student.tests.factories import UserFactory, CourseModeFactory
from student.models import CourseEnrollment
from xmodule.modulestore.tests.django_utils import (
ModuleStoreTestCase, mixed_store_config
)
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from openedx.core.djangoapps.user_api.models import UserOrgTag
MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False)
THIRD_PARTY_AUTH_CONFIGURED = (
settings.FEATURES.get('ENABLE_THIRD_PARTY_AUTH') and
getattr(settings, 'THIRD_PARTY_AUTH', {})
@@ -31,7 +27,6 @@ THIRD_PARTY_AUTH_CONFIGURED = (
@unittest.skipUnless(THIRD_PARTY_AUTH_CONFIGURED, "Third party auth must be configured")
@override_settings(MODULESTORE=MODULESTORE_CONFIG)
@ddt.ddt
class PipelineEnrollmentTest(ModuleStoreTestCase):
"""Test that the pipeline auto-enrolls students upon successful authentication. """

View File

@@ -18,6 +18,7 @@ class KeywordSubTest(ModuleStoreTestCase):
""" Tests for the keyword substitution feature """
def setUp(self):
super(KeywordSubTest, self).setUp(create_user=False)
self.user = UserFactory.create(
email="testuser@edx.org",
username="testuser",

View File

@@ -13,6 +13,7 @@ class CorrectMapTest(unittest.TestCase):
"""
def setUp(self):
super(CorrectMapTest, self).setUp()
self.cmap = CorrectMap()
def test_set_input_properties(self):

View File

@@ -34,6 +34,7 @@ class TemplateTestCase(unittest.TestCase):
"""
Load the template under test.
"""
super(TemplateTestCase, self).setUp()
capa_path = capa.__path__[0]
self.template_path = os.path.join(capa_path,
'templates',

View File

@@ -393,6 +393,7 @@ class MatlabTest(unittest.TestCase):
Test Matlab input types
'''
def setUp(self):
super(MatlabTest, self).setUp()
self.rows = '10'
self.cols = '80'
self.tabsize = '4'
@@ -1003,6 +1004,7 @@ class ChemicalEquationTest(unittest.TestCase):
Check that chemical equation inputs work.
'''
def setUp(self):
super(ChemicalEquationTest, self).setUp()
self.size = "42"
xml_str = """<chemicalequationinput id="prob_1_2" size="{size}"/>""".format(size=self.size)
@@ -1089,6 +1091,7 @@ class FormulaEquationTest(unittest.TestCase):
Check that formula equation inputs work.
"""
def setUp(self):
super(FormulaEquationTest, self).setUp()
self.size = "42"
xml_str = """<formulaequationinput id="prob_1_2" size="{size}"/>""".format(size=self.size)

View File

@@ -37,6 +37,7 @@ class ResponseTest(unittest.TestCase):
maxDiff = None
def setUp(self):
super(ResponseTest, self).setUp()
if self.xml_factory_class:
self.xml_factory = self.xml_factory_class()

View File

@@ -19,6 +19,7 @@ class FormulaTest(unittest.TestCase):
mathml_end = '</mstyle></math>'
def setUp(self):
super(FormulaTest, self).setUp()
self.formulaInstance = formula.formula('')
def test_replace_mathvariants(self):

View File

@@ -12,6 +12,7 @@ from mock import patch
from django.conf import settings
from django.contrib.auth.models import User
from django.test import TestCase
from django.test.utils import override_settings
from request_cache.middleware import RequestCache
from xmodule.contentstore.django import _CONTENTSTORE
@@ -19,6 +20,7 @@ from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore, clear_existing_modulestores
from xmodule.modulestore.tests.mongo_connection import MONGO_PORT_NUM, MONGO_HOST
from xmodule.modulestore.tests.sample_courses import default_block_info_tree, TOY_BLOCK_INFO_TREE
from xmodule.modulestore.tests.factories import XMODULE_FACTORY_LOCK
from xmodule.tabs import CoursewareTab, CourseInfoTab, StaticTab, DiscussionTab, ProgressTab, WikiTab
@@ -189,15 +191,14 @@ class ModuleStoreTestCase(TestCase):
Usage:
1. Create a subclass of `ModuleStoreTestCase`
2. Use Django's @override_settings decorator to use
the desired modulestore configuration.
2. (optional) If you need a specific variety of modulestore, or particular ModuleStore
options, set the MODULESTORE class attribute of your test class to the
appropriate modulestore config.
For example:
MIXED_CONFIG = mixed_store_config(data_dir, mappings)
@override_settings(MODULESTORE=MIXED_CONFIG)
class FooTest(ModuleStoreTestCase):
MODULESTORE = mixed_store_config(data_dir, mappings)
# ...
3. Use factories (e.g. `CourseFactory`, `ItemFactory`) to populate
@@ -219,6 +220,9 @@ class ModuleStoreTestCase(TestCase):
`clear_existing_modulestores()` directly in
your `setUp()` method.
"""
MODULESTORE = TEST_DATA_MOCK_MODULESTORE
def setUp(self, **kwargs):
"""
Creates a test User if `create_user` is True.
@@ -227,6 +231,22 @@ class ModuleStoreTestCase(TestCase):
Args:
create_user - specifies whether or not to create a test User. Default is True.
"""
settings_override = override_settings(MODULESTORE=self.MODULESTORE)
settings_override.__enter__()
self.addCleanup(settings_override.__exit__, None, None, None)
# Clear out any existing modulestores,
# which will cause them to be re-created
clear_existing_modulestores()
self.addCleanup(self.drop_mongo_collections)
self.addCleanup(RequestCache().clear_request_cache)
# Enable XModuleFactories for the space of this test (and its setUp).
self.addCleanup(XMODULE_FACTORY_LOCK.disable)
XMODULE_FACTORY_LOCK.enable()
super(ModuleStoreTestCase, self).setUp()
self.store = modulestore()
@@ -293,43 +313,6 @@ class ModuleStoreTestCase(TestCase):
if hasattr(module_store, 'close_connections'):
module_store.close_connections()
@classmethod
def setUpClass(cls):
"""
Delete the existing modulestores, causing them to be reloaded.
"""
# Clear out any existing modulestores,
# which will cause them to be re-created
# the next time they are accessed.
clear_existing_modulestores()
TestCase.setUpClass()
def _pre_setup(self):
"""
Flush the ModuleStore.
"""
# Flush the Mongo modulestore
self.drop_mongo_collections()
# Call superclass implementation
super(ModuleStoreTestCase, self)._pre_setup()
def _post_teardown(self):
"""
Flush the ModuleStore after each test.
"""
self.drop_mongo_collections()
# Clear out the existing modulestores,
# which will cause them to be re-created
# the next time they are accessed.
# We do this at *both* setup and teardown just to be safe.
clear_existing_modulestores()
# clear RequestCache to emulate its clearance after each http request.
RequestCache().clear_request_cache()
# Call superclass implementation
super(ModuleStoreTestCase, self)._post_teardown()
def create_sample_course(self, org, course, run, block_info_tree=None, course_fields=None):
"""
create a course in the default modulestore from the collection of BlockInfo

View File

@@ -22,6 +22,44 @@ class Dummy(object):
pass
class XModuleFactoryLock(threading.local):
"""
This class exists to store whether XModuleFactory can be accessed in a safe
way (meaning, in a context where the data it creates will be cleaned up).
Users of XModuleFactory (or its subclasses) should only call XModuleFactoryLock.enable
after ensuring that a) the modulestore will be cleaned up, and b) that XModuleFactoryLock.disable
will be called.
"""
def __init__(self):
super(XModuleFactoryLock, self).__init__()
self._enabled = False
def enable(self):
"""
Enable XModuleFactories. This should only be turned in a context
where the modulestore will be reset at the end of the test (such
as inside ModuleStoreTestCase).
"""
self._enabled = True
def disable(self):
"""
Disable XModuleFactories. This should be called once the data
from the factory has been cleaned up.
"""
self._enabled = False
def is_enabled(self):
"""
Return whether XModuleFactories are enabled.
"""
return self._enabled
XMODULE_FACTORY_LOCK = XModuleFactoryLock()
class XModuleFactory(Factory):
"""
Factory for XModules
@@ -34,6 +72,9 @@ class XModuleFactory(Factory):
@lazy_attribute
def modulestore(self):
msg = "XMODULE_FACTORY_LOCK not enabled. Please use ModuleStoreTestCase as your test baseclass."
assert XMODULE_FACTORY_LOCK.is_enabled(), msg
from xmodule.modulestore.django import modulestore
return modulestore()

View File

@@ -62,6 +62,7 @@ class TestSortedAssetList(unittest.TestCase):
Tests the SortedAssetList class.
"""
def setUp(self):
super(TestSortedAssetList, self).setUp()
asset_list = [dict(zip(AssetStoreTestData.asset_fields, asset)) for asset in AssetStoreTestData.all_asset_data]
self.sorted_asset_list_by_filename = SortedAssetList(iterable=asset_list)
self.sorted_asset_list_by_last_edit = SortedAssetList(iterable=asset_list, key=lambda x: x['edited_on'])

View File

@@ -153,13 +153,9 @@ class TestMongoModuleStoreBase(unittest.TestCase):
# Destroy the test db.
connection.drop_database(DB)
@classmethod
def setUp(cls):
cls.dummy_user = ModuleStoreEnum.UserID.test
@classmethod
def tearDown(cls):
pass
def setUp(self):
super(TestMongoModuleStoreBase, self).setUp()
self.dummy_user = ModuleStoreEnum.UserID.test
class TestMongoModuleStore(TestMongoModuleStoreBase):
@@ -742,12 +738,13 @@ class TestMongoModuleStoreWithNoAssetCollection(TestMongoModuleStore):
self.assertRaises(ItemNotFoundError, lambda: self.draft_store.get_all_asset_metadata(course_key, 'asset')[:1])
class TestMongoKeyValueStore(object):
class TestMongoKeyValueStore(unittest.TestCase):
"""
Tests for MongoKeyValueStore.
"""
def setUp(self):
super(TestMongoKeyValueStore, self).setUp()
self.data = {'foo': 'foo_value'}
self.course_id = SlashSeparatedCourseKey('org', 'course', 'run')
self.parent = self.course_id.make_usage_key('parent', 'p')

View File

@@ -519,6 +519,7 @@ class SplitModuleTest(unittest.TestCase):
split_store.copy("test@edx.org", source_course, destination, [to_publish], None)
def setUp(self):
super(SplitModuleTest, self).setUp()
self.user_id = random.getrandbits(32)
def tearDown(self):
@@ -1707,7 +1708,7 @@ class TestPublish(SplitModuleTest):
Test the publishing api
"""
def setUp(self):
SplitModuleTest.setUp(self)
super(TestPublish, self).setUp()
def tearDown(self):
SplitModuleTest.tearDown(self)

View File

@@ -114,6 +114,7 @@ class PartitionTestCase(TestCase):
TEST_SCHEME_NAME = "mock"
def setUp(self):
super(PartitionTestCase, self).setUp()
# Set up two user partition schemes: mock and random
self.non_random_scheme = MockUserPartitionScheme(self.TEST_SCHEME_NAME)
self.random_scheme = MockUserPartitionScheme("random")

View File

@@ -172,9 +172,6 @@ def mock_render_template(*args, **kwargs):
class ModelsTest(unittest.TestCase):
def setUp(self):
pass
def test_load_class(self):
vc = XModuleDescriptor.load_class('video')
vc_str = "<class 'xmodule.video_module.video_module.VideoDescriptor'>"
@@ -187,6 +184,7 @@ class LogicTest(unittest.TestCase):
raw_field_data = {}
def setUp(self):
super(LogicTest, self).setUp()
self.system = get_test_system()
self.descriptor = Mock(name="descriptor", url_name='', category='test')

View File

@@ -32,6 +32,7 @@ class AnnotatableModuleTestCase(unittest.TestCase):
'''
def setUp(self):
super(AnnotatableModuleTestCase, self).setUp()
self.annotatable = AnnotatableModule(
Mock(),
get_test_system(),

View File

@@ -187,6 +187,8 @@ if submission[0] == '':
class CapaModuleTest(unittest.TestCase):
def setUp(self):
super(CapaModuleTest, self).setUp()
now = datetime.datetime.now(UTC)
day_delta = datetime.timedelta(days=1)
self.yesterday_str = str(now - day_delta)
@@ -1736,6 +1738,7 @@ class TestProblemCheckTracking(unittest.TestCase):
"""
def setUp(self):
super(TestProblemCheckTracking, self).setUp()
self.maxDiff = None
def test_choice_answer_text(self):

View File

@@ -85,6 +85,7 @@ class OpenEndedChildTest(unittest.TestCase):
descriptor = Mock()
def setUp(self):
super(OpenEndedChildTest, self).setUp()
self.test_system = get_test_system()
self.test_system.open_ended_grading_interface = None
self.openendedchild = OpenEndedChild(self.test_system, self.location,
@@ -249,6 +250,7 @@ class OpenEndedModuleTest(unittest.TestCase):
}
def setUp(self):
super(OpenEndedModuleTest, self).setUp()
self.test_system = get_test_system()
self.test_system.open_ended_grading_interface = None
self.test_system.location = self.location
@@ -529,6 +531,7 @@ class CombinedOpenEndedModuleTest(unittest.TestCase):
)
def setUp(self):
super(CombinedOpenEndedModuleTest, self).setUp()
self.combinedoe = CombinedOpenEndedV1Module(self.test_system,
self.location,
self.definition,
@@ -885,6 +888,7 @@ class CombinedOpenEndedModuleConsistencyTest(unittest.TestCase):
)
def setUp(self):
super(CombinedOpenEndedModuleConsistencyTest, self).setUp()
self.combinedoe = CombinedOpenEndedV1Module(self.test_system,
self.location,
self.definition,
@@ -987,6 +991,7 @@ class OpenEndedModuleXmlTest(unittest.TestCase, DummyModulestore):
return test_system
def setUp(self):
super(OpenEndedModuleXmlTest, self).setUp()
self.setup_modulestore(COURSE)
def _handle_ajax(self, dispatch, content):
@@ -1229,6 +1234,7 @@ class OpenEndedModuleXmlAttemptTest(unittest.TestCase, DummyModulestore):
return test_system
def setUp(self):
super(OpenEndedModuleXmlAttemptTest, self).setUp()
self.setup_modulestore(COURSE)
def _handle_ajax(self, dispatch, content):
@@ -1304,6 +1310,7 @@ class OpenEndedModuleXmlImageUploadTest(unittest.TestCase, DummyModulestore):
return test_system
def setUp(self):
super(OpenEndedModuleXmlImageUploadTest, self).setUp()
self.setup_modulestore(COURSE)
def test_file_upload_fail(self):

View File

@@ -116,6 +116,7 @@ class ConditionalModuleBasicTest(unittest.TestCase):
"""
def setUp(self):
super(ConditionalModuleBasicTest, self).setUp()
self.test_system = get_test_system()
def test_icon_class(self):
@@ -178,6 +179,7 @@ class ConditionalModuleXmlTest(unittest.TestCase):
return DummySystem(load_error_modules)
def setUp(self):
super(ConditionalModuleXmlTest, self).setUp()
self.test_system = get_test_system()
def get_course(self, name):

View File

@@ -91,6 +91,8 @@ class HasEndedMayCertifyTestCase(unittest.TestCase):
"""Double check the semantics around when to finalize courses."""
def setUp(self):
super(HasEndedMayCertifyTestCase, self).setUp()
system = DummySystem(load_error_modules=True)
#sample_xml = """
# <course org="{org}" course="{course}" display_organization="{org}_display" display_coursenumber="{course}_display"
@@ -139,6 +141,8 @@ class IsNewCourseTestCase(unittest.TestCase):
"""Make sure the property is_new works on courses"""
def setUp(self):
super(IsNewCourseTestCase, self).setUp()
# Needed for test_is_newish
datetime_patcher = patch.object(
xmodule.course_module, 'datetime',

View File

@@ -14,8 +14,10 @@ from xblock.fields import ScopeIds
from xblock.test.tools import unabc
class SetupTestErrorModules():
class SetupTestErrorModules(unittest.TestCase):
"""Common setUp for use in ErrorModule tests."""
def setUp(self):
super(SetupTestErrorModules, self).setUp()
self.system = get_test_system()
self.course_id = SlashSeparatedCourseKey('org', 'course', 'run')
self.location = self.course_id.make_usage_key('foo', 'bar')
@@ -23,13 +25,10 @@ class SetupTestErrorModules():
self.error_msg = "Error"
class TestErrorModule(unittest.TestCase, SetupTestErrorModules):
class TestErrorModule(SetupTestErrorModules):
"""
Tests for ErrorModule and ErrorDescriptor
"""
def setUp(self):
SetupTestErrorModules.setUp(self)
def test_error_module_xml_rendering(self):
descriptor = ErrorDescriptor.from_xml(
self.valid_xml,
@@ -58,13 +57,10 @@ class TestErrorModule(unittest.TestCase, SetupTestErrorModules):
self.assertIn(repr(descriptor), context_repr)
class TestNonStaffErrorModule(unittest.TestCase, SetupTestErrorModules):
class TestNonStaffErrorModule(SetupTestErrorModules):
"""
Tests for NonStaffErrorModule and NonStaffErrorDescriptor
"""
def setUp(self):
SetupTestErrorModules.setUp(self)
def test_non_staff_error_module_create(self):
descriptor = NonStaffErrorDescriptor.from_xml(
self.valid_xml,
@@ -125,6 +121,7 @@ class TestErrorModuleConstruction(unittest.TestCase):
"""
def setUp(self):
super(TestErrorModuleConstruction, self).setUp()
field_data = Mock(spec=FieldData)
self.descriptor = BrokenDescriptor(
TestRuntime(Mock(spec=IdReader), field_data),

View File

@@ -70,6 +70,7 @@ class RoundTripTestCase(unittest.TestCase):
"""
def setUp(self):
super(RoundTripTestCase, self).setUp()
self.maxDiff = None
self.temp_dir = mkdtemp()
self.addCleanup(shutil.rmtree, self.temp_dir)
@@ -158,6 +159,8 @@ class TestEdxJsonEncoder(unittest.TestCase):
Tests for xml_exporter.EdxJSONEncoder
"""
def setUp(self):
super(TestEdxJsonEncoder, self).setUp()
self.encoder = EdxJSONEncoder()
class OffsetTZ(tzinfo):
@@ -220,6 +223,7 @@ class ConvertExportFormat(unittest.TestCase):
"""
def setUp(self):
""" Common setup. """
super(ConvertExportFormat, self).setUp()
# Directory for expanding all the test archives
self.temp_dir = mkdtemp()

View File

@@ -46,6 +46,8 @@ class ImageAnnotationModuleTestCase(unittest.TestCase):
"""
Makes sure that the Module is declared and mocked with the sample xml above.
"""
super(ImageAnnotationModuleTestCase, self).setUp()
# return anything except None to test LMS
def test_real_user(useless):
useless_user = Mock(email='fake@fake.com', id=useless)

View File

@@ -48,6 +48,7 @@ class PeerGradingModuleTest(unittest.TestCase, DummyModulestore):
Create a peer grading module from a test system
@return:
"""
super(PeerGradingModuleTest, self).setUp()
self.setup_modulestore(self.course_id.course)
self.peer_grading = self.get_module_from_location(self.problem_location)
self.coe = self.get_module_from_location(self.coe_location)
@@ -264,6 +265,7 @@ class PeerGradingModuleScoredTest(unittest.TestCase, DummyModulestore):
Create a peer grading module from a test system
@return:
"""
super(PeerGradingModuleScoredTest, self).setUp()
self.setup_modulestore(self.course_id.course)
def test_metadata_load(self):
@@ -305,6 +307,7 @@ class PeerGradingModuleLinkedTest(unittest.TestCase, DummyModulestore):
"""
Create a peer grading module from a test system.
"""
super(PeerGradingModuleLinkedTest, self).setUp()
self.setup_modulestore(self.course_id.course)
@property

View File

@@ -35,6 +35,8 @@ class SelfAssessmentTest(unittest.TestCase):
descriptor = Mock()
def setUp(self):
super(SelfAssessmentTest, self).setUp()
self.static_data = {
'max_attempts': 10,
'rubric': etree.XML(self.rubric),

View File

@@ -8,6 +8,7 @@ from opaque_keys.edx.locations import SlashSeparatedCourseKey
class TabTestCase(unittest.TestCase):
"""Base class for Tab-related test cases."""
def setUp(self):
super(TabTestCase, self).setUp()
self.course = MagicMock()
self.course.id = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')
@@ -450,6 +451,7 @@ class KeyCheckerTestCase(unittest.TestCase):
"""Test cases for KeyChecker class"""
def setUp(self):
super(KeyCheckerTestCase, self).setUp()
self.valid_keys = ['a', 'b']
self.invalid_keys = ['a', 'v', 'g']
@@ -467,6 +469,7 @@ class NeedNameTestCase(unittest.TestCase):
"""Test cases for NeedName validator"""
def setUp(self):
super(NeedNameTestCase, self).setUp()
self.valid_dict1 = {'a': 1, 'name': 2}
self.valid_dict2 = {'name': 1}

View File

@@ -31,6 +31,8 @@ class TextAnnotationModuleTestCase(unittest.TestCase):
"""
Makes sure that the Module is declared and mocked with the sample xml above.
"""
super(TextAnnotationModuleTestCase, self).setUp()
# return anything except None to test LMS
def test_real_user(useless):
useless_user = Mock(email='fake@fake.com', id=useless)

View File

@@ -14,6 +14,7 @@ class BaseVerticalModuleTest(XModuleXmlImportTest):
test_html_2 = 'Test HTML 2'
def setUp(self):
super(BaseVerticalModuleTest, self).setUp()
# construct module
course = xml.CourseFactory.build()
sequence = xml.SequenceFactory.build(parent=course)

View File

@@ -185,6 +185,7 @@ class VideoDescriptorTestBase(unittest.TestCase):
"""
def setUp(self):
super(VideoDescriptorTestBase, self).setUp()
self.descriptor = instantiate_descriptor()

View File

@@ -27,6 +27,8 @@ class VideoAnnotationModuleTestCase(unittest.TestCase):
"""
Makes sure that the Video Annotation Module is created.
"""
super(VideoAnnotationModuleTestCase, self).setUp()
# return anything except None to test LMS
def test_real_user(useless):
useless_user = Mock(email='fake@fake.com', id=useless)

View File

@@ -362,6 +362,7 @@ class TestXModuleHandler(TestCase):
"""
def setUp(self):
super(TestXModuleHandler, self).setUp()
self.module = XModule(descriptor=Mock(), field_data=Mock(), runtime=Mock(), scope_ids=Mock())
self.module.handle_ajax = Mock(return_value='{}')
self.request = webob.Request({})

View File

@@ -64,6 +64,7 @@ class InheritingFieldDataTest(unittest.TestCase):
not_inherited = String(scope=Scope.settings, default="nothing")
def setUp(self):
super(InheritingFieldDataTest, self).setUp()
self.system = get_test_descriptor_system()
self.all_blocks = {}
self.system.get_block = self.all_blocks.get

View File

@@ -41,7 +41,6 @@ def mock_render_to_response(*args, **kwargs):
RENDER_MOCK = Mock(side_effect=mock_render_to_response)
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class AnonymousIndexPageTest(ModuleStoreTestCase):
"""
Tests that anonymous users can access the '/' page, Need courses with start date
@@ -115,7 +114,6 @@ class AnonymousIndexPageTest(ModuleStoreTestCase):
self.assertEqual(response._headers.get("location")[1], "/login") # pylint: disable=protected-access
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class PreRequisiteCourseCatalog(ModuleStoreTestCase, LoginEnrollmentTestCase):
"""
Test to simulate and verify fix for disappearing courses in
@@ -123,6 +121,8 @@ class PreRequisiteCourseCatalog(ModuleStoreTestCase, LoginEnrollmentTestCase):
"""
@patch.dict(settings.FEATURES, {'ENABLE_PREREQUISITE_COURSES': True, 'MILESTONES_APP': True})
def setUp(self):
super(PreRequisiteCourseCatalog, self).setUp()
seed_milestone_relationship_types()
@patch.dict(settings.FEATURES, {'ENABLE_PREREQUISITE_COURSES': True, 'MILESTONES_APP': True})
@@ -161,7 +161,6 @@ class PreRequisiteCourseCatalog(ModuleStoreTestCase, LoginEnrollmentTestCase):
self.assertIn('course that has pre requisite', resp.content)
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class IndexPageCourseCardsSortingTests(ModuleStoreTestCase):
"""
Test for Index page course cards sorting

View File

@@ -19,7 +19,6 @@ from xmodule.modulestore.tests.factories import CourseFactory
@patch('bulk_email.models.html_to_text', Mock(return_value='Mocking CourseEmail.text_message'))
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestOptoutCourseEmails(ModuleStoreTestCase):
"""
@@ -27,6 +26,7 @@ class TestOptoutCourseEmails(ModuleStoreTestCase):
"""
def setUp(self):
super(TestOptoutCourseEmails, self).setUp()
course_title = u"ẗëṡẗ title イ乇丂イ ᄊ乇丂丂ムg乇 キo尺 ムレレ тэѕт мэѕѕаБэ"
self.course = CourseFactory.create(display_name=course_title)
self.instructor = AdminFactory.create()

View File

@@ -51,6 +51,7 @@ class EmailSendFromDashboardTestCase(ModuleStoreTestCase):
@patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False})
def setUp(self):
super(EmailSendFromDashboardTestCase, self).setUp()
course_title = u"ẗëṡẗ title イ乇丂イ ᄊ乇丂丂ムg乇 キo尺 ムレレ тэѕт мэѕѕаБэ"
self.course = CourseFactory.create(display_name=course_title)
@@ -91,7 +92,6 @@ class EmailSendFromDashboardTestCase(ModuleStoreTestCase):
patch.stopall()
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False})
@patch('bulk_email.models.html_to_text', Mock(return_value='Mocking CourseEmail.text_message'))
class TestEmailSendFromDashboardMockedHtmlToText(EmailSendFromDashboardTestCase):
@@ -299,7 +299,6 @@ class TestEmailSendFromDashboardMockedHtmlToText(EmailSendFromDashboardTestCase)
self.assertItemsEqual(outbox_contents, should_send_contents)
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False})
@skipIf(os.environ.get("TRAVIS") == 'true', "Skip this test in Travis CI.")
class TestEmailSendFromDashboard(EmailSendFromDashboardTestCase):

View File

@@ -38,7 +38,6 @@ class EmailTestException(Exception):
@patch('bulk_email.models.html_to_text', Mock(return_value='Mocking CourseEmail.text_message'))
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False})
class TestEmailErrors(ModuleStoreTestCase):
"""
@@ -46,6 +45,7 @@ class TestEmailErrors(ModuleStoreTestCase):
"""
def setUp(self):
super(TestEmailErrors, self).setUp()
course_title = u"ẗëṡẗ title イ乇丂イ ᄊ乇丂丂ムg乇 キo尺 ムレレ тэѕт мэѕѕаБэ"
self.course = CourseFactory.create(display_name=course_title)
self.instructor = AdminFactory.create()

View File

@@ -18,11 +18,11 @@ from xmodule.modulestore.django import modulestore
from xmodule.modulestore import ModuleStoreEnum
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class CourseAuthorizationFormTest(ModuleStoreTestCase):
"""Test the CourseAuthorizationAdminForm form for Mongo-backed courses."""
def setUp(self):
super(CourseAuthorizationFormTest, self).setUp()
course_title = u"ẗëṡẗ title イ乇丂イ ᄊ乇丂丂ムg乇 キo尺 ムレレ тэѕт мэѕѕаБэ"
self.course = CourseFactory.create(display_name=course_title)
@@ -122,9 +122,9 @@ class CourseAuthorizationFormTest(ModuleStoreTestCase):
form.save()
@override_settings(MODULESTORE=TEST_DATA_MIXED_TOY_MODULESTORE)
class CourseAuthorizationXMLFormTest(ModuleStoreTestCase):
"""Check that XML courses cannot be authorized for email."""
MODULESTORE = TEST_DATA_MIXED_TOY_MODULESTORE
@patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': True})
def test_xml_course_authorization(self):
@@ -145,7 +145,6 @@ class CourseAuthorizationXMLFormTest(ModuleStoreTestCase):
form.save()
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class CourseEmailTemplateFormTest(ModuleStoreTestCase):
"""Test the CourseEmailTemplateForm that is used in the Django admin subsystem."""

View File

@@ -69,6 +69,8 @@ class CourseEmailTemplateTest(TestCase):
"""Test the CourseEmailTemplate model."""
def setUp(self):
super(CourseEmailTemplateTest, self).setUp()
# load initial content (since we don't run migrations as part of tests):
call_command("loaddata", "course_email_template.json")

View File

@@ -27,13 +27,13 @@ from class_dashboard.views import has_instructor_access_for_class
USER_COUNT = 11
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestGetProblemGradeDistribution(ModuleStoreTestCase):
"""
Tests related to class_dashboard/dashboard_data.py
"""
def setUp(self):
super(TestGetProblemGradeDistribution, self).setUp()
self.request_factory = RequestFactory()
self.instructor = AdminFactory.create()

View File

@@ -14,13 +14,13 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from class_dashboard import views
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestViews(ModuleStoreTestCase):
"""
Tests related to class_dashboard/views.py
"""
def setUp(self):
super(TestViews, self).setUp()
self.request_factory = RequestFactory()
self.request = self.request_factory.get('')

View File

@@ -17,10 +17,10 @@ from course_wiki.utils import user_is_article_course_staff, course_wiki_slug
from course_wiki import settings
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestWikiAccessBase(ModuleStoreTestCase):
"""Base class for testing wiki access."""
def setUp(self):
super(TestWikiAccessBase, self).setUp()
self.wiki = get_or_create_root()

View File

@@ -14,12 +14,13 @@ from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from course_wiki.views import get_or_create_root
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestWikiAccessMiddleware(ModuleStoreTestCase):
"""Tests for WikiAccessMiddleware."""
def setUp(self):
"""Test setup."""
super(TestWikiAccessMiddleware, self).setUp()
self.wiki = get_or_create_root()
self.course_math101 = CourseFactory.create(org='edx', number='math101', display_name='2014', metadata={'use_unique_wiki_id': 'false'})

View File

@@ -2,23 +2,20 @@ from django.core.urlresolvers import reverse
from django.test.utils import override_settings
from courseware.tests.tests import LoginEnrollmentTestCase
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from mock import patch
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class WikiRedirectTestCase(LoginEnrollmentTestCase):
class WikiRedirectTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
"""
Tests for wiki course redirection.
"""
@classmethod
def setUpClass(cls):
cls.toy = CourseFactory.create(org='edX', course='toy', display_name='2012_Fall')
def setUp(self):
super(WikiRedirectTestCase, self).setUp()
self.toy = CourseFactory.create(org='edX', course='toy', display_name='2012_Fall')
# Create two accounts
self.student = 'view@test.com'

View File

@@ -46,6 +46,7 @@ class CommandsTestBase(TestCase):
"""
def setUp(self):
super(CommandsTestBase, self).setUp()
self.loaded_courses = self.load_courses()
def load_courses(self):
@@ -199,17 +200,17 @@ class CommandsTestBase(TestCase):
assert_in('edX-simple-2012_Fall/sequential/Lecture_2.xml', names)
@override_settings(MODULESTORE=TEST_DATA_MIXED_XML_MODULESTORE)
class CommandsXMLTestCase(CommandsTestBase, ModuleStoreTestCase):
"""
Test case for management commands using the xml modulestore.
"""
MODULESTORE = TEST_DATA_MIXED_XML_MODULESTORE
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
class CommandsMongoTestCase(CommandsTestBase, ModuleStoreTestCase):
"""
Test case for management commands using the mixed mongo modulestore.
"""
MODULESTORE = TEST_DATA_MONGO_MODULESTORE

View File

@@ -24,7 +24,6 @@ from lms.djangoapps.lms_xblock.field_data import LmsFieldData
from lms.djangoapps.lms_xblock.runtime import quote_slashes
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
class BaseTestXmodule(ModuleStoreTestCase):
"""Base class for testing Xmodules with mongo store.
@@ -41,6 +40,8 @@ class BaseTestXmodule(ModuleStoreTestCase):
This class should not contain any tests, because CATEGORY
should be defined in child class.
"""
MODULESTORE = TEST_DATA_MONGO_MODULESTORE
USER_COUNT = 2
COURSE_DATA = {}

View File

@@ -33,12 +33,12 @@ REG_STR = "<form id=\"class_enroll_form\" method=\"post\" data-remote=\"true\" a
SHIB_ERROR_STR = "The currently logged-in user account does not have permission to enroll in this course."
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class AboutTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
"""
Tests about xblock.
"""
def setUp(self):
super(AboutTestCase, self).setUp()
self.course = CourseFactory.create()
self.about = ItemFactory.create(
category="about", parent_location=self.course.location,
@@ -181,11 +181,12 @@ class AboutTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
self.assertEqual(resp.status_code, 200)
@override_settings(MODULESTORE=TEST_DATA_MIXED_CLOSED_MODULESTORE)
class AboutTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase):
"""
Tests for the course about page
"""
MODULESTORE = TEST_DATA_MIXED_CLOSED_MODULESTORE
# The following XML test course (which lives at common/test/data/2014)
# is closed; we're testing that an about page still appears when
# the course is already closed
@@ -211,7 +212,6 @@ class AboutTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase):
self.assertIn(self.xml_data, resp.content)
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class AboutWithCappedEnrollmentsTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
"""
This test case will check the About page when a course has a capped enrollment
@@ -220,6 +220,7 @@ class AboutWithCappedEnrollmentsTestCase(LoginEnrollmentTestCase, ModuleStoreTes
"""
Set up the tests
"""
super(AboutWithCappedEnrollmentsTestCase, self).setUp()
self.course = CourseFactory.create(metadata={"max_student_enrollments_allowed": 1})
self.about = ItemFactory.create(
@@ -261,12 +262,12 @@ class AboutWithCappedEnrollmentsTestCase(LoginEnrollmentTestCase, ModuleStoreTes
self.assertNotIn(REG_STR, resp.content)
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class AboutWithInvitationOnly(ModuleStoreTestCase):
"""
This test case will check the About page when a course is invitation only.
"""
def setUp(self):
super(AboutWithInvitationOnly, self).setUp()
self.course = CourseFactory.create(metadata={"invitation_only": True})
@@ -308,12 +309,12 @@ class AboutWithInvitationOnly(ModuleStoreTestCase):
@patch.dict(settings.FEATURES, {'RESTRICT_ENROLL_BY_REG_METHOD': True})
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class AboutTestCaseShibCourse(LoginEnrollmentTestCase, ModuleStoreTestCase):
"""
Test cases covering about page behavior for courses that use shib enrollment domain ("shib courses")
"""
def setUp(self):
super(AboutTestCaseShibCourse, self).setUp()
self.course = CourseFactory.create(enrollment_domain="shib:https://idp.stanford.edu/")
self.about = ItemFactory.create(
@@ -347,7 +348,6 @@ class AboutTestCaseShibCourse(LoginEnrollmentTestCase, ModuleStoreTestCase):
self.assertIn(REG_STR, resp.content)
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class AboutWithClosedEnrollment(ModuleStoreTestCase):
"""
This test case will check the About page for a course that has enrollment start/end
@@ -391,7 +391,6 @@ class AboutWithClosedEnrollment(ModuleStoreTestCase):
self.assertNotIn('<span class="important-dates-item-text">$10</span>', resp.content)
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch.dict(settings.FEATURES, {'ENABLE_SHOPPING_CART': True})
@patch.dict(settings.FEATURES, {'ENABLE_PAID_COURSE_REGISTRATION': True})
class AboutPurchaseCourseTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):

View File

@@ -16,6 +16,7 @@ from xmodule.course_module import (
CATALOG_VISIBILITY_NONE
)
from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from util.milestones_helpers import (
set_prerequisite_courses,
@@ -27,11 +28,12 @@ from util.milestones_helpers import (
# pylint: disable=protected-access
class AccessTestCase(LoginEnrollmentTestCase):
class AccessTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
"""
Tests for the various access controls on the student dashboard
"""
def setUp(self):
super(AccessTestCase, self).setUp()
course_key = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')
self.course = course_key.make_usage_key('course', course_key.run)
self.anonymous_user = AnonymousUserFactory()
@@ -329,6 +331,7 @@ class UserRoleTestCase(TestCase):
Tests for user roles.
"""
def setUp(self):
super(UserRoleTestCase, self).setUp()
self.course_key = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')
self.anonymous_user = AnonymousUserFactory()
self.student = UserFactory()

View File

@@ -15,12 +15,12 @@ from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from .helpers import LoginEnrollmentTestCase
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class CourseInfoTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
"""
Tests for the Course Info page
"""
def setUp(self):
super(CourseInfoTestCase, self).setUp()
self.course = CourseFactory.create()
self.page = ItemFactory.create(
category="course_info", parent_location=self.course.location,
@@ -48,11 +48,12 @@ class CourseInfoTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
self.assertNotIn("OOGIE BLOOGIE", resp.content)
@override_settings(MODULESTORE=TEST_DATA_MIXED_CLOSED_MODULESTORE)
class CourseInfoTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase):
"""
Tests for the Course Info page for an XML course
"""
MODULESTORE = TEST_DATA_MIXED_CLOSED_MODULESTORE
# The following XML test course (which lives at common/test/data/2014)
# is closed; we're testing that a course info page still appears when
# the course is already closed

View File

@@ -9,10 +9,11 @@ from django.core.urlresolvers import reverse
from survey.models import SurveyForm
from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from courseware.tests.helpers import LoginEnrollmentTestCase
class SurveyViewsTests(LoginEnrollmentTestCase):
class SurveyViewsTests(LoginEnrollmentTestCase, ModuleStoreTestCase):
"""
All tests for the views.py file
"""

View File

@@ -148,7 +148,6 @@ class XmlCourseImageTestCase(XModuleXmlImportTest):
self.assertEquals(course_image_url(course), u'/static/xml_test_course/before after.jpg')
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class CoursesRenderTest(ModuleStoreTestCase):
"""Test methods related to rendering courses content."""
@@ -196,9 +195,10 @@ class CoursesRenderTest(ModuleStoreTestCase):
self.assertIn("this module is temporarily unavailable", course_about)
@override_settings(MODULESTORE=TEST_DATA_MIXED_TOY_MODULESTORE)
class XmlCoursesRenderTest(ModuleStoreTestCase):
"""Test methods related to rendering courses content for an XML course."""
MODULESTORE = TEST_DATA_MIXED_TOY_MODULESTORE
toy_course_key = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')
def test_get_course_info_section_render(self):

View File

@@ -7,7 +7,6 @@ from opaque_keys.edx.locations import SlashSeparatedCourseKey
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestDraftModuleStore(TestCase):
"""
Test the draft modulestore

View File

@@ -15,7 +15,6 @@ from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from util.milestones_helpers import generate_milestone_namespace, NAMESPACE_CHOICES
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class EntranceExamTestCases(ModuleStoreTestCase):
"""
Check that content is properly gated. Create a test course from scratch to mess with.

View File

@@ -27,7 +27,6 @@ def _grade_with_errors(student, request, course, keep_raw_scores=False):
return grade(student, request, course, keep_raw_scores=keep_raw_scores)
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestGradeIteration(ModuleStoreTestCase):
"""
Test iteration through student gradesets.
@@ -39,6 +38,8 @@ class TestGradeIteration(ModuleStoreTestCase):
"""
Create a course and a handful of users to assign grades
"""
super(TestGradeIteration, self).setUp()
self.course = CourseFactory.create(
display_name=self.COURSE_NAME,
number=self.COURSE_NUM

View File

@@ -72,6 +72,7 @@ class GroupAccessTestCase(ModuleStoreTestCase):
modulestore().update_item(block, 1)
def setUp(self):
super(GroupAccessTestCase, self).setUp()
UserPartition.scheme_extensions = ExtensionManager.make_test_instance(
[

View File

@@ -9,7 +9,7 @@ from django.test.utils import override_settings
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE, LANGUAGES=(('eo', 'Esperanto'),))
@override_settings(LANGUAGES=(('eo', 'Esperanto'),))
class I18nTestCase(TestCase):
"""
Tests for i18n

View File

@@ -124,7 +124,6 @@ class TestLTI(BaseTestXmodule):
self.assertEqual(generated_content, expected_content)
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestLTIModuleListing(ModuleStoreTestCase):
"""
a test for the rest endpoint that lists LTI modules in a course
@@ -135,6 +134,7 @@ class TestLTIModuleListing(ModuleStoreTestCase):
def setUp(self):
"""Create course, 2 chapters, 2 sections"""
super(TestLTIModuleListing, self).setUp()
self.course = CourseFactory.create(display_name=self.COURSE_NAME, number=self.COURSE_SLUG)
self.chapter1 = ItemFactory.create(
parent_location=self.course.location,

View File

@@ -20,12 +20,13 @@ from xmodule.modulestore.tests.factories import ItemFactory, CourseFactory
from xmodule.partitions.partitions import Group, UserPartition
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class MasqueradeTestCase(ModuleStoreTestCase, LoginEnrollmentTestCase):
"""
Base class for masquerade tests that sets up a test course and enrolls a user in the course.
"""
def setUp(self):
super(MasqueradeTestCase, self).setUp()
# By default, tests run with DISABLE_START_DATES=True. To test that masquerading as a student is
# working properly, we must use start dates and set a start date in the past (otherwise the access
# checks exist prematurely).

View File

@@ -14,7 +14,6 @@ from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestMicrosites(ModuleStoreTestCase, LoginEnrollmentTestCase):
"""
This is testing of the Microsite feature
@@ -23,6 +22,8 @@ class TestMicrosites(ModuleStoreTestCase, LoginEnrollmentTestCase):
STUDENT_INFO = [('view@test.com', 'foo'), ('view2@test.com', 'foo')]
def setUp(self):
super(TestMicrosites, self).setUp()
# use a different hostname to test Microsites since they are
# triggered on subdomain mappings
#

View File

@@ -15,11 +15,12 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class CoursewareMiddlewareTestCase(ModuleStoreTestCase):
"""Tests that courseware middleware is correctly redirected"""
def setUp(self):
super(CoursewareMiddlewareTestCase, self).setUp()
self.course = CourseFactory.create()
def check_user_not_enrolled_redirect(self):

View File

@@ -54,6 +54,7 @@ class StudentModuleFactory(cmfStudentModuleFactory):
class TestInvalidScopes(TestCase):
def setUp(self):
super(TestInvalidScopes, self).setUp()
self.user = UserFactory.create(username='user')
self.field_data_cache = FieldDataCache([mock_descriptor([mock_field(Scope.user_state, 'a_field')])], course_id, self.user)
self.kvs = DjangoKeyValueStore(self.field_data_cache)
@@ -101,6 +102,7 @@ class TestStudentModuleStorage(OtherUserFailureTestMixin, TestCase):
existing_field_name = "a_field"
def setUp(self):
super(TestStudentModuleStorage, self).setUp()
student_module = StudentModuleFactory(state=json.dumps({'a_field': 'a_value', 'b_field': 'b_value'}))
self.user = student_module.student
self.assertEqual(self.user.id, 1) # check our assumption hard-coded in the key functions above.
@@ -179,6 +181,8 @@ class TestStudentModuleStorage(OtherUserFailureTestMixin, TestCase):
class TestMissingStudentModule(TestCase):
def setUp(self):
super(TestMissingStudentModule, self).setUp()
self.user = UserFactory.create(username='user')
self.assertEqual(self.user.id, 1) # check our assumption hard-coded in the key functions above.
self.field_data_cache = FieldDataCache([mock_descriptor()], course_id, self.user)

View File

@@ -14,7 +14,7 @@ from django.test.client import RequestFactory
from django.test.utils import override_settings
from django.contrib.auth.models import AnonymousUser
from mock import MagicMock, patch, Mock
from opaque_keys.edx.keys import UsageKey
from opaque_keys.edx.keys import UsageKey, CourseKey
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from xblock.field_data import FieldData
from xblock.runtime import Runtime
@@ -72,7 +72,6 @@ class EmptyXModuleDescriptor(XModuleDescriptor): # pylint: disable=abstract-met
@ddt.ddt
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class ModuleRenderTestCase(ModuleStoreTestCase, LoginEnrollmentTestCase):
"""
Tests of courseware.module_render
@@ -248,7 +247,6 @@ class ModuleRenderTestCase(ModuleStoreTestCase, LoginEnrollmentTestCase):
render.get_module_for_descriptor(self.mock_user, request, descriptor, field_data_cache, self.toy_course.id)
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestHandleXBlockCallback(ModuleStoreTestCase, LoginEnrollmentTestCase):
"""
Test the handle_xblock_callback function
@@ -403,7 +401,6 @@ class TestHandleXBlockCallback(ModuleStoreTestCase, LoginEnrollmentTestCase):
@ddt.ddt
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestTOC(ModuleStoreTestCase):
"""Check the Table of Contents for a course"""
def setup_modulestore(self, default_ms, num_finds, num_sends):
@@ -499,13 +496,13 @@ class TestTOC(ModuleStoreTestCase):
self.assertIn(toc_section, actual)
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestHtmlModifiers(ModuleStoreTestCase):
"""
Tests to verify that standard modifications to the output of XModule/XBlock
student_view are taking place
"""
def setUp(self):
super(TestHtmlModifiers, self).setUp()
self.user = UserFactory.create()
self.request = RequestFactory().get('/')
self.request.user = self.user
@@ -637,6 +634,7 @@ class ViewInStudioTest(ModuleStoreTestCase):
def setUp(self):
""" Set up the user and request that will be used. """
super(ViewInStudioTest, self).setUp()
self.staff_user = GlobalStaffFactory.create()
self.request = RequestFactory().get('/')
self.request.user = self.staff_user
@@ -693,13 +691,9 @@ class ViewInStudioTest(ModuleStoreTestCase):
self.module = self._get_module(course_key, descriptor, location)
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class MongoViewInStudioTest(ViewInStudioTest):
"""Test the 'View in Studio' link visibility in a mongo backed course."""
def setUp(self):
super(MongoViewInStudioTest, self).setUp()
def test_view_in_studio_link_studio_course(self):
"""Regular Studio courses should see 'View in Studio' links."""
self.setup_mongo_course()
@@ -725,12 +719,10 @@ class MongoViewInStudioTest(ViewInStudioTest):
self.assertNotIn('View Unit in Studio', result_fragment.content)
@override_settings(MODULESTORE=TEST_DATA_MIXED_TOY_MODULESTORE)
class MixedViewInStudioTest(ViewInStudioTest):
"""Test the 'View in Studio' link visibility in a mixed mongo backed course."""
def setUp(self):
super(MixedViewInStudioTest, self).setUp()
MODULESTORE = TEST_DATA_MIXED_TOY_MODULESTORE
def test_view_in_studio_link_mongo_backed(self):
"""Mixed mongo courses that are mongo backed should see 'View in Studio' links."""
@@ -751,12 +743,9 @@ class MixedViewInStudioTest(ViewInStudioTest):
self.assertNotIn('View Unit in Studio', result_fragment.content)
@override_settings(MODULESTORE=TEST_DATA_XML_MODULESTORE)
class XmlViewInStudioTest(ViewInStudioTest):
"""Test the 'View in Studio' link visibility in an xml backed course."""
def setUp(self):
super(XmlViewInStudioTest, self).setUp()
MODULESTORE = TEST_DATA_XML_MODULESTORE
def test_view_in_studio_link_xml_backed(self):
"""Course in XML only modulestore should not see 'View in Studio' links."""
@@ -765,13 +754,13 @@ class XmlViewInStudioTest(ViewInStudioTest):
self.assertNotIn('View Unit in Studio', result_fragment.content)
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch.dict('django.conf.settings.FEATURES', {'DISPLAY_DEBUG_INFO_TO_STAFF': True, 'DISPLAY_HISTOGRAMS_TO_STAFF': True})
@patch('courseware.module_render.has_access', Mock(return_value=True))
class TestStaffDebugInfo(ModuleStoreTestCase):
"""Tests to verify that Staff Debug Info panel and histograms are displayed to staff."""
def setUp(self):
super(TestStaffDebugInfo, self).setUp()
self.user = UserFactory.create()
self.request = RequestFactory().get('/')
self.request.user = self.user
@@ -886,13 +875,13 @@ PER_STUDENT_ANONYMIZED_DESCRIPTORS = set(
@ddt.ddt
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestAnonymousStudentId(ModuleStoreTestCase, LoginEnrollmentTestCase):
"""
Test that anonymous_student_id is set correctly across a variety of XBlock types
"""
def setUp(self):
super(TestAnonymousStudentId, self).setUp(create_user=False)
self.user = UserFactory()
@patch('courseware.module_render.has_access', Mock(return_value=True))
@@ -933,7 +922,7 @@ class TestAnonymousStudentId(ModuleStoreTestCase, LoginEnrollmentTestCase):
# This value is set by observation, so that later changes to the student
# id computation don't break old data
'5afe5d9bb03796557ee2614f5c9611fb',
self._get_anonymous_id(SlashSeparatedCourseKey.from_deprecated_string(course_id), descriptor_class)
self._get_anonymous_id(CourseKey.from_string(course_id), descriptor_class)
)
@ddt.data(*PER_COURSE_ANONYMIZED_DESCRIPTORS)
@@ -953,7 +942,6 @@ class TestAnonymousStudentId(ModuleStoreTestCase, LoginEnrollmentTestCase):
)
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch('track.views.tracker')
class TestModuleTrackingContext(ModuleStoreTestCase):
"""
@@ -961,6 +949,8 @@ class TestModuleTrackingContext(ModuleStoreTestCase):
"""
def setUp(self):
super(TestModuleTrackingContext, self).setUp()
self.user = UserFactory.create()
self.request = RequestFactory().get('/')
self.request.user = self.user
@@ -1145,7 +1135,6 @@ class TestRebindModule(TestSubmittingProblems):
@ddt.ddt
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestEventPublishing(ModuleStoreTestCase, LoginEnrollmentTestCase):
"""
Tests of event publishing for both XModules and XBlocks.

View File

@@ -14,7 +14,6 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestNavigation(ModuleStoreTestCase, LoginEnrollmentTestCase):
"""
Check that navigation state is saved properly.

View File

@@ -20,10 +20,7 @@ from courseware.tests.factories import GlobalStaffFactory
from lms.djangoapps.lms_xblock.runtime import quote_slashes
MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False)
@override_settings(MODULESTORE=MODULESTORE_CONFIG)
class TestRecommender(ModuleStoreTestCase, LoginEnrollmentTestCase):
"""
Check that Recommender state is saved properly
@@ -35,6 +32,8 @@ class TestRecommender(ModuleStoreTestCase, LoginEnrollmentTestCase):
XBLOCK_NAMES = ['recommender', 'recommender_second']
def setUp(self):
super(TestRecommender, self).setUp()
self.course = CourseFactory.create(
display_name='Recommender_Test_Course'
)

View File

@@ -15,7 +15,6 @@ from xmodule.partitions.partitions import Group, UserPartition
from openedx.core.djangoapps.user_api.tests.factories import UserCourseTagFactory
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class SplitTestBase(ModuleStoreTestCase):
"""
Sets up a basic course and user for split test testing.
@@ -29,6 +28,7 @@ class SplitTestBase(ModuleStoreTestCase):
VISIBLE_CONTENT = None
def setUp(self):
super(SplitTestBase, self).setUp()
self.partition = UserPartition(
0,
'first_partition',
@@ -270,12 +270,13 @@ class TestSplitTestVert(SplitTestBase):
html1 = self._html(cond1vert, 1)
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class SplitTestPosition(ModuleStoreTestCase):
"""
Check that we can change positions in a course with partitions defined
"""
def setUp(self):
super(SplitTestPosition, self).setUp()
self.partition = UserPartition(
0,
'first_partition',

View File

@@ -30,7 +30,6 @@ from xmodule.partitions.partitions import Group, UserPartition
from openedx.core.djangoapps.user_api.tests.factories import UserCourseTagFactory
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestSubmittingProblems(ModuleStoreTestCase, LoginEnrollmentTestCase):
"""
Check that a course gets graded properly.
@@ -648,7 +647,6 @@ class ProblemWithUploadedFilesTest(TestSubmittingProblems):
self.assertItemsEqual(kwargs['files'].keys(), filenames.split())
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestPythonGradedResponse(TestSubmittingProblems):
"""
Check that we can submit a schematic and custom response, and it answers properly.

View File

@@ -26,11 +26,13 @@ if settings.FEATURES.get('MILESTONES_APP', False):
from milestones.models import MilestoneRelationshipType
@override_settings(MODULESTORE=TEST_DATA_MIXED_TOY_MODULESTORE)
class StaticTabDateTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
"""Test cases for Static Tab Dates."""
MODULESTORE = TEST_DATA_MIXED_TOY_MODULESTORE
def setUp(self):
super(StaticTabDateTestCase, self).setUp()
self.course = CourseFactory.create()
self.page = ItemFactory.create(
category="static_tab", parent_location=self.course.location,
@@ -75,11 +77,13 @@ class StaticTabDateTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
self.assertIn("this module is temporarily unavailable", static_tab)
@override_settings(MODULESTORE=TEST_DATA_MIXED_CLOSED_MODULESTORE)
class StaticTabDateTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase):
"""
Tests for the static tab dates of an XML course
"""
MODULESTORE = TEST_DATA_MIXED_CLOSED_MODULESTORE
# The following XML test course (which lives at common/test/data/2014)
# is closed; we're testing that tabs still appear when
# the course is already closed
@@ -106,17 +110,20 @@ class StaticTabDateTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase):
self.assertIn(self.xml_data, resp.content)
@override_settings(MODULESTORE=TEST_DATA_MIXED_CLOSED_MODULESTORE)
class EntranceExamsTabsTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
"""
Validate tab behavior when dealing with Entrance Exams
"""
MODULESTORE = TEST_DATA_MIXED_CLOSED_MODULESTORE
if settings.FEATURES.get('ENTRANCE_EXAMS', False):
def setUp(self):
"""
Test case scaffolding
"""
super(EntranceExamsTabsTestCase, self).setUp()
self.course = CourseFactory.create()
self.instructor_tab = ItemFactory.create(
category="instructor", parent_location=self.course.location,

Some files were not shown because too many files have changed in this diff Show More