Commit bf3b87bc by Jesse Zoldak

Clean up all modulestore testcases

Move modulestore config for tests to an importable location
Disable pylnt warning for lms imports in common tests
Refactor all testcases that loaded all xml courses
TE-610
TE-489
parent 8c946f8b
...@@ -2,23 +2,24 @@ ...@@ -2,23 +2,24 @@
''' '''
Utilities for contentstore tests Utilities for contentstore tests
''' '''
import json import json
from django.test.client import Client from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.test.client import Client
from django.test.utils import override_settings
from opaque_keys.edx.locations import SlashSeparatedCourseKey, AssetLocation
from contentstore.utils import reverse_url
from student.models import Registration
from xmodule.modulestore.split_mongo.split import SplitMongoModuleStore
from xmodule.contentstore.django import contentstore from xmodule.contentstore.django import contentstore
from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.inheritance import own_metadata from xmodule.modulestore.inheritance import own_metadata
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.modulestore.xml_importer import import_from_xml from xmodule.modulestore.xml_importer import import_from_xml
from student.models import Registration
from opaque_keys.edx.locations import SlashSeparatedCourseKey, AssetLocation
from contentstore.utils import reverse_url
from xmodule.modulestore.split_mongo.split import SplitMongoModuleStore
from django.conf import settings
TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
...@@ -66,7 +67,12 @@ class AjaxEnabledTestClient(Client): ...@@ -66,7 +67,12 @@ class AjaxEnabledTestClient(Client):
return self.get(path, data or {}, follow, HTTP_ACCEPT="application/json", **extra) return self.get(path, data or {}, follow, HTTP_ACCEPT="application/json", **extra)
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class CourseTestCase(ModuleStoreTestCase): class CourseTestCase(ModuleStoreTestCase):
"""
Base class for Studio tests that require a logged in user and a course.
Also provides helper methods for manipulating and verifying the course.
"""
def setUp(self): def setUp(self):
""" """
These tests need a user in the DB so that the django Test Client can log them in. These tests need a user in the DB so that the django Test Client can log them in.
......
import django.test
from django.contrib.auth.models import User
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User
from django.http import Http404 from django.http import Http404
from django.test import TestCase
from django.test.utils import override_settings from django.test.utils import override_settings
from mock import call, patch from mock import call, patch
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from student.models import CourseEnrollment
from student.tests.factories import UserFactory
from course_groups.models import CourseUserGroup
from course_groups import cohorts from course_groups import cohorts
from course_groups.models import CourseUserGroup
from course_groups.tests.helpers import topic_name_to_id, config_course_cohorts, CohortFactory from course_groups.tests.helpers import topic_name_to_id, config_course_cohorts, CohortFactory
from student.models import CourseEnrollment
from student.tests.factories import UserFactory
from xmodule.modulestore.django import modulestore, clear_existing_modulestores from xmodule.modulestore.django import modulestore, clear_existing_modulestores
from opaque_keys.edx.locations import SlashSeparatedCourseKey from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_TOY_MODULESTORE
from xmodule.modulestore.tests.django_utils import mixed_store_config
# NOTE: running this with the lms.envs.test config works without # NOTE: running this with the lms.envs.test config works without
# manually overriding the modulestore. However, running with # manually overriding the modulestore. However, running with
# cms.envs.test doesn't. # cms.envs.test doesn't.
TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
TEST_MAPPING = {'edX/toy/2012_Fall': 'xml'}
TEST_DATA_MIXED_MODULESTORE = mixed_store_config(TEST_DATA_DIR, TEST_MAPPING)
@patch("course_groups.cohorts.tracker") @patch("course_groups.cohorts.tracker")
class TestCohortSignals(django.test.TestCase): class TestCohortSignals(TestCase):
def setUp(self): def setUp(self):
self.course_key = SlashSeparatedCourseKey("dummy", "dummy", "dummy") self.course_key = SlashSeparatedCourseKey("dummy", "dummy", "dummy")
...@@ -123,9 +115,11 @@ class TestCohortSignals(django.test.TestCase): ...@@ -123,9 +115,11 @@ class TestCohortSignals(django.test.TestCase):
self.assertFalse(mock_tracker.emit.called) self.assertFalse(mock_tracker.emit.called)
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_TOY_MODULESTORE)
class TestCohorts(django.test.TestCase): class TestCohorts(TestCase):
"""
Test the cohorts feature
"""
def setUp(self): def setUp(self):
""" """
Make sure that course is reloaded every time--clear out the modulestore. Make sure that course is reloaded every time--clear out the modulestore.
......
"""
Tests for course group views
"""
from collections import namedtuple
import json import json
from django.contrib.auth.models import User
from django.http import Http404
from django.test.client import RequestFactory from django.test.client import RequestFactory
from django.test.utils import override_settings from django.test.utils import override_settings
from course_groups.tests.helpers import config_course_cohorts, CohortFactory from opaque_keys.edx.locations import SlashSeparatedCourseKey
from collections import namedtuple
from django.http import Http404 from course_groups.cohorts import (
from django.contrib.auth.models import User get_cohort, CohortAssignmentType, get_cohort_by_name, DEFAULT_COHORT_NAME
from courseware.tests.tests import TEST_DATA_MIXED_MODULESTORE )
from course_groups.models import CourseUserGroup
from course_groups.tests.helpers import config_course_cohorts, CohortFactory
from course_groups.views import (
list_cohorts, add_cohort, users_in_cohort, add_users_to_cohort, remove_user_from_cohort
)
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from student.models import CourseEnrollment from student.models import CourseEnrollment
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from course_groups.models import CourseUserGroup
from course_groups.views import list_cohorts, add_cohort, users_in_cohort, add_users_to_cohort, remove_user_from_cohort
from course_groups.cohorts import get_cohort, CohortAssignmentType, get_cohort_by_name, DEFAULT_COHORT_NAME
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class CohortViewsTestCase(ModuleStoreTestCase): class CohortViewsTestCase(ModuleStoreTestCase):
""" """
Base class which sets up a course and staff/non-staff users. Base class which sets up a course and staff/non-staff users.
......
...@@ -13,10 +13,10 @@ from embargo.models import EmbargoedCourse, EmbargoedState, IPFilter ...@@ -13,10 +13,10 @@ from embargo.models import EmbargoedCourse, EmbargoedState, IPFilter
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class EmbargoCourseFormTest(ModuleStoreTestCase): class EmbargoCourseFormTest(ModuleStoreTestCase):
"""Test the course form properly validates course IDs""" """Test the course form properly validates course IDs"""
......
...@@ -4,9 +4,8 @@ Tests for Shibboleth Authentication ...@@ -4,9 +4,8 @@ Tests for Shibboleth Authentication
@jbau @jbau
""" """
import unittest import unittest
from mock import patch
from ddt import ddt, data
from ddt import ddt, data
from django.conf import settings from django.conf import settings
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.test import TestCase from django.test import TestCase
...@@ -15,22 +14,21 @@ from django.test.utils import override_settings ...@@ -15,22 +14,21 @@ from django.test.utils import override_settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.contrib.auth.models import AnonymousUser, User from django.contrib.auth.models import AnonymousUser, User
from django.utils.importlib import import_module from django.utils.importlib import import_module
from edxmako.tests import mako_middleware_process_request
from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, mixed_store_config
from xmodule.modulestore.django import modulestore
from xmodule.modulestore import ModuleStoreEnum
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from external_auth.models import ExternalAuthMap from external_auth.models import ExternalAuthMap
from external_auth.views import shib_login, course_specific_login, course_specific_register, _flatten_to_ascii from external_auth.views import (
shib_login, course_specific_login, course_specific_register, _flatten_to_ascii
)
from mock import patch
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from student.views import create_account, change_enrollment from student.views import create_account, change_enrollment
from student.models import UserProfile, Registration, CourseEnrollment from student.models import UserProfile, CourseEnrollment
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
from edxmako.tests import mako_middleware_process_request from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore import ModuleStoreEnum
TEST_DATA_MIXED_MODULESTORE = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {})
# Shib is supposed to provide 'REMOTE_USER', 'givenName', 'sn', 'mail', 'Shib-Identity-Provider' # Shib is supposed to provide 'REMOTE_USER', 'givenName', 'sn', 'mail', 'Shib-Identity-Provider'
# attributes via request.META. We can count on 'Shib-Identity-Provider', and 'REMOTE_USER' being present # attributes via request.META. We can count on 'Shib-Identity-Provider', and 'REMOTE_USER' being present
...@@ -75,7 +73,7 @@ def gen_all_identities(): ...@@ -75,7 +73,7 @@ def gen_all_identities():
@ddt @ddt
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE, SESSION_ENGINE='django.contrib.sessions.backends.cache') @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE, SESSION_ENGINE='django.contrib.sessions.backends.cache')
class ShibSPTest(ModuleStoreTestCase): class ShibSPTest(ModuleStoreTestCase):
""" """
Tests for the Shibboleth SP, which communicates via request.META Tests for the Shibboleth SP, which communicates via request.META
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
Provides unit tests for SSL based authentication portions Provides unit tests for SSL based authentication portions
of the external_auth app. of the external_auth app.
""" """
import unittest import unittest
from django.conf import settings from django.conf import settings
...@@ -13,17 +12,16 @@ from django.core.urlresolvers import reverse ...@@ -13,17 +12,16 @@ from django.core.urlresolvers import reverse
from django.test.client import Client from django.test.client import Client
from django.test.client import RequestFactory from django.test.client import RequestFactory
from django.test.utils import override_settings from django.test.utils import override_settings
from mock import Mock
import external_auth.views
from edxmako.middleware import MakoMiddleware from edxmako.middleware import MakoMiddleware
from external_auth.models import ExternalAuthMap from external_auth.models import ExternalAuthMap
from opaque_keys import InvalidKeyError import external_auth.views
from mock import Mock
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from student.models import CourseEnrollment from student.models import CourseEnrollment
from student.roles import CourseStaffRole from student.roles import CourseStaffRole
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
from xmodule.modulestore.tests.django_utils import (ModuleStoreTestCase, from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
mixed_store_config)
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
FEATURES_WITH_SSL_AUTH = settings.FEATURES.copy() FEATURES_WITH_SSL_AUTH = settings.FEATURES.copy()
...@@ -35,8 +33,6 @@ FEATURES_WITH_SSL_AUTH_AUTO_ACTIVATE['BYPASS_ACTIVATION_EMAIL_FOR_EXTAUTH'] = Tr ...@@ -35,8 +33,6 @@ FEATURES_WITH_SSL_AUTH_AUTO_ACTIVATE['BYPASS_ACTIVATION_EMAIL_FOR_EXTAUTH'] = Tr
FEATURES_WITHOUT_SSL_AUTH = settings.FEATURES.copy() FEATURES_WITHOUT_SSL_AUTH = settings.FEATURES.copy()
FEATURES_WITHOUT_SSL_AUTH['AUTH_USE_CERTIFICATES'] = False FEATURES_WITHOUT_SSL_AUTH['AUTH_USE_CERTIFICATES'] = False
TEST_DATA_MIXED_MODULESTORE = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {})
@override_settings(FEATURES=FEATURES_WITH_SSL_AUTH) @override_settings(FEATURES=FEATURES_WITH_SSL_AUTH)
class SSLClientTest(ModuleStoreTestCase): class SSLClientTest(ModuleStoreTestCase):
...@@ -325,7 +321,7 @@ class SSLClientTest(ModuleStoreTestCase): ...@@ -325,7 +321,7 @@ class SSLClientTest(ModuleStoreTestCase):
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
@override_settings(FEATURES=FEATURES_WITH_SSL_AUTH_AUTO_ACTIVATE, @override_settings(FEATURES=FEATURES_WITH_SSL_AUTH_AUTO_ACTIVATE,
MODULESTORE=TEST_DATA_MIXED_MODULESTORE) MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
def test_ssl_lms_redirection(self): def test_ssl_lms_redirection(self):
""" """
Auto signup auth user and ensure they return to the original Auto signup auth user and ensure they return to the original
......
""" """
Tests for CountryMiddleware. Tests for CountryMiddleware.
""" """
from mock import patch
from mock import Mock, patch
import pygeoip import pygeoip
from django.contrib.sessions.middleware import SessionMiddleware
from django.test import TestCase from django.test import TestCase
from django.test.utils import override_settings from django.test.utils import override_settings
from django.test.client import RequestFactory from django.test.client import RequestFactory
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE
from student.models import CourseEnrollment
from student.tests.factories import UserFactory, AnonymousUserFactory
from django.contrib.sessions.middleware import SessionMiddleware
from geoinfo.middleware import CountryMiddleware from geoinfo.middleware import CountryMiddleware
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from student.tests.factories import UserFactory, AnonymousUserFactory
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class CountryMiddlewareTests(TestCase): class CountryMiddlewareTests(TestCase):
""" """
Tests of CountryMiddleware. Tests of CountryMiddleware.
......
...@@ -7,14 +7,14 @@ import pytz ...@@ -7,14 +7,14 @@ import pytz
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.test.utils import override_settings from django.test.utils import override_settings
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from reverification.models import MidcourseReverificationWindow from reverification.models import MidcourseReverificationWindow
from reverification.tests.factories import MidcourseReverificationWindowFactory from reverification.tests.factories import MidcourseReverificationWindowFactory
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestMidcourseReverificationWindow(ModuleStoreTestCase): class TestMidcourseReverificationWindow(ModuleStoreTestCase):
""" Tests for MidcourseReverificationWindow objects """ """ Tests for MidcourseReverificationWindow objects """
......
...@@ -4,25 +4,27 @@ that bulk email is always disabled for non-Mongo backed courses, regardless ...@@ -4,25 +4,27 @@ that bulk email is always disabled for non-Mongo backed courses, regardless
of email feature flag, and that the view is conditionally available when of email feature flag, and that the view is conditionally available when
Course Auth is turned on. Course Auth is turned on.
""" """
import unittest
from django.test.utils import override_settings
from django.conf import settings from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
import unittest from django.test.utils import override_settings
from mock import patch
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE
from student.tests.factories import UserFactory, CourseEnrollmentFactory from student.tests.factories import UserFactory, CourseEnrollmentFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.django_utils import (
TEST_DATA_MOCK_MODULESTORE, TEST_DATA_MIXED_TOY_MODULESTORE
)
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from bulk_email.models import CourseAuthorization # This import is for an lms djangoapp.
# Its testcases are only run under lms.
from mock import patch from bulk_email.models import CourseAuthorization # pylint: disable=import-error
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class TestStudentDashboardEmailView(ModuleStoreTestCase): class TestStudentDashboardEmailView(ModuleStoreTestCase):
""" """
...@@ -88,7 +90,7 @@ class TestStudentDashboardEmailView(ModuleStoreTestCase): ...@@ -88,7 +90,7 @@ class TestStudentDashboardEmailView(ModuleStoreTestCase):
self.assertTrue(self.email_modal_link in response.content) self.assertTrue(self.email_modal_link in response.content)
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_TOY_MODULESTORE)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class TestStudentDashboardEmailViewXMLBacked(ModuleStoreTestCase): class TestStudentDashboardEmailViewXMLBacked(ModuleStoreTestCase):
""" """
......
...@@ -3,7 +3,6 @@ Tests for student activation and login ...@@ -3,7 +3,6 @@ Tests for student activation and login
''' '''
import json import json
import unittest import unittest
from mock import patch
from django.test import TestCase from django.test import TestCase
from django.test.client import Client from django.test.client import Client
...@@ -12,23 +11,21 @@ from django.conf import settings ...@@ -12,23 +11,21 @@ from django.conf import settings
from django.core.cache import cache from django.core.cache import cache
from django.core.urlresolvers import reverse, NoReverseMatch from django.core.urlresolvers import reverse, NoReverseMatch
from django.http import HttpResponseBadRequest, HttpResponse from django.http import HttpResponseBadRequest, HttpResponse
from external_auth.models import ExternalAuthMap
import httpretty import httpretty
from mock import patch
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from social.apps.django_app.default.models import UserSocialAuth from social.apps.django_app.default.models import UserSocialAuth
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from student.tests.factories import UserFactory, RegistrationFactory, UserProfileFactory from student.tests.factories import UserFactory, RegistrationFactory, UserProfileFactory
from student.views import ( from student.views import (
_parse_course_id_from_string, _parse_course_id_from_string,
_get_course_enrollment_domain, _get_course_enrollment_domain,
login_oauth_token, login_oauth_token,
) )
from xmodule.modulestore.tests.factories import CourseFactory 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 xmodule.modulestore.django import modulestore
from external_auth.models import ExternalAuthMap
from opaque_keys.edx.locations import SlashSeparatedCourseKey
TEST_DATA_MIXED_MODULESTORE = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {})
class LoginTest(TestCase): class LoginTest(TestCase):
...@@ -345,7 +342,7 @@ class UtilFnTest(TestCase): ...@@ -345,7 +342,7 @@ class UtilFnTest(TestCase):
self.assertIsNone(_parse_course_id_from_string(NON_COURSE_URL)) self.assertIsNone(_parse_course_id_from_string(NON_COURSE_URL))
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class ExternalAuthShibTest(ModuleStoreTestCase): class ExternalAuthShibTest(ModuleStoreTestCase):
""" """
Tests how login_user() interacts with ExternalAuth, in particular Shib Tests how login_user() interacts with ExternalAuth, in particular Shib
......
...@@ -5,35 +5,38 @@ when you run "manage.py test". ...@@ -5,35 +5,38 @@ when you run "manage.py test".
Replace this with more appropriate tests for your application. Replace this with more appropriate tests for your application.
""" """
import logging
import unittest
from datetime import datetime, timedelta from datetime import datetime, timedelta
import logging
import pytz import pytz
import unittest
from django.conf import settings from django.conf import settings
from django.test import TestCase
from django.test.utils import override_settings
from django.test.client import RequestFactory, Client
from django.contrib.auth.models import User, AnonymousUser from django.contrib.auth.models import User, AnonymousUser
from django.core.urlresolvers import reverse
from django.contrib.sessions.middleware import SessionMiddleware from django.contrib.sessions.middleware import SessionMiddleware
from django.core.urlresolvers import reverse
from xmodule.modulestore.tests.factories import CourseFactory from django.test import TestCase
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from django.test.client import RequestFactory, Client
from courseware.tests.tests import TEST_DATA_MIXED_MODULESTORE from django.test.utils import override_settings
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from mock import Mock, patch from mock import Mock, patch
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from student.models import anonymous_id_for_user, user_by_anonymous_id, CourseEnrollment, unique_id_for_user from student.models import (
anonymous_id_for_user, user_by_anonymous_id, CourseEnrollment, unique_id_for_user
)
from student.views import (process_survey_link, _cert_info, from student.views import (process_survey_link, _cert_info,
change_enrollment, complete_course_mode_info) change_enrollment, complete_course_mode_info)
from student.tests.factories import UserFactory, CourseModeFactory 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.
from bulk_email.models import Optout # pylint: disable=import-error
from certificates.models import CertificateStatuses # pylint: disable=import-error
from certificates.tests.factories import GeneratedCertificateFactory # pylint: disable=import-error
import shoppingcart # pylint: disable=import-error
from certificates.models import CertificateStatuses
from certificates.tests.factories import GeneratedCertificateFactory
import shoppingcart
from bulk_email.models import Optout
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -176,7 +179,7 @@ class CourseEndingTest(TestCase): ...@@ -176,7 +179,7 @@ class CourseEndingTest(TestCase):
self.assertIsNone(_cert_info(user, course2, cert_status)) self.assertIsNone(_cert_info(user, course2, cert_status))
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class DashboardTest(ModuleStoreTestCase): class DashboardTest(ModuleStoreTestCase):
""" """
Tests for dashboard utility functions Tests for dashboard utility functions
...@@ -580,7 +583,7 @@ class EnrollInCourseTest(TestCase): ...@@ -580,7 +583,7 @@ class EnrollInCourseTest(TestCase):
self.assert_enrollment_mode_change_event_was_emitted(user, course_id, "honor") self.assert_enrollment_mode_change_event_was_emitted(user, course_id, "honor")
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class ChangeEnrollmentViewTest(ModuleStoreTestCase): class ChangeEnrollmentViewTest(ModuleStoreTestCase):
"""Tests the student.views.change_enrollment view""" """Tests the student.views.change_enrollment view"""
...@@ -663,7 +666,7 @@ class ChangeEnrollmentViewTest(ModuleStoreTestCase): ...@@ -663,7 +666,7 @@ class ChangeEnrollmentViewTest(ModuleStoreTestCase):
self.assertEqual(enrollment_mode, u'honor') self.assertEqual(enrollment_mode, u'honor')
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class PaidRegistrationTest(ModuleStoreTestCase): class PaidRegistrationTest(ModuleStoreTestCase):
""" """
Tests for paid registration functionality (not verified student), involves shoppingcart Tests for paid registration functionality (not verified student), involves shoppingcart
...@@ -696,7 +699,7 @@ class PaidRegistrationTest(ModuleStoreTestCase): ...@@ -696,7 +699,7 @@ class PaidRegistrationTest(ModuleStoreTestCase):
shoppingcart.models.Order.get_cart_for_user(self.user), self.course.id)) shoppingcart.models.Order.get_cart_for_user(self.user), self.course.id))
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class AnonymousLookupTable(ModuleStoreTestCase): class AnonymousLookupTable(ModuleStoreTestCase):
""" """
Tests for anonymous_id_functions Tests for anonymous_id_functions
......
...@@ -2,21 +2,25 @@ ...@@ -2,21 +2,25 @@
""" """
Modulestore configuration for test cases. Modulestore configuration for test cases.
""" """
import datetime
import pytz
from tempfile import mkdtemp
from uuid import uuid4 from uuid import uuid4
from django.test import TestCase
from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.test import TestCase
from request_cache.middleware import RequestCache
from xmodule.contentstore.django import _CONTENTSTORE from xmodule.contentstore.django import _CONTENTSTORE
from xmodule.modulestore.django import modulestore, clear_existing_modulestores
from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore import ModuleStoreEnum
import datetime from xmodule.modulestore.django import modulestore, clear_existing_modulestores
import pytz
from request_cache.middleware import RequestCache
from xmodule.tabs import CoursewareTab, CourseInfoTab, StaticTab, DiscussionTab, ProgressTab, WikiTab
from xmodule.modulestore.tests.sample_courses import default_block_info_tree, TOY_BLOCK_INFO_TREE
from xmodule.modulestore.tests.mongo_connection import MONGO_PORT_NUM, MONGO_HOST 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.tabs import CoursewareTab, CourseInfoTab, StaticTab, DiscussionTab, ProgressTab, WikiTab
def mixed_store_config(data_dir, mappings, include_xml=True): def mixed_store_config(data_dir, mappings, include_xml=False, xml_course_dirs=None):
""" """
Return a `MixedModuleStore` configuration, which provides Return a `MixedModuleStore` configuration, which provides
access to both Mongo- and XML-backed courses. access to both Mongo- and XML-backed courses.
...@@ -36,9 +40,12 @@ def mixed_store_config(data_dir, mappings, include_xml=True): ...@@ -36,9 +40,12 @@ def mixed_store_config(data_dir, mappings, include_xml=True):
Keyword Args: Keyword Args:
include_xml (boolean): If True, include an XML modulestore in the configuration. include_xml (boolean): If True, include an XML modulestore in the configuration.
Note that this will require importing multiple XML courses from disk, xml_course_dirs (list): The directories containing XML courses to load from disk.
so unless your tests really needs XML course fixtures or is explicitly
testing mixed modulestore, set this to False. note: For the courses to be loaded into the XML modulestore and accessible do the following:
include_xml should be True
xml_course_dirs should be the list of courses you want to load
mappings should be configured, pointing the xml courses to the xml modulestore
""" """
stores = [ stores = [
...@@ -47,7 +54,7 @@ def mixed_store_config(data_dir, mappings, include_xml=True): ...@@ -47,7 +54,7 @@ def mixed_store_config(data_dir, mappings, include_xml=True):
] ]
if include_xml: if include_xml:
stores.append(xml_store_config(data_dir)['default']) stores.append(xml_store_config(data_dir, course_dirs=xml_course_dirs)['default'])
store = { store = {
'default': { 'default': {
...@@ -80,7 +87,7 @@ def draft_mongo_store_config(data_dir): ...@@ -80,7 +87,7 @@ def draft_mongo_store_config(data_dir):
'host': MONGO_HOST, 'host': MONGO_HOST,
'port': MONGO_PORT_NUM, 'port': MONGO_PORT_NUM,
'db': 'test_xmodule', 'db': 'test_xmodule',
'collection': 'modulestore{0}'.format(uuid4().hex[:5]), 'collection': 'modulestore_{0}'.format(uuid4().hex[:5]),
}, },
'OPTIONS': modulestore_options 'OPTIONS': modulestore_options
} }
...@@ -107,7 +114,7 @@ def split_mongo_store_config(data_dir): ...@@ -107,7 +114,7 @@ def split_mongo_store_config(data_dir):
'host': MONGO_HOST, 'host': MONGO_HOST,
'port': MONGO_PORT_NUM, 'port': MONGO_PORT_NUM,
'db': 'test_xmodule', 'db': 'test_xmodule',
'collection': 'modulestore{0}'.format(uuid4().hex[:5]), 'collection': 'modulestore_{0}'.format(uuid4().hex[:5]),
}, },
'OPTIONS': modulestore_options 'OPTIONS': modulestore_options
} }
...@@ -119,6 +126,9 @@ def split_mongo_store_config(data_dir): ...@@ -119,6 +126,9 @@ def split_mongo_store_config(data_dir):
def xml_store_config(data_dir, course_dirs=None): def xml_store_config(data_dir, course_dirs=None):
""" """
Defines default module store using XMLModuleStore. Defines default module store using XMLModuleStore.
Note: you should pass in a list of course_dirs that you care about,
otherwise all courses in the data_dir will be processed.
""" """
store = { store = {
'default': { 'default': {
...@@ -134,6 +144,39 @@ def xml_store_config(data_dir, course_dirs=None): ...@@ -134,6 +144,39 @@ def xml_store_config(data_dir, course_dirs=None):
return store return store
TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
# This is an XML only modulestore with only the toy course loaded
TEST_DATA_XML_MODULESTORE = xml_store_config(TEST_DATA_DIR, course_dirs=['toy'])
# This modulestore will provide both a mixed mongo editable modulestore, and
# an XML store with just the toy course loaded.
TEST_DATA_MIXED_TOY_MODULESTORE = mixed_store_config(
TEST_DATA_DIR, {'edX/toy/2012_Fall': 'xml', }, include_xml=True, xml_course_dirs=['toy']
)
# This modulestore will provide both a mixed mongo editable modulestore, and
# an XML store with common/test/data/2014 loaded, which is a course that is closed.
TEST_DATA_MIXED_CLOSED_MODULESTORE = mixed_store_config(
TEST_DATA_DIR, {'edX/detached_pages/2014': 'xml', }, include_xml=True, xml_course_dirs=['2014']
)
# This modulestore will provide both a mixed mongo editable modulestore, and
# an XML store with common/test/data/graded loaded, which is a course that is graded.
TEST_DATA_MIXED_GRADED_MODULESTORE = mixed_store_config(
TEST_DATA_DIR, {'edX/graded/2012_Fall': 'xml', }, include_xml=True, xml_course_dirs=['graded']
)
# All store requests now go through mixed
# Use this modulestore if you specifically want to test mongo and not a mocked modulestore.
# This modulestore definition below will not load any xml courses.
TEST_DATA_MONGO_MODULESTORE = mixed_store_config(mkdtemp(), {}, include_xml=False)
# Unit tests that are not specifically testing the modulestore implementation but just need course context can use a mocked modulestore.
# Use this modulestore if you do not care about the underlying implementation.
# TODO: acutally mock out the modulestore for this in a subsequent PR.
TEST_DATA_MOCK_MODULESTORE = mixed_store_config(mkdtemp(), {}, include_xml=False)
class ModuleStoreTestCase(TestCase): class ModuleStoreTestCase(TestCase):
""" """
......
...@@ -3,17 +3,17 @@ Tests for assetstore using any of the modulestores for metadata. May extend to t ...@@ -3,17 +3,17 @@ Tests for assetstore using any of the modulestores for metadata. May extend to t
too. too.
""" """
from datetime import datetime, timedelta from datetime import datetime, timedelta
import ddt
from nose.plugins.attrib import attr
import pytz import pytz
import unittest import unittest
import ddt
from xmodule.assetstore import AssetMetadata from xmodule.assetstore import AssetMetadata
from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.test_cross_modulestore_import_export import ( from xmodule.modulestore.tests.test_cross_modulestore_import_export import (
MIXED_MODULESTORE_BOTH_SETUP, MODULESTORE_SETUPS, MongoContentstoreBuilder, MIXED_MODULESTORE_BOTH_SETUP, MODULESTORE_SETUPS, MongoContentstoreBuilder,
XmlModulestoreBuilder, MixedModulestoreBuilder, MongoModulestoreBuilder XmlModulestoreBuilder, MixedModulestoreBuilder
) )
...@@ -43,6 +43,7 @@ class AssetStoreTestData(object): ...@@ -43,6 +43,7 @@ class AssetStoreTestData(object):
) )
@attr('mongo')
@ddt.ddt @ddt.ddt
class TestMongoAssetMetadataStorage(unittest.TestCase): class TestMongoAssetMetadataStorage(unittest.TestCase):
""" """
......
...@@ -11,16 +11,17 @@ and then for each combination of modulestores, performing the sequence: ...@@ -11,16 +11,17 @@ and then for each combination of modulestores, performing the sequence:
4) Compare all modules in the source and destination modulestores to make sure that they line up 4) Compare all modules in the source and destination modulestores to make sure that they line up
""" """
import ddt from contextlib import contextmanager, nested
import itertools import itertools
from path import path
import random import random
from contextlib import contextmanager, nested
from shutil import rmtree from shutil import rmtree
from tempfile import mkdtemp from tempfile import mkdtemp
from path import path
from xmodule.tests import CourseComparisonTest import ddt
from nose.plugins.attrib import attr
from xmodule.tests import CourseComparisonTest
from xmodule.modulestore.mongo.base import ModuleStoreEnum from xmodule.modulestore.mongo.base import ModuleStoreEnum
from xmodule.modulestore.mongo.draft import DraftModuleStore from xmodule.modulestore.mongo.draft import DraftModuleStore
from xmodule.modulestore.mixed import MixedModuleStore from xmodule.modulestore.mixed import MixedModuleStore
...@@ -289,6 +290,7 @@ COURSE_DATA_NAMES = ( ...@@ -289,6 +290,7 @@ COURSE_DATA_NAMES = (
@ddt.ddt @ddt.ddt
@attr('mongo')
class CrossStoreXMLRoundtrip(CourseComparisonTest): class CrossStoreXMLRoundtrip(CourseComparisonTest):
""" """
This class exists to test XML import and export between different modulestore This class exists to test XML import and export between different modulestore
......
...@@ -2,25 +2,26 @@ ...@@ -2,25 +2,26 @@
""" """
Unit tests for the Mixed Modulestore, with DDT for the various stores (Split, Draft, XML) Unit tests for the Mixed Modulestore, with DDT for the various stores (Split, Draft, XML)
""" """
from collections import namedtuple
import datetime import datetime
import ddt import ddt
import itertools
import pymongo
from collections import namedtuple
from importlib import import_module from importlib import import_module
from pytz import UTC import itertools
import mimetypes
from uuid import uuid4 from uuid import uuid4
# Mixed modulestore depends on django, so we'll manually configure some django settings # Mixed modulestore depends on django, so we'll manually configure some django settings
# before importing the module # before importing the module
# TODO remove this import and the configuration -- xmodule should not depend on django! # TODO remove this import and the configuration -- xmodule should not depend on django!
from django.conf import settings from django.conf import settings
from nose.plugins.attrib import attr
import pymongo
from pytz import UTC
from xmodule.modulestore.edit_info import EditInfoMixin from xmodule.modulestore.edit_info import EditInfoMixin
from xmodule.modulestore.inheritance import InheritanceMixin from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.modulestore.tests.test_cross_modulestore_import_export import MongoContentstoreBuilder from xmodule.modulestore.tests.test_cross_modulestore_import_export import MongoContentstoreBuilder
from xmodule.contentstore.content import StaticContent from xmodule.contentstore.content import StaticContent
import mimetypes
from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.keys import CourseKey
from xmodule.modulestore.xml_importer import import_from_xml from xmodule.modulestore.xml_importer import import_from_xml
from nose import SkipTest from nose import SkipTest
...@@ -43,6 +44,7 @@ from xmodule.tests import DATA_DIR, CourseComparisonTest ...@@ -43,6 +44,7 @@ from xmodule.tests import DATA_DIR, CourseComparisonTest
@ddt.ddt @ddt.ddt
@attr('mongo')
class TestMixedModuleStore(CourseComparisonTest): class TestMixedModuleStore(CourseComparisonTest):
""" """
Quasi-superclass which tests Location based apps against both split and mongo dbs (Locator and Quasi-superclass which tests Location based apps against both split and mongo dbs (Locator and
......
""" """
Test the publish code (mostly testing that publishing doesn't result in orphans) Test the publish code (mostly testing that publishing doesn't result in orphans)
""" """
from nose.plugins.attrib import attr
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.exceptions import ItemNotFoundError from xmodule.modulestore.exceptions import ItemNotFoundError
from xmodule.modulestore.tests.test_split_w_old_mongo import SplitWMongoCourseBoostrapper from xmodule.modulestore.tests.test_split_w_old_mongo import SplitWMongoCourseBoostrapper
from xmodule.modulestore.tests.factories import check_mongo_calls, mongo_uses_error_check from xmodule.modulestore.tests.factories import check_mongo_calls, mongo_uses_error_check
from xmodule.modulestore import ModuleStoreEnum
@attr('mongo')
class TestPublish(SplitWMongoCourseBoostrapper): class TestPublish(SplitWMongoCourseBoostrapper):
""" """
Test the publish code (primary causing orphans) Test the publish code (primary causing orphans)
......
...@@ -2,14 +2,18 @@ ...@@ -2,14 +2,18 @@
Tests for split_migrator Tests for split_migrator
""" """
import uuid
import random import random
import uuid
import mock import mock
from nose.plugins.attrib import attr
from xblock.fields import Reference, ReferenceList, ReferenceValueDict from xblock.fields import Reference, ReferenceList, ReferenceValueDict
from xmodule.modulestore.split_migrator import SplitMigrator from xmodule.modulestore.split_migrator import SplitMigrator
from xmodule.modulestore.tests.test_split_w_old_mongo import SplitWMongoCourseBoostrapper from xmodule.modulestore.tests.test_split_w_old_mongo import SplitWMongoCourseBoostrapper
@attr('mongo')
class TestMigration(SplitWMongoCourseBoostrapper): class TestMigration(SplitWMongoCourseBoostrapper):
""" """
Test the split migrator Test the split migrator
......
...@@ -2,13 +2,15 @@ ...@@ -2,13 +2,15 @@
Test split modulestore w/o using any django stuff. Test split modulestore w/o using any django stuff.
""" """
import datetime import datetime
from importlib import import_module
from path import path
import random import random
import re import re
import unittest import unittest
import uuid import uuid
from contracts import contract from contracts import contract
from importlib import import_module from nose.plugins.attrib import attr
from path import path
from xblock.fields import Reference, ReferenceList, ReferenceValueDict from xblock.fields import Reference, ReferenceList, ReferenceValueDict
from xmodule.course_module import CourseDescriptor from xmodule.course_module import CourseDescriptor
...@@ -33,6 +35,7 @@ BRANCH_NAME_DRAFT = ModuleStoreEnum.BranchName.draft ...@@ -33,6 +35,7 @@ BRANCH_NAME_DRAFT = ModuleStoreEnum.BranchName.draft
BRANCH_NAME_PUBLISHED = ModuleStoreEnum.BranchName.published BRANCH_NAME_PUBLISHED = ModuleStoreEnum.BranchName.published
@attr('mongo')
class SplitModuleTest(unittest.TestCase): class SplitModuleTest(unittest.TestCase):
''' '''
The base set of tests manually populates a db w/ courses which have The base set of tests manually populates a db w/ courses which have
......
import unittest
import mock
import datetime import datetime
import uuid
import random import random
import unittest
import uuid
from nose.plugins.attrib import attr
import mock
from xmodule.modulestore.inheritance import InheritanceMixin
from opaque_keys.edx.locator import CourseLocator, BlockUsageLocator from opaque_keys.edx.locator import CourseLocator, BlockUsageLocator
from xmodule.modulestore.split_mongo.split import SplitMongoModuleStore
from xmodule.modulestore.mongo import DraftMongoModuleStore
from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.modulestore.mongo import DraftMongoModuleStore
from xmodule.modulestore.split_mongo.split import SplitMongoModuleStore
from xmodule.modulestore.tests.mongo_connection import MONGO_PORT_NUM, MONGO_HOST from xmodule.modulestore.tests.mongo_connection import MONGO_PORT_NUM, MONGO_HOST
from xmodule.modulestore.tests.test_cross_modulestore_import_export import MemoryCache from xmodule.modulestore.tests.test_cross_modulestore_import_export import MemoryCache
@attr('mongo')
class SplitWMongoCourseBoostrapper(unittest.TestCase): class SplitWMongoCourseBoostrapper(unittest.TestCase):
""" """
Helper for tests which need to construct split mongo & old mongo based courses to get interesting internal structure. Helper for tests which need to construct split mongo & old mongo based courses to get interesting internal structure.
......
...@@ -2,20 +2,19 @@ ...@@ -2,20 +2,19 @@
Tests for branding page Tests for branding page
""" """
import datetime import datetime
from django.http import HttpResponseRedirect
from pytz import UTC
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import AnonymousUser from django.contrib.auth.models import AnonymousUser
from django.http import HttpResponseRedirect
from django.test.utils import override_settings from django.test.utils import override_settings
from django.test.client import RequestFactory from django.test.client import RequestFactory
from pytz import UTC
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.factories import CourseFactory
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE
import student.views
from branding.views import index from branding.views import index
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from edxmako.tests import mako_middleware_process_request from edxmako.tests import mako_middleware_process_request
import student.views
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
FEATURES_WITH_STARTDATE = settings.FEATURES.copy() FEATURES_WITH_STARTDATE = settings.FEATURES.copy()
FEATURES_WITH_STARTDATE['DISABLE_START_DATES'] = False FEATURES_WITH_STARTDATE['DISABLE_START_DATES'] = False
...@@ -23,7 +22,7 @@ FEATURES_WO_STARTDATE = settings.FEATURES.copy() ...@@ -23,7 +22,7 @@ FEATURES_WO_STARTDATE = settings.FEATURES.copy()
FEATURES_WO_STARTDATE['DISABLE_START_DATES'] = True FEATURES_WO_STARTDATE['DISABLE_START_DATES'] = True
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class AnonymousIndexPageTest(ModuleStoreTestCase): class AnonymousIndexPageTest(ModuleStoreTestCase):
""" """
Tests that anonymous users can access the '/' page, Need courses with start date Tests that anonymous users can access the '/' page, Need courses with start date
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
Unit tests for student optouts from course email Unit tests for student optouts from course email
""" """
import json import json
from mock import patch
from django.core import mail from django.core import mail
from django.core.management import call_command from django.core.management import call_command
...@@ -10,16 +11,14 @@ from django.core.urlresolvers import reverse ...@@ -10,16 +11,14 @@ from django.core.urlresolvers import reverse
from django.conf import settings from django.conf import settings
from django.test.utils import override_settings from django.test.utils import override_settings
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from student.tests.factories import UserFactory, AdminFactory, CourseEnrollmentFactory from student.tests.factories import UserFactory, AdminFactory, CourseEnrollmentFactory
from student.models import CourseEnrollment from student.models import CourseEnrollment
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from mock import patch
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestOptoutCourseEmails(ModuleStoreTestCase): class TestOptoutCourseEmails(ModuleStoreTestCase):
""" """
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
Unit tests for sending course email Unit tests for sending course email
""" """
import json import json
from mock import patch from mock import patch
from django.conf import settings from django.conf import settings
...@@ -12,16 +11,15 @@ from django.core.urlresolvers import reverse ...@@ -12,16 +11,15 @@ from django.core.urlresolvers import reverse
from django.core.management import call_command from django.core.management import call_command
from django.test.utils import override_settings from django.test.utils import override_settings
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE
from student.tests.factories import CourseEnrollmentFactory, UserFactory
from courseware.tests.factories import StaffFactory, InstructorFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from bulk_email.models import Optout from bulk_email.models import Optout
from courseware.tests.factories import StaffFactory, InstructorFactory
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from instructor_task.subtasks import update_subtask_status from instructor_task.subtasks import update_subtask_status
from student.roles import CourseStaffRole from student.roles import CourseStaffRole
from student.models import CourseEnrollment from student.models import CourseEnrollment
from student.tests.factories import CourseEnrollmentFactory, UserFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
STAFF_COUNT = 3 STAFF_COUNT = 3
STUDENT_COUNT = 10 STUDENT_COUNT = 10
...@@ -44,7 +42,7 @@ class MockCourseEmailResult(object): ...@@ -44,7 +42,7 @@ class MockCourseEmailResult(object):
return mock_update_subtask_status return mock_update_subtask_status
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False}) @patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False})
class TestEmailSendFromDashboard(ModuleStoreTestCase): class TestEmailSendFromDashboard(ModuleStoreTestCase):
""" """
......
...@@ -2,28 +2,21 @@ ...@@ -2,28 +2,21 @@
""" """
Unit tests for handling email sending errors Unit tests for handling email sending errors
""" """
import json
from itertools import cycle from itertools import cycle
from mock import patch
from smtplib import SMTPDataError, SMTPServerDisconnected, SMTPConnectError
from celery.states import SUCCESS, RETRY from celery.states import SUCCESS, RETRY
from django.test.utils import override_settings from django.test.utils import override_settings
from django.conf import settings from django.conf import settings
from django.core.management import call_command from django.core.management import call_command
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.db import DatabaseError from django.db import DatabaseError
import json
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from mock import patch
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from smtplib import SMTPDataError, SMTPServerDisconnected, SMTPConnectError
from xmodule.modulestore.tests.factories import CourseFactory
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from student.tests.factories import UserFactory, AdminFactory, CourseEnrollmentFactory
from bulk_email.models import CourseEmail, SEND_TO_ALL from bulk_email.models import CourseEmail, SEND_TO_ALL
from bulk_email.tasks import perform_delegate_email_batches, send_course_email from bulk_email.tasks import perform_delegate_email_batches, send_course_email
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from instructor_task.models import InstructorTask from instructor_task.models import InstructorTask
from instructor_task.subtasks import ( from instructor_task.subtasks import (
initialize_subtask_info, initialize_subtask_info,
...@@ -33,6 +26,10 @@ from instructor_task.subtasks import ( ...@@ -33,6 +26,10 @@ from instructor_task.subtasks import (
DuplicateTaskException, DuplicateTaskException,
MAX_DATABASE_LOCK_RETRIES, MAX_DATABASE_LOCK_RETRIES,
) )
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from student.tests.factories import UserFactory, AdminFactory, CourseEnrollmentFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
class EmailTestException(Exception): class EmailTestException(Exception):
...@@ -40,7 +37,7 @@ class EmailTestException(Exception): ...@@ -40,7 +37,7 @@ class EmailTestException(Exception):
pass pass
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False}) @patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False})
class TestEmailErrors(ModuleStoreTestCase): class TestEmailErrors(ModuleStoreTestCase):
""" """
......
...@@ -2,25 +2,23 @@ ...@@ -2,25 +2,23 @@
""" """
Unit tests for bulk-email-related forms. Unit tests for bulk-email-related forms.
""" """
from django.test.utils import override_settings
from django.conf import settings from django.conf import settings
from django.test.utils import override_settings
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from xmodule.modulestore.django import modulestore
from xmodule.modulestore import ModuleStoreEnum
from mock import patch from mock import patch
from bulk_email.models import CourseAuthorization, CourseEmailTemplate from bulk_email.models import CourseAuthorization, CourseEmailTemplate
from bulk_email.forms import CourseAuthorizationAdminForm, CourseEmailTemplateForm from bulk_email.forms import CourseAuthorizationAdminForm, CourseEmailTemplateForm
from xmodule.modulestore.tests.django_utils import (
TEST_DATA_MOCK_MODULESTORE, TEST_DATA_MIXED_TOY_MODULESTORE
)
from opaque_keys.edx.locations import SlashSeparatedCourseKey from opaque_keys.edx.locations import SlashSeparatedCourseKey
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.django import modulestore
from xmodule.modulestore import ModuleStoreEnum
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class CourseAuthorizationFormTest(ModuleStoreTestCase): class CourseAuthorizationFormTest(ModuleStoreTestCase):
"""Test the CourseAuthorizationAdminForm form for Mongo-backed courses.""" """Test the CourseAuthorizationAdminForm form for Mongo-backed courses."""
...@@ -124,7 +122,7 @@ class CourseAuthorizationFormTest(ModuleStoreTestCase): ...@@ -124,7 +122,7 @@ class CourseAuthorizationFormTest(ModuleStoreTestCase):
form.save() form.save()
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_TOY_MODULESTORE)
class CourseAuthorizationXMLFormTest(ModuleStoreTestCase): class CourseAuthorizationXMLFormTest(ModuleStoreTestCase):
"""Check that XML courses cannot be authorized for email.""" """Check that XML courses cannot be authorized for email."""
...@@ -147,7 +145,7 @@ class CourseAuthorizationXMLFormTest(ModuleStoreTestCase): ...@@ -147,7 +145,7 @@ class CourseAuthorizationXMLFormTest(ModuleStoreTestCase):
form.save() form.save()
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class CourseEmailTemplateFormTest(ModuleStoreTestCase): class CourseEmailTemplateFormTest(ModuleStoreTestCase):
"""Test the CourseEmailTemplateForm that is used in the Django admin subsystem.""" """Test the CourseEmailTemplateForm that is used in the Django admin subsystem."""
......
...@@ -3,17 +3,18 @@ Tests for class dashboard (Metrics tab in instructor dashboard) ...@@ -3,17 +3,18 @@ Tests for class dashboard (Metrics tab in instructor dashboard)
""" """
import json import json
from mock import patch
from django.test.utils import override_settings from django.test.utils import override_settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test.client import RequestFactory from django.test.client import RequestFactory
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from mock import patch
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from capa.tests.response_xml_factory import StringResponseXMLFactory
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from courseware.tests.factories import StudentModuleFactory from courseware.tests.factories import StudentModuleFactory
from student.tests.factories import UserFactory, CourseEnrollmentFactory, AdminFactory from student.tests.factories import UserFactory, CourseEnrollmentFactory, AdminFactory
from capa.tests.response_xml_factory import StringResponseXMLFactory from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from class_dashboard.dashboard_data import (get_problem_grade_distribution, get_sequential_open_distrib, from class_dashboard.dashboard_data import (get_problem_grade_distribution, get_sequential_open_distrib,
get_problem_set_grade_distrib, get_d3_problem_grade_distrib, get_problem_set_grade_distrib, get_d3_problem_grade_distrib,
...@@ -26,7 +27,7 @@ from class_dashboard.views import has_instructor_access_for_class ...@@ -26,7 +27,7 @@ from class_dashboard.views import has_instructor_access_for_class
USER_COUNT = 11 USER_COUNT = 11
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestGetProblemGradeDistribution(ModuleStoreTestCase): class TestGetProblemGradeDistribution(ModuleStoreTestCase):
""" """
Tests related to class_dashboard/dashboard_data.py Tests related to class_dashboard/dashboard_data.py
......
""" """
Tests for class dashboard (Metrics tab in instructor dashboard) Tests for class dashboard (Metrics tab in instructor dashboard)
""" """
from mock import patch
from django.test.utils import override_settings from django.test.utils import override_settings
from django.test import TestCase
from django.test.client import RequestFactory from django.test.client import RequestFactory
from xmodule.modulestore.tests.factories import CourseFactory
from student.tests.factories import AdminFactory
from django.utils import simplejson from django.utils import simplejson
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from mock import patch
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from student.tests.factories import AdminFactory
from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from class_dashboard import views from class_dashboard import views
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestViews(ModuleStoreTestCase): class TestViews(ModuleStoreTestCase):
""" """
Tests related to class_dashboard/views.py Tests related to class_dashboard/views.py
......
...@@ -9,7 +9,7 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase ...@@ -9,7 +9,7 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from django.test.utils import override_settings from django.test.utils import override_settings
from courseware.tests.factories import InstructorFactory, StaffFactory from courseware.tests.factories import InstructorFactory, StaffFactory
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from wiki.models import URLPath from wiki.models import URLPath
from course_wiki.views import get_or_create_root from course_wiki.views import get_or_create_root
...@@ -17,7 +17,7 @@ from course_wiki.utils import user_is_article_course_staff, course_wiki_slug ...@@ -17,7 +17,7 @@ from course_wiki.utils import user_is_article_course_staff, course_wiki_slug
from course_wiki import settings from course_wiki import settings
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestWikiAccessBase(ModuleStoreTestCase): class TestWikiAccessBase(ModuleStoreTestCase):
"""Base class for testing wiki access.""" """Base class for testing wiki access."""
def setUp(self): def setUp(self):
......
...@@ -10,11 +10,11 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase ...@@ -10,11 +10,11 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from courseware.tests.factories import InstructorFactory from courseware.tests.factories import InstructorFactory
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from course_wiki.views import get_or_create_root from course_wiki.views import get_or_create_root
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestWikiAccessMiddleware(ModuleStoreTestCase): class TestWikiAccessMiddleware(ModuleStoreTestCase):
"""Tests for WikiAccessMiddleware.""" """Tests for WikiAccessMiddleware."""
......
...@@ -2,13 +2,13 @@ from django.core.urlresolvers import reverse ...@@ -2,13 +2,13 @@ from django.core.urlresolvers import reverse
from django.test.utils import override_settings from django.test.utils import override_settings
from courseware.tests.tests import LoginEnrollmentTestCase from courseware.tests.tests import LoginEnrollmentTestCase
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from mock import patch from mock import patch
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class WikiRedirectTestCase(LoginEnrollmentTestCase): class WikiRedirectTestCase(LoginEnrollmentTestCase):
""" """
Tests for wiki course redirection. Tests for wiki course redirection.
......
...@@ -3,33 +3,37 @@ ...@@ -3,33 +3,37 @@
"""Tests for Django management commands""" """Tests for Django management commands"""
import json import json
from path import path
import shutil import shutil
from StringIO import StringIO from StringIO import StringIO
import tarfile import tarfile
from tempfile import mkdtemp from tempfile import mkdtemp
from path import path from django.conf import settings
from django.core.management import call_command from django.core.management import call_command
from django.test.utils import override_settings from django.test.utils import override_settings
from django.test.testcases import TestCase from django.test.testcases import TestCase
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from courseware.tests.modulestore_config import TEST_DATA_XML_MODULESTORE
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE
from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, mixed_store_config
from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_MODULESTORE
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.xml_importer import import_from_xml from xmodule.modulestore.xml_importer import import_from_xml
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from django.conf import settings
DATA_DIR = settings.COMMON_TEST_DATA_ROOT DATA_DIR = settings.COMMON_TEST_DATA_ROOT
TEST_COURSE_ID = 'edX/simple/2012_Fall' TEST_COURSE_ID = 'edX/simple/2012_Fall'
XML_COURSE_DIRS = ['toy', 'simple', 'open_ended']
MAPPINGS = {
'edX/toy/2012_Fall': 'xml',
'edX/simple/2012_Fall': 'xml',
'edX/open_ended/2012_Fall': 'xml',
}
TEST_DATA_MIXED_XML_MODULESTORE = mixed_store_config(
DATA_DIR, MAPPINGS, include_xml=True, xml_course_dirs=XML_COURSE_DIRS
)
class CommandsTestBase(TestCase): class CommandsTestBase(TestCase):
""" """
...@@ -58,7 +62,7 @@ class CommandsTestBase(TestCase): ...@@ -58,7 +62,7 @@ class CommandsTestBase(TestCase):
courses = store.get_courses() courses = store.get_courses()
# NOTE: if xml store owns these, it won't import them into mongo # NOTE: if xml store owns these, it won't import them into mongo
if SlashSeparatedCourseKey.from_deprecated_string(TEST_COURSE_ID) not in [c.id for c in courses]: if SlashSeparatedCourseKey.from_deprecated_string(TEST_COURSE_ID) not in [c.id for c in courses]:
import_from_xml(store, ModuleStoreEnum.UserID.mgmt_command, DATA_DIR, ['toy', 'simple', 'open_ended']) import_from_xml(store, ModuleStoreEnum.UserID.mgmt_command, DATA_DIR, XML_COURSE_DIRS)
return [course.id for course in store.get_courses()] return [course.id for course in store.get_courses()]
...@@ -194,7 +198,7 @@ class CommandsTestBase(TestCase): ...@@ -194,7 +198,7 @@ class CommandsTestBase(TestCase):
assert_in('edX-simple-2012_Fall/sequential/Lecture_2.xml', names) assert_in('edX-simple-2012_Fall/sequential/Lecture_2.xml', names)
@override_settings(MODULESTORE=TEST_DATA_XML_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_XML_MODULESTORE)
class CommandsXMLTestCase(CommandsTestBase, ModuleStoreTestCase): class CommandsXMLTestCase(CommandsTestBase, ModuleStoreTestCase):
""" """
Test case for management commands using the xml modulestore. Test case for management commands using the xml modulestore.
...@@ -205,14 +209,6 @@ class CommandsXMLTestCase(CommandsTestBase, ModuleStoreTestCase): ...@@ -205,14 +209,6 @@ class CommandsXMLTestCase(CommandsTestBase, ModuleStoreTestCase):
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
class CommandsMongoTestCase(CommandsTestBase, ModuleStoreTestCase): class CommandsMongoTestCase(CommandsTestBase, ModuleStoreTestCase):
""" """
Test case for management commands using the mongo modulestore. Test case for management commands using the mixed mongo modulestore.
"""
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class CommandsMixedTestCase(CommandsTestBase, ModuleStoreTestCase):
"""
Test case for management commands. Using the mixed modulestore.
""" """
...@@ -13,7 +13,7 @@ from django.test.client import Client ...@@ -13,7 +13,7 @@ from django.test.client import Client
from edxmako.shortcuts import render_to_string from edxmako.shortcuts import render_to_string
from student.tests.factories import UserFactory, CourseEnrollmentFactory from student.tests.factories import UserFactory, CourseEnrollmentFactory
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_MODULESTORE
from xblock.field_data import DictFieldData from xblock.field_data import DictFieldData
from xmodule.tests import get_test_system, get_test_descriptor_system from xmodule.tests import get_test_system, get_test_descriptor_system
from opaque_keys.edx.locations import Location from opaque_keys.edx.locations import Location
......
"""
Define test configuration for modulestores.
"""
from xmodule.modulestore.tests.django_utils import xml_store_config, \
mixed_store_config
from django.conf import settings
TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
TEST_DATA_XML_MODULESTORE = xml_store_config(TEST_DATA_DIR)
# Map all XML course fixtures so they are accessible through
# the MixedModuleStore
MAPPINGS = {
'edX/simple/2012_Fall': 'xml',
'edX/toy/2012_Fall': 'xml',
'edX/toy/TT_2012_Fall': 'xml',
'edX/test_end/2012_Fall': 'xml',
'edX/test_about_blob_end_date/2012_Fall': 'xml',
'edX/graded/2012_Fall': 'xml',
'edX/open_ended/2012_Fall': 'xml',
'edX/due_date/2013_fall': 'xml',
'edX/open_ended_nopath/2012_Fall': 'xml',
'edX/detached_pages/2014': 'xml',
}
TEST_DATA_MIXED_MODULESTORE = mixed_store_config(TEST_DATA_DIR, MAPPINGS)
# All store requests now go through mixed
# Some tests require that no XML courses exist. So provide the following constant with no course Mappings.
TEST_DATA_MONGO_MODULESTORE = mixed_store_config(TEST_DATA_DIR, {})
""" """
Test the about xblock Test the about xblock
""" """
import mock
from mock import patch
import pytz
import datetime import datetime
from django.test.utils import override_settings import pytz
from django.core.urlresolvers import reverse
from django.conf import settings
from .helpers import LoginEnrollmentTestCase from django.conf import settings
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from django.core.urlresolvers import reverse
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE, TEST_DATA_MIXED_MODULESTORE from django.test.utils import override_settings
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from mock import patch
from opaque_keys.edx.locations import SlashSeparatedCourseKey from opaque_keys.edx.locations import SlashSeparatedCourseKey
from student.tests.factories import UserFactory, CourseEnrollmentAllowedFactory
from course_modes.models import CourseMode from course_modes.models import CourseMode
from xmodule.modulestore.tests.django_utils import (
TEST_DATA_MOCK_MODULESTORE, TEST_DATA_MIXED_CLOSED_MODULESTORE
)
from student.models import CourseEnrollment from student.models import CourseEnrollment
from student.tests.factories import UserFactory, CourseEnrollmentAllowedFactory
from shoppingcart.models import Order, PaidCourseRegistration from shoppingcart.models import Order, PaidCourseRegistration
from xmodule.course_module import CATALOG_VISIBILITY_ABOUT, CATALOG_VISIBILITY_NONE from xmodule.course_module import CATALOG_VISIBILITY_ABOUT, CATALOG_VISIBILITY_NONE
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from .helpers import LoginEnrollmentTestCase
# HTML for registration button # HTML for registration button
REG_STR = "<form id=\"class_enroll_form\" method=\"post\" data-remote=\"true\" action=\"/change_enrollment\">" REG_STR = "<form id=\"class_enroll_form\" method=\"post\" data-remote=\"true\" action=\"/change_enrollment\">"
SHIB_ERROR_STR = "The currently logged-in user account does not have permission to enroll in this course." SHIB_ERROR_STR = "The currently logged-in user account does not have permission to enroll in this course."
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class AboutTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase): class AboutTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
""" """
Tests about xblock. Tests about xblock.
...@@ -120,8 +121,11 @@ class AboutTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase): ...@@ -120,8 +121,11 @@ class AboutTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
self.assertTrue(target_url.endswith(info_url)) self.assertTrue(target_url.endswith(info_url))
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_CLOSED_MODULESTORE)
class AboutTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase): class AboutTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase):
"""
Tests for the course about page
"""
# The following XML test course (which lives at common/test/data/2014) # The following XML test course (which lives at common/test/data/2014)
# is closed; we're testing that an about page still appears when # is closed; we're testing that an about page still appears when
# the course is already closed # the course is already closed
...@@ -131,7 +135,7 @@ class AboutTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase): ...@@ -131,7 +135,7 @@ class AboutTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase):
# common/test/data/2014/about/overview.html # common/test/data/2014/about/overview.html
xml_data = "about page 463139" xml_data = "about page 463139"
@mock.patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False}) @patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False})
def test_logged_in_xml(self): def test_logged_in_xml(self):
self.setup_user() self.setup_user()
url = reverse('about_course', args=[self.xml_course_id.to_deprecated_string()]) url = reverse('about_course', args=[self.xml_course_id.to_deprecated_string()])
...@@ -139,7 +143,7 @@ class AboutTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase): ...@@ -139,7 +143,7 @@ class AboutTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase):
self.assertEqual(resp.status_code, 200) self.assertEqual(resp.status_code, 200)
self.assertIn(self.xml_data, resp.content) self.assertIn(self.xml_data, resp.content)
@mock.patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False}) @patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False})
def test_anonymous_user_xml(self): def test_anonymous_user_xml(self):
url = reverse('about_course', args=[self.xml_course_id.to_deprecated_string()]) url = reverse('about_course', args=[self.xml_course_id.to_deprecated_string()])
resp = self.client.get(url) resp = self.client.get(url)
...@@ -147,7 +151,7 @@ class AboutTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase): ...@@ -147,7 +151,7 @@ class AboutTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase):
self.assertIn(self.xml_data, resp.content) self.assertIn(self.xml_data, resp.content)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class AboutWithCappedEnrollmentsTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase): class AboutWithCappedEnrollmentsTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
""" """
This test case will check the About page when a course has a capped enrollment This test case will check the About page when a course has a capped enrollment
...@@ -197,7 +201,7 @@ class AboutWithCappedEnrollmentsTestCase(LoginEnrollmentTestCase, ModuleStoreTes ...@@ -197,7 +201,7 @@ class AboutWithCappedEnrollmentsTestCase(LoginEnrollmentTestCase, ModuleStoreTes
self.assertNotIn(REG_STR, resp.content) self.assertNotIn(REG_STR, resp.content)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class AboutWithInvitationOnly(ModuleStoreTestCase): class AboutWithInvitationOnly(ModuleStoreTestCase):
""" """
This test case will check the About page when a course is invitation only. This test case will check the About page when a course is invitation only.
...@@ -244,7 +248,7 @@ class AboutWithInvitationOnly(ModuleStoreTestCase): ...@@ -244,7 +248,7 @@ class AboutWithInvitationOnly(ModuleStoreTestCase):
@patch.dict(settings.FEATURES, {'RESTRICT_ENROLL_BY_REG_METHOD': True}) @patch.dict(settings.FEATURES, {'RESTRICT_ENROLL_BY_REG_METHOD': True})
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class AboutTestCaseShibCourse(LoginEnrollmentTestCase, ModuleStoreTestCase): class AboutTestCaseShibCourse(LoginEnrollmentTestCase, ModuleStoreTestCase):
""" """
Test cases covering about page behavior for courses that use shib enrollment domain ("shib courses") Test cases covering about page behavior for courses that use shib enrollment domain ("shib courses")
...@@ -283,7 +287,7 @@ class AboutTestCaseShibCourse(LoginEnrollmentTestCase, ModuleStoreTestCase): ...@@ -283,7 +287,7 @@ class AboutTestCaseShibCourse(LoginEnrollmentTestCase, ModuleStoreTestCase):
self.assertIn(REG_STR, resp.content) self.assertIn(REG_STR, resp.content)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class AboutWithClosedEnrollment(ModuleStoreTestCase): class AboutWithClosedEnrollment(ModuleStoreTestCase):
""" """
This test case will check the About page for a course that has enrollment start/end This test case will check the About page for a course that has enrollment start/end
...@@ -319,7 +323,7 @@ class AboutWithClosedEnrollment(ModuleStoreTestCase): ...@@ -319,7 +323,7 @@ class AboutWithClosedEnrollment(ModuleStoreTestCase):
self.assertNotIn(REG_STR, resp.content) self.assertNotIn(REG_STR, resp.content)
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch.dict(settings.FEATURES, {'ENABLE_SHOPPING_CART': True}) @patch.dict(settings.FEATURES, {'ENABLE_SHOPPING_CART': True})
@patch.dict(settings.FEATURES, {'ENABLE_PAID_COURSE_REGISTRATION': True}) @patch.dict(settings.FEATURES, {'ENABLE_PAID_COURSE_REGISTRATION': True})
class AboutPurchaseCourseTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase): class AboutPurchaseCourseTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
......
import courseware.access as access
import datetime import datetime
import pytz
import mock
from mock import Mock
from django.test import TestCase from django.test import TestCase
from mock import Mock, patch
from opaque_keys.edx.locations import SlashSeparatedCourseKey
import courseware.access as access
from courseware.tests.factories import UserFactory, StaffFactory, InstructorFactory from courseware.tests.factories import UserFactory, StaffFactory, InstructorFactory
from student.tests.factories import AnonymousUserFactory, CourseEnrollmentAllowedFactory from student.tests.factories import AnonymousUserFactory, CourseEnrollmentAllowedFactory
import pytz
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from xmodule.course_module import ( from xmodule.course_module import (
CATALOG_VISIBILITY_CATALOG_AND_ABOUT, CATALOG_VISIBILITY_ABOUT, CATALOG_VISIBILITY_CATALOG_AND_ABOUT, CATALOG_VISIBILITY_ABOUT,
CATALOG_VISIBILITY_NONE) CATALOG_VISIBILITY_NONE
)
# pylint: disable=missing-docstring # pylint: disable=missing-docstring
# pylint: disable=protected-access # pylint: disable=protected-access
...@@ -115,7 +113,7 @@ class AccessTestCase(TestCase): ...@@ -115,7 +113,7 @@ class AccessTestCase(TestCase):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
access._has_access_descriptor(user, 'not_load_or_staff', descriptor) access._has_access_descriptor(user, 'not_load_or_staff', descriptor)
@mock.patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False}) @patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False})
def test__has_access_descriptor_staff_lock(self): def test__has_access_descriptor_staff_lock(self):
""" """
Tests that "visible_to_staff_only" overrides start date. Tests that "visible_to_staff_only" overrides start date.
......
""" """
Test the course_info xblock Test the course_info xblock
""" """
import mock
from django.test.utils import override_settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test.utils import override_settings
import mock
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from .helpers import LoginEnrollmentTestCase
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE from xmodule.modulestore.tests.django_utils import (
TEST_DATA_MOCK_MODULESTORE, TEST_DATA_MIXED_CLOSED_MODULESTORE
)
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from .helpers import LoginEnrollmentTestCase
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class CourseInfoTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase): class CourseInfoTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
"""
Tests for the Course Info page
"""
def setUp(self): def setUp(self):
self.course = CourseFactory.create() self.course = CourseFactory.create()
self.page = ItemFactory.create( self.page = ItemFactory.create(
...@@ -41,12 +48,15 @@ class CourseInfoTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase): ...@@ -41,12 +48,15 @@ class CourseInfoTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
self.assertNotIn("OOGIE BLOOGIE", resp.content) self.assertNotIn("OOGIE BLOOGIE", resp.content)
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_CLOSED_MODULESTORE)
class CourseInfoTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase): class CourseInfoTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase):
"""
Tests for the Course Info page for an XML course
"""
# The following XML test course (which lives at common/test/data/2014) # 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 # is closed; we're testing that a course info page still appears when
# the course is already closed # the course is already closed
xml_course_id = 'edX/detached_pages/2014' xml_course_key = SlashSeparatedCourseKey('edX', 'detached_pages', '2014')
# this text appears in that course's course info page # this text appears in that course's course info page
# common/test/data/2014/info/updates.html # common/test/data/2014/info/updates.html
...@@ -55,14 +65,14 @@ class CourseInfoTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase): ...@@ -55,14 +65,14 @@ class CourseInfoTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase):
@mock.patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False}) @mock.patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False})
def test_logged_in_xml(self): def test_logged_in_xml(self):
self.setup_user() self.setup_user()
url = reverse('info', args=[self.xml_course_id]) url = reverse('info', args=[self.xml_course_key.to_deprecated_string()])
resp = self.client.get(url) resp = self.client.get(url)
self.assertEqual(resp.status_code, 200) self.assertEqual(resp.status_code, 200)
self.assertIn(self.xml_data, resp.content) self.assertIn(self.xml_data, resp.content)
@mock.patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False}) @mock.patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False})
def test_anonymous_user_xml(self): def test_anonymous_user_xml(self):
url = reverse('info', args=[self.xml_course_id]) url = reverse('info', args=[self.xml_course_key.to_deprecated_string()])
resp = self.client.get(url) resp = self.client.get(url)
self.assertEqual(resp.status_code, 200) self.assertEqual(resp.status_code, 200)
self.assertNotIn(self.xml_data, resp.content) self.assertNotIn(self.xml_data, resp.content)
...@@ -2,34 +2,38 @@ ...@@ -2,34 +2,38 @@
""" """
Tests for course access Tests for course access
""" """
from django.conf import settings
from django.test.utils import override_settings
import mock import mock
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from django.test.utils import override_settings from courseware.courses import (
get_course_by_id, get_cms_course_link, course_image_url,
get_course_info_section, get_course_about_section, get_cms_block_link
)
from courseware.tests.helpers import get_request_for_user
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
import xmodule.modulestore.django as store_django import xmodule.modulestore.django as store_django
from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.xml_importer import import_from_xml
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.django_utils import (
TEST_DATA_MOCK_MODULESTORE, TEST_DATA_MIXED_TOY_MODULESTORE
)
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.tests.xml import factories as xml from xmodule.tests.xml import factories as xml
from xmodule.tests.xml import XModuleXmlImportTest from xmodule.tests.xml import XModuleXmlImportTest
from courseware.courses import (
get_course_by_id, get_cms_course_link, course_image_url,
get_course_info_section, get_course_about_section, get_cms_block_link
)
from courseware.tests.helpers import get_request_for_user
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE, TEST_DATA_MIXED_MODULESTORE
from opaque_keys.edx.locations import SlashSeparatedCourseKey
CMS_BASE_TEST = 'testcms' CMS_BASE_TEST = 'testcms'
TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
class CoursesTest(ModuleStoreTestCase): class CoursesTest(ModuleStoreTestCase):
"""Test methods related to fetching courses.""" """Test methods related to fetching courses."""
@override_settings( @override_settings(
MODULESTORE=TEST_DATA_MONGO_MODULESTORE, CMS_BASE=CMS_BASE_TEST MODULESTORE=TEST_DATA_MOCK_MODULESTORE, CMS_BASE=CMS_BASE_TEST
) )
def test_get_cms_course_block_link(self): def test_get_cms_course_block_link(self):
""" """
...@@ -71,7 +75,7 @@ class ModuleStoreBranchSettingTest(ModuleStoreTestCase): ...@@ -71,7 +75,7 @@ class ModuleStoreBranchSettingTest(ModuleStoreTestCase):
@override_settings( @override_settings(
MODULESTORE=TEST_DATA_MONGO_MODULESTORE, CMS_BASE=CMS_BASE_TEST MODULESTORE=TEST_DATA_MOCK_MODULESTORE, CMS_BASE=CMS_BASE_TEST
) )
class MongoCourseImageTestCase(ModuleStoreTestCase): class MongoCourseImageTestCase(ModuleStoreTestCase):
"""Tests for course image URLs when using a mongo modulestore.""" """Tests for course image URLs when using a mongo modulestore."""
...@@ -144,35 +148,43 @@ class XmlCourseImageTestCase(XModuleXmlImportTest): ...@@ -144,35 +148,43 @@ class XmlCourseImageTestCase(XModuleXmlImportTest):
self.assertEquals(course_image_url(course), u'/static/xml_test_course/before after.jpg') self.assertEquals(course_image_url(course), u'/static/xml_test_course/before after.jpg')
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class CoursesRenderTest(ModuleStoreTestCase): class CoursesRenderTest(ModuleStoreTestCase):
"""Test methods related to rendering courses content.""" """Test methods related to rendering courses content."""
toy_course_key = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')
def test_get_course_info_section_render(self): # TODO: this test relies on the specific setup of the toy course.
course = get_course_by_id(self.toy_course_key) # It should be rewritten to build the course it needs and then test that.
request = get_request_for_user(UserFactory.create()) def setUp(self):
"""
Set up the course and user context
"""
super(CoursesRenderTest, self).setUp()
store = store_django.modulestore()
course_items = import_from_xml(store, self.user.id, TEST_DATA_DIR, ['toy'])
course_key = course_items[0].id
self.course = get_course_by_id(course_key)
self.request = get_request_for_user(UserFactory.create())
def test_get_course_info_section_render(self):
# Test render works okay # Test render works okay
course_info = get_course_info_section(request, course, 'handouts') course_info = get_course_info_section(self.request, self.course, 'handouts')
self.assertEqual(course_info, "<a href='/static/toy/handouts/sample_handout.txt'>Sample</a>") self.assertEqual(course_info, u"<a href='/c4x/edX/toy/asset/handouts_sample_handout.txt'>Sample</a>")
# Test when render raises an exception # Test when render raises an exception
with mock.patch('courseware.courses.get_module') as mock_module_render: with mock.patch('courseware.courses.get_module') as mock_module_render:
mock_module_render.return_value = mock.MagicMock( mock_module_render.return_value = mock.MagicMock(
render=mock.Mock(side_effect=Exception('Render failed!')) render=mock.Mock(side_effect=Exception('Render failed!'))
) )
course_info = get_course_info_section(request, course, 'handouts') course_info = get_course_info_section(self.request, self.course, 'handouts')
self.assertIn("this module is temporarily unavailable", course_info) self.assertIn("this module is temporarily unavailable", course_info)
@mock.patch('courseware.courses.get_request_for_thread') @mock.patch('courseware.courses.get_request_for_thread')
def test_get_course_about_section_render(self, mock_get_request): def test_get_course_about_section_render(self, mock_get_request):
course = get_course_by_id(self.toy_course_key) mock_get_request.return_value = self.request
request = get_request_for_user(UserFactory.create())
mock_get_request.return_value = request
# Test render works okay # Test render works okay
course_about = get_course_about_section(course, 'short_description') course_about = get_course_about_section(self.course, 'short_description')
self.assertEqual(course_about, "A course about toys.") self.assertEqual(course_about, "A course about toys.")
# Test when render raises an exception # Test when render raises an exception
...@@ -180,5 +192,27 @@ class CoursesRenderTest(ModuleStoreTestCase): ...@@ -180,5 +192,27 @@ class CoursesRenderTest(ModuleStoreTestCase):
mock_module_render.return_value = mock.MagicMock( mock_module_render.return_value = mock.MagicMock(
render=mock.Mock(side_effect=Exception('Render failed!')) render=mock.Mock(side_effect=Exception('Render failed!'))
) )
course_about = get_course_about_section(course, 'short_description') course_about = get_course_about_section(self.course, 'short_description')
self.assertIn("this module is temporarily unavailable", course_about) 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."""
toy_course_key = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')
def test_get_course_info_section_render(self):
course = get_course_by_id(self.toy_course_key)
request = get_request_for_user(UserFactory.create())
# Test render works okay. Note the href is different in XML courses.
course_info = get_course_info_section(request, course, 'handouts')
self.assertEqual(course_info, "<a href='/static/toy/handouts/sample_handout.txt'>Sample</a>")
# Test when render raises an exception
with mock.patch('courseware.courses.get_module') as mock_module_render:
mock_module_render.return_value = mock.MagicMock(
render=mock.Mock(side_effect=Exception('Render failed!'))
)
course_info = get_course_info_section(request, course, 'handouts')
self.assertIn("this module is temporarily unavailable", course_info)
...@@ -4,11 +4,14 @@ from django.test.utils import override_settings ...@@ -4,11 +4,14 @@ from django.test.utils import override_settings
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from opaque_keys.edx.locations import SlashSeparatedCourseKey from opaque_keys.edx.locations import SlashSeparatedCourseKey
from modulestore_config import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestDraftModuleStore(TestCase): class TestDraftModuleStore(TestCase):
"""
Test the draft modulestore
"""
def test_get_items_with_course_items(self): def test_get_items_with_course_items(self):
store = modulestore() store = modulestore()
......
...@@ -4,14 +4,13 @@ Test grade calculation. ...@@ -4,14 +4,13 @@ Test grade calculation.
from django.http import Http404 from django.http import Http404
from django.test.utils import override_settings from django.test.utils import override_settings
from mock import patch from mock import patch
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE from courseware.grades import grade, iterate_grades_for
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from courseware.grades import grade, iterate_grades_for
def _grade_with_errors(student, request, course, keep_raw_scores=False): def _grade_with_errors(student, request, course, keep_raw_scores=False):
...@@ -28,7 +27,7 @@ def _grade_with_errors(student, request, course, keep_raw_scores=False): ...@@ -28,7 +27,7 @@ def _grade_with_errors(student, request, course, keep_raw_scores=False):
return grade(student, request, course, keep_raw_scores=keep_raw_scores) return grade(student, request, course, keep_raw_scores=keep_raw_scores)
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestGradeIteration(ModuleStoreTestCase): class TestGradeIteration(ModuleStoreTestCase):
""" """
Test iteration through student gradesets. Test iteration through student gradesets.
......
""" """
Tests i18n in courseware Tests i18n in courseware
""" """
import re
from django.test import TestCase from django.test import TestCase
from django.test.utils import override_settings from django.test.utils import override_settings
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
import re from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE, LANGUAGES=(('eo', 'Esperanto'),)) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE, LANGUAGES=(('eo', 'Esperanto'),))
class I18nTestCase(TestCase): class I18nTestCase(TestCase):
""" """
Tests for i18n Tests for i18n
......
"""LTI integration tests""" """LTI integration tests"""
import oauthlib
from collections import OrderedDict from collections import OrderedDict
import json
import mock import mock
import oauthlib
import urllib import urllib
import json
from django.test.utils import override_settings
from django.core.urlresolvers import reverse
from django.conf import settings from django.conf import settings
from django.core.urlresolvers import reverse
from xmodule.modulestore import ModuleStoreEnum from django.test.utils import override_settings
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.x_module import STUDENT_VIEW
from courseware.tests import BaseTestXmodule from courseware.tests import BaseTestXmodule
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from courseware.views import get_course_lti_endpoints from courseware.views import get_course_lti_endpoints
from lms.lib.xblock.runtime import quote_slashes from lms.lib.xblock.runtime import quote_slashes
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.x_module import STUDENT_VIEW
class TestLTI(BaseTestXmodule): class TestLTI(BaseTestXmodule):
...@@ -126,7 +123,7 @@ class TestLTI(BaseTestXmodule): ...@@ -126,7 +123,7 @@ class TestLTI(BaseTestXmodule):
self.assertEqual(generated_content, expected_content) self.assertEqual(generated_content, expected_content)
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestLTIModuleListing(ModuleStoreTestCase): class TestLTIModuleListing(ModuleStoreTestCase):
""" """
a test for the rest endpoint that lists LTI modules in a course a test for the rest endpoint that lists LTI modules in a course
......
...@@ -7,32 +7,33 @@ Notes for running by hand: ...@@ -7,32 +7,33 @@ Notes for running by hand:
./manage.py lms --settings test test lms/djangoapps/courseware ./manage.py lms --settings test test lms/djangoapps/courseware
""" """
import json import json
from django.test.utils import override_settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test.utils import override_settings
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from courseware.tests.factories import StaffFactory from courseware.tests.factories import StaffFactory
from courseware.tests.helpers import LoginEnrollmentTestCase from courseware.tests.helpers import LoginEnrollmentTestCase
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.django import modulestore, clear_existing_modulestores
from lms.lib.xblock.runtime import quote_slashes from lms.lib.xblock.runtime import quote_slashes
from opaque_keys.edx.locations import SlashSeparatedCourseKey from xmodule.modulestore.django import modulestore, clear_existing_modulestores
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_GRADED_MODULESTORE
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) # TODO: the abtest in the sample course "graded" is currently preventing
# it from being successfully loaded in the mongo modulestore.
# Fix this testcase class to not depend on that course, and let it use
# the mocked modulestore instead of the XML.
@override_settings(MODULESTORE=TEST_DATA_MIXED_GRADED_MODULESTORE)
class TestStaffMasqueradeAsStudent(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestStaffMasqueradeAsStudent(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Check for staff being able to masquerade as student. Check for staff being able to masquerade as student.
""" """
def setUp(self): def setUp(self):
# Clear out the modulestores, causing them to reload # Clear out the modulestores, causing them to reload
clear_existing_modulestores() clear_existing_modulestores()
self.graded_course = modulestore().get_course(SlashSeparatedCourseKey("edX", "graded", "2012_Fall")) self.graded_course = modulestore().get_course(SlashSeparatedCourseKey("edX", "graded", "2012_Fall"))
# Create staff account # Create staff account
......
""" """
Tests related to the Microsites feature Tests related to the Microsites feature
""" """
from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test.utils import override_settings from django.test.utils import override_settings
from django.conf import settings
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from courseware.tests.helpers import LoginEnrollmentTestCase
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from helpers import LoginEnrollmentTestCase
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from course_modes.models import CourseMode from course_modes.models import CourseMode
from xmodule.course_module import ( from xmodule.course_module import (
CATALOG_VISIBILITY_CATALOG_AND_ABOUT, CATALOG_VISIBILITY_NONE) CATALOG_VISIBILITY_CATALOG_AND_ABOUT, CATALOG_VISIBILITY_NONE)
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestMicrosites(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestMicrosites(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
This is testing of the Microsite feature This is testing of the Microsite feature
......
...@@ -8,14 +8,14 @@ from django.test.client import RequestFactory ...@@ -8,14 +8,14 @@ from django.test.client import RequestFactory
from django.http import Http404 from django.http import Http404
from mock import patch from mock import patch
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
import courseware.courses as courses import courseware.courses as courses
from courseware.middleware import RedirectUnenrolledMiddleware from courseware.middleware import RedirectUnenrolledMiddleware
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class CoursewareMiddlewareTestCase(ModuleStoreTestCase): class CoursewareMiddlewareTestCase(ModuleStoreTestCase):
"""Tests that courseware middleware is correctly redirected""" """Tests that courseware middleware is correctly redirected"""
......
""" """
Test for lms courseware app, module render unit Test for lms courseware app, module render unit
""" """
import ddt
from functools import partial from functools import partial
from mock import MagicMock, patch, Mock
import json import json
from unittest import skip
import ddt
from django.http import Http404, HttpResponse from django.http import Http404, HttpResponse
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.conf import settings from django.conf import settings
from django.test.client import RequestFactory from django.test.client import RequestFactory
from django.test.utils import override_settings from django.test.utils import override_settings
from django.contrib.auth.models import AnonymousUser from django.contrib.auth.models import AnonymousUser
from mock import MagicMock, patch, Mock
from capa.tests.response_xml_factory import OptionResponseXMLFactory from opaque_keys.edx.locations import SlashSeparatedCourseKey
from xblock.field_data import FieldData from xblock.field_data import FieldData
from xblock.runtime import Runtime from xblock.runtime import Runtime
from xblock.fields import ScopeIds from xblock.fields import ScopeIds
from xblock.core import XBlock from xblock.core import XBlock
from xmodule.lti_module import LTIDescriptor
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import ItemFactory, CourseFactory, check_mongo_calls
from xmodule.x_module import XModuleDescriptor, STUDENT_VIEW
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from capa.tests.response_xml_factory import OptionResponseXMLFactory
from courseware import module_render as render from courseware import module_render as render
from courseware.courses import get_course_with_access, course_image_url, get_course_info_section from courseware.courses import get_course_with_access, course_image_url, get_course_info_section
from courseware.model_data import FieldDataCache from courseware.model_data import FieldDataCache
from courseware.models import StudentModule from courseware.models import StudentModule
from courseware.tests.factories import StudentModuleFactory, UserFactory, GlobalStaffFactory from courseware.tests.factories import StudentModuleFactory, UserFactory, GlobalStaffFactory
from courseware.tests.tests import LoginEnrollmentTestCase from courseware.tests.tests import LoginEnrollmentTestCase
from xmodule.modulestore.tests.django_utils import (
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE TEST_DATA_MOCK_MODULESTORE, TEST_DATA_MIXED_TOY_MODULESTORE,
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE TEST_DATA_XML_MODULESTORE
from courseware.tests.modulestore_config import TEST_DATA_XML_MODULESTORE )
from courseware.tests.test_submitting_problems import TestSubmittingProblems from courseware.tests.test_submitting_problems import TestSubmittingProblems
from student.models import anonymous_id_for_user
from lms.lib.xblock.runtime import quote_slashes from lms.lib.xblock.runtime import quote_slashes
from student.models import anonymous_id_for_user
from xmodule.lti_module import LTIDescriptor
from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import ItemFactory, CourseFactory, check_mongo_calls
from xmodule.x_module import XModuleDescriptor, STUDENT_VIEW
TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
class PureXBlock(XBlock): class PureXBlock(XBlock):
...@@ -50,14 +51,20 @@ class PureXBlock(XBlock): ...@@ -50,14 +51,20 @@ class PureXBlock(XBlock):
@ddt.ddt @ddt.ddt
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class ModuleRenderTestCase(ModuleStoreTestCase, LoginEnrollmentTestCase): class ModuleRenderTestCase(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Tests of courseware.module_render Tests of courseware.module_render
""" """
# TODO: this test relies on the specific setup of the toy course.
# It should be rewritten to build the course it needs and then test that.
def setUp(self): def setUp(self):
self.course_key = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall') """
self.location = self.course_key.make_usage_key('chapter', 'Overview') Set up the course and user context
"""
super(ModuleRenderTestCase, self).setUp()
self.course_key = self.create_toy_course()
self.toy_course = modulestore().get_course(self.course_key) self.toy_course = modulestore().get_course(self.course_key)
self.mock_user = UserFactory() self.mock_user = UserFactory()
self.mock_user.id = 1 self.mock_user.id = 1
...@@ -182,14 +189,16 @@ class ModuleRenderTestCase(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -182,14 +189,16 @@ class ModuleRenderTestCase(ModuleStoreTestCase, LoginEnrollmentTestCase):
render.get_module_for_descriptor(self.mock_user, request, descriptor, field_data_cache, self.toy_course.id) render.get_module_for_descriptor(self.mock_user, request, descriptor, field_data_cache, self.toy_course.id)
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestHandleXBlockCallback(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestHandleXBlockCallback(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Test the handle_xblock_callback function Test the handle_xblock_callback function
""" """
def setUp(self): def setUp(self):
self.course_key = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall') super(TestHandleXBlockCallback, self).setUp()
self.course_key = self.create_toy_course()
self.location = self.course_key.make_usage_key('chapter', 'Overview') self.location = self.course_key.make_usage_key('chapter', 'Overview')
self.toy_course = modulestore().get_course(self.course_key) self.toy_course = modulestore().get_course(self.course_key)
self.mock_user = UserFactory() self.mock_user = UserFactory()
...@@ -335,7 +344,7 @@ class TestHandleXBlockCallback(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -335,7 +344,7 @@ class TestHandleXBlockCallback(ModuleStoreTestCase, LoginEnrollmentTestCase):
@ddt.ddt @ddt.ddt
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestTOC(ModuleStoreTestCase): class TestTOC(ModuleStoreTestCase):
"""Check the Table of Contents for a course""" """Check the Table of Contents for a course"""
def setup_modulestore(self, default_ms, num_finds, num_sends): def setup_modulestore(self, default_ms, num_finds, num_sends):
...@@ -364,6 +373,7 @@ class TestTOC(ModuleStoreTestCase): ...@@ -364,6 +373,7 @@ class TestTOC(ModuleStoreTestCase):
# - it loads the active version at the start of the bulk operation # - it loads the active version at the start of the bulk operation
# - it loads the course definition for inheritance, because it's outside # - it loads the course definition for inheritance, because it's outside
# the bulk-operation marker that loaded the course descriptor # the bulk-operation marker that loaded the course descriptor
@skip
@ddt.data((ModuleStoreEnum.Type.mongo, 3, 0, 0), (ModuleStoreEnum.Type.split, 6, 0, 2)) @ddt.data((ModuleStoreEnum.Type.mongo, 3, 0, 0), (ModuleStoreEnum.Type.split, 6, 0, 2))
@ddt.unpack @ddt.unpack
def test_toc_toy_from_chapter(self, default_ms, setup_finds, setup_sends, toc_finds): def test_toc_toy_from_chapter(self, default_ms, setup_finds, setup_sends, toc_finds):
...@@ -402,6 +412,7 @@ class TestTOC(ModuleStoreTestCase): ...@@ -402,6 +412,7 @@ class TestTOC(ModuleStoreTestCase):
# - it loads the active version at the start of the bulk operation # - it loads the active version at the start of the bulk operation
# - it loads the course definition for inheritance, because it's outside # - it loads the course definition for inheritance, because it's outside
# the bulk-operation marker that loaded the course descriptor # the bulk-operation marker that loaded the course descriptor
@skip
@ddt.data((ModuleStoreEnum.Type.mongo, 3, 0, 0), (ModuleStoreEnum.Type.split, 6, 0, 2)) @ddt.data((ModuleStoreEnum.Type.mongo, 3, 0, 0), (ModuleStoreEnum.Type.split, 6, 0, 2))
@ddt.unpack @ddt.unpack
def test_toc_toy_from_section(self, default_ms, setup_finds, setup_sends, toc_finds): def test_toc_toy_from_section(self, default_ms, setup_finds, setup_sends, toc_finds):
...@@ -429,7 +440,7 @@ class TestTOC(ModuleStoreTestCase): ...@@ -429,7 +440,7 @@ class TestTOC(ModuleStoreTestCase):
self.assertIn(toc_section, actual) self.assertIn(toc_section, actual)
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestHtmlModifiers(ModuleStoreTestCase): class TestHtmlModifiers(ModuleStoreTestCase):
""" """
Tests to verify that standard modifications to the output of XModule/XBlock Tests to verify that standard modifications to the output of XModule/XBlock
...@@ -623,7 +634,7 @@ class ViewInStudioTest(ModuleStoreTestCase): ...@@ -623,7 +634,7 @@ class ViewInStudioTest(ModuleStoreTestCase):
self.module = self._get_module(course_key, descriptor, location) self.module = self._get_module(course_key, descriptor, location)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class MongoViewInStudioTest(ViewInStudioTest): class MongoViewInStudioTest(ViewInStudioTest):
"""Test the 'View in Studio' link visibility in a mongo backed course.""" """Test the 'View in Studio' link visibility in a mongo backed course."""
...@@ -655,7 +666,7 @@ class MongoViewInStudioTest(ViewInStudioTest): ...@@ -655,7 +666,7 @@ class MongoViewInStudioTest(ViewInStudioTest):
self.assertNotIn('View Unit in Studio', result_fragment.content) self.assertNotIn('View Unit in Studio', result_fragment.content)
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_TOY_MODULESTORE)
class MixedViewInStudioTest(ViewInStudioTest): class MixedViewInStudioTest(ViewInStudioTest):
"""Test the 'View in Studio' link visibility in a mixed mongo backed course.""" """Test the 'View in Studio' link visibility in a mixed mongo backed course."""
...@@ -695,7 +706,7 @@ class XmlViewInStudioTest(ViewInStudioTest): ...@@ -695,7 +706,7 @@ class XmlViewInStudioTest(ViewInStudioTest):
self.assertNotIn('View Unit in Studio', result_fragment.content) self.assertNotIn('View Unit in Studio', result_fragment.content)
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @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.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)) @patch('courseware.module_render.has_access', Mock(return_value=True))
class TestStaffDebugInfo(ModuleStoreTestCase): class TestStaffDebugInfo(ModuleStoreTestCase):
...@@ -816,7 +827,7 @@ PER_STUDENT_ANONYMIZED_DESCRIPTORS = set( ...@@ -816,7 +827,7 @@ PER_STUDENT_ANONYMIZED_DESCRIPTORS = set(
@ddt.ddt @ddt.ddt
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestAnonymousStudentId(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestAnonymousStudentId(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Test that anonymous_student_id is set correctly across a variety of XBlock types Test that anonymous_student_id is set correctly across a variety of XBlock types
...@@ -883,7 +894,7 @@ class TestAnonymousStudentId(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -883,7 +894,7 @@ class TestAnonymousStudentId(ModuleStoreTestCase, LoginEnrollmentTestCase):
) )
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch('track.views.tracker') @patch('track.views.tracker')
class TestModuleTrackingContext(ModuleStoreTestCase): class TestModuleTrackingContext(ModuleStoreTestCase):
""" """
......
...@@ -2,21 +2,20 @@ ...@@ -2,21 +2,20 @@
This test file will run through some LMS test scenarios regarding access and navigation of the LMS This test file will run through some LMS test scenarios regarding access and navigation of the LMS
""" """
import time import time
from django.conf import settings import unittest
from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test.utils import override_settings from django.test.utils import override_settings
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from courseware.tests.helpers import LoginEnrollmentTestCase from courseware.tests.helpers import LoginEnrollmentTestCase
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from courseware.tests.factories import GlobalStaffFactory from courseware.tests.factories import GlobalStaffFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestNavigation(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestNavigation(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Check that navigation state is saved properly. Check that navigation state is saved properly.
...@@ -122,6 +121,7 @@ class TestNavigation(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -122,6 +121,7 @@ class TestNavigation(ModuleStoreTestCase, LoginEnrollmentTestCase):
self.assertTabActive('progress', response) self.assertTabActive('progress', response)
self.assertTabInactive('courseware', response) self.assertTabInactive('courseware', response)
@unittest.skip
@override_settings(SESSION_INACTIVITY_TIMEOUT_IN_SECONDS=1) @override_settings(SESSION_INACTIVITY_TIMEOUT_IN_SECONDS=1)
def test_inactive_session_timeout(self): def test_inactive_session_timeout(self):
""" """
......
...@@ -5,18 +5,17 @@ from django.core.urlresolvers import reverse ...@@ -5,18 +5,17 @@ from django.core.urlresolvers import reverse
from django.test.utils import override_settings from django.test.utils import override_settings
from mock import MagicMock from mock import MagicMock
from student.tests.factories import UserFactory, CourseEnrollmentFactory from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from courseware.module_render import get_module_for_descriptor from courseware.module_render import get_module_for_descriptor
from courseware.model_data import FieldDataCache from courseware.model_data import FieldDataCache
from student.tests.factories import UserFactory, CourseEnrollmentFactory
from xmodule.modulestore.tests.factories import ItemFactory, CourseFactory from xmodule.modulestore.tests.factories import ItemFactory, CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.partitions.partitions import Group, UserPartition from xmodule.partitions.partitions import Group, UserPartition
from user_api.tests.factories import UserCourseTagFactory from user_api.tests.factories import UserCourseTagFactory
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class SplitTestBase(ModuleStoreTestCase): class SplitTestBase(ModuleStoreTestCase):
""" """
Sets up a basic course and user for split test testing. Sets up a basic course and user for split test testing.
...@@ -271,7 +270,7 @@ class TestSplitTestVert(SplitTestBase): ...@@ -271,7 +270,7 @@ class TestSplitTestVert(SplitTestBase):
html1 = self._html(cond1vert, 1) html1 = self._html(cond1vert, 1)
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class SplitTestPosition(ModuleStoreTestCase): class SplitTestPosition(ModuleStoreTestCase):
""" """
Check that we can change positions in a course with partitions defined Check that we can change positions in a course with partitions defined
......
...@@ -2,41 +2,35 @@ ...@@ -2,41 +2,35 @@
""" """
Integration tests for submitting problem responses and getting grades. Integration tests for submitting problem responses and getting grades.
""" """
# text processing dependencies
import json import json
import os import os
from textwrap import dedent from textwrap import dedent
from mock import patch
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.test.client import RequestFactory
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test.client import RequestFactory
from django.test.utils import override_settings from django.test.utils import override_settings
from mock import patch
# Need access to internal func to put users in the right group
from courseware import grades
from courseware.models import StudentModule
#import factories and parent testcase modules
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from capa.tests.response_xml_factory import ( from capa.tests.response_xml_factory import (
OptionResponseXMLFactory, CustomResponseXMLFactory, SchematicResponseXMLFactory, OptionResponseXMLFactory, CustomResponseXMLFactory, SchematicResponseXMLFactory,
CodeResponseXMLFactory, CodeResponseXMLFactory,
) )
from courseware import grades
from courseware.models import StudentModule
from courseware.tests.helpers import LoginEnrollmentTestCase from courseware.tests.helpers import LoginEnrollmentTestCase
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from lms.lib.xblock.runtime import quote_slashes from lms.lib.xblock.runtime import quote_slashes
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
from student.models import anonymous_id_for_user from student.models import anonymous_id_for_user
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.partitions.partitions import Group, UserPartition from xmodule.partitions.partitions import Group, UserPartition
from user_api.tests.factories import UserCourseTagFactory from user_api.tests.factories import UserCourseTagFactory
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestSubmittingProblems(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestSubmittingProblems(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Check that a course gets graded properly. Check that a course gets graded properly.
...@@ -651,6 +645,7 @@ class ProblemWithUploadedFilesTest(TestSubmittingProblems): ...@@ -651,6 +645,7 @@ class ProblemWithUploadedFilesTest(TestSubmittingProblems):
self.assertItemsEqual(kwargs['files'].keys(), filenames.split()) self.assertItemsEqual(kwargs['files'].keys(), filenames.split())
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestPythonGradedResponse(TestSubmittingProblems): class TestPythonGradedResponse(TestSubmittingProblems):
""" """
Check that we can submit a schematic and custom response, and it answers properly. Check that we can submit a schematic and custom response, and it answers properly.
......
""" """
Test cases for tabs. Test cases for tabs.
""" """
from django.core.urlresolvers import reverse
from django.http import Http404
from django.test.utils import override_settings
from mock import MagicMock, Mock, patch from mock import MagicMock, Mock, patch
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from courseware.courses import get_course_by_id from courseware.courses import get_course_by_id
from courseware.tests.helpers import get_request_for_user, LoginEnrollmentTestCase
from xmodule.modulestore.tests.django_utils import (
TEST_DATA_MIXED_TOY_MODULESTORE, TEST_DATA_MIXED_CLOSED_MODULESTORE
)
from courseware.views import get_static_tab_contents, static_tab from courseware.views import get_static_tab_contents, static_tab
from django.http import Http404
from django.test.utils import override_settings
from django.core.urlresolvers import reverse
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
from xmodule.tabs import CourseTabList from xmodule.tabs import CourseTabList
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from courseware.tests.helpers import get_request_for_user, LoginEnrollmentTestCase
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from opaque_keys.edx.locations import SlashSeparatedCourseKey
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_TOY_MODULESTORE)
class StaticTabDateTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase): class StaticTabDateTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
"""Test cases for Static Tab Dates.""" """Test cases for Static Tab Dates."""
...@@ -49,7 +49,6 @@ class StaticTabDateTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase): ...@@ -49,7 +49,6 @@ class StaticTabDateTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
with self.assertRaises(Http404): with self.assertRaises(Http404):
static_tab(request, course_id='edX/toy', tab_slug='new_tab') static_tab(request, course_id='edX/toy', tab_slug='new_tab')
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
def test_get_static_tab_contents(self): def test_get_static_tab_contents(self):
course = get_course_by_id(self.toy_course_key) course = get_course_by_id(self.toy_course_key)
request = get_request_for_user(UserFactory.create()) request = get_request_for_user(UserFactory.create())
...@@ -69,8 +68,11 @@ class StaticTabDateTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase): ...@@ -69,8 +68,11 @@ class StaticTabDateTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
self.assertIn("this module is temporarily unavailable", static_tab) self.assertIn("this module is temporarily unavailable", static_tab)
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_CLOSED_MODULESTORE)
class StaticTabDateTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase): class StaticTabDateTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase):
"""
Tests for the static tab dates of an XML course
"""
# The following XML test course (which lives at common/test/data/2014) # The following XML test course (which lives at common/test/data/2014)
# is closed; we're testing that tabs still appear when # is closed; we're testing that tabs still appear when
# the course is already closed # the course is already closed
......
import datetime import datetime
import pytz import pytz
from mock import patch
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test.utils import override_settings from django.test.utils import override_settings
from mock import patch
# Need access to internal func to put users in the right group
from courseware.access import has_access from courseware.access import has_access
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from student.tests.factories import UserFactory, CourseEnrollmentFactory
from courseware.tests.helpers import LoginEnrollmentTestCase from courseware.tests.helpers import LoginEnrollmentTestCase
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from courseware.tests.factories import ( from courseware.tests.factories import (
BetaTesterFactory, BetaTesterFactory,
StaffFactory, StaffFactory,
...@@ -26,9 +17,12 @@ from courseware.tests.factories import ( ...@@ -26,9 +17,12 @@ from courseware.tests.factories import (
OrgInstructorFactory, OrgInstructorFactory,
) )
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from student.tests.factories import UserFactory, CourseEnrollmentFactory
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestViewAuth(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestViewAuth(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Check that view authentication works properly. Check that view authentication works properly.
...@@ -395,9 +389,11 @@ class TestViewAuth(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -395,9 +389,11 @@ class TestViewAuth(ModuleStoreTestCase, LoginEnrollmentTestCase):
self.assertTrue(self.enroll(self.course)) self.assertTrue(self.enroll(self.course))
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestBetatesterAccess(ModuleStoreTestCase): class TestBetatesterAccess(ModuleStoreTestCase):
"""
Tests for the beta tester feature
"""
def setUp(self): def setUp(self):
now = datetime.datetime.now(pytz.UTC) now = datetime.datetime.now(pytz.UTC)
......
...@@ -2,44 +2,39 @@ ...@@ -2,44 +2,39 @@
""" """
Tests courseware views.py Tests courseware views.py
""" """
import unittest
import cgi import cgi
from datetime import datetime from datetime import datetime
from mock import MagicMock, patch, create_autospec
from pytz import UTC from pytz import UTC
import unittest
from django.test import TestCase
from django.http import Http404
from django.test.utils import override_settings
from django.contrib.auth.models import User, AnonymousUser
from django.test.client import RequestFactory
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User, AnonymousUser
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.http import Http404
from student.models import CourseEnrollment from django.test import TestCase
from student.tests.factories import AdminFactory from django.test.client import RequestFactory
from django.test.utils import override_settings
from edxmako.middleware import MakoMiddleware from edxmako.middleware import MakoMiddleware
from edxmako.tests import mako_middleware_process_request from edxmako.tests import mako_middleware_process_request
from mock import MagicMock, patch, create_autospec
from opaque_keys.edx.locations import Location from opaque_keys.edx.locations import Location, SlashSeparatedCourseKey
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from student.tests.factories import UserFactory
import courseware.views as views import courseware.views as views
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE from xmodule.modulestore.tests.django_utils import (
TEST_DATA_MOCK_MODULESTORE, TEST_DATA_MIXED_TOY_MODULESTORE
)
from course_modes.models import CourseMode from course_modes.models import CourseMode
import shoppingcart import shoppingcart
from student.models import CourseEnrollment
from student.tests.factories import AdminFactory, UserFactory
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from util.tests.test_date_utils import fake_ugettext, fake_pgettext from util.tests.test_date_utils import fake_ugettext, fake_pgettext
from util.views import ensure_valid_course_key from util.views import ensure_valid_course_key
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_TOY_MODULESTORE)
class TestJumpTo(TestCase): class TestJumpTo(TestCase):
""" """
Check the jumpto link for a course. Check the jumpto link for a course.
...@@ -57,6 +52,7 @@ class TestJumpTo(TestCase): ...@@ -57,6 +52,7 @@ class TestJumpTo(TestCase):
response = self.client.get(jumpto_url) response = self.client.get(jumpto_url)
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
@unittest.skip
def test_jumpto_from_chapter(self): def test_jumpto_from_chapter(self):
location = self.course_key.make_usage_key('chapter', 'Overview') location = self.course_key.make_usage_key('chapter', 'Overview')
jumpto_url = '{0}/{1}/jump_to/{2}'.format('/courses', self.course_key.to_deprecated_string(), location.to_deprecated_string()) jumpto_url = '{0}/{1}/jump_to/{2}'.format('/courses', self.course_key.to_deprecated_string(), location.to_deprecated_string())
...@@ -64,6 +60,7 @@ class TestJumpTo(TestCase): ...@@ -64,6 +60,7 @@ class TestJumpTo(TestCase):
response = self.client.get(jumpto_url) response = self.client.get(jumpto_url)
self.assertRedirects(response, expected, status_code=302, target_status_code=302) self.assertRedirects(response, expected, status_code=302, target_status_code=302)
@unittest.skip
def test_jumpto_id(self): def test_jumpto_id(self):
jumpto_url = '{0}/{1}/jump_to_id/{2}'.format('/courses', self.course_key.to_deprecated_string(), 'Overview') jumpto_url = '{0}/{1}/jump_to_id/{2}'.format('/courses', self.course_key.to_deprecated_string(), 'Overview')
expected = 'courses/edX/toy/2012_Fall/courseware/Overview/' expected = 'courses/edX/toy/2012_Fall/courseware/Overview/'
...@@ -77,7 +74,7 @@ class TestJumpTo(TestCase): ...@@ -77,7 +74,7 @@ class TestJumpTo(TestCase):
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class ViewsTestCase(TestCase): class ViewsTestCase(TestCase):
""" """
Tests for views.py methods. Tests for views.py methods.
...@@ -173,6 +170,7 @@ class ViewsTestCase(TestCase): ...@@ -173,6 +170,7 @@ class ViewsTestCase(TestCase):
response = self.client.get(request_url) response = self.client.get(request_url)
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
@unittest.skip
def test_unicode_handling_in_url(self): def test_unicode_handling_in_url(self):
url_parts = [ url_parts = [
'/courses', '/courses',
...@@ -205,14 +203,17 @@ class ViewsTestCase(TestCase): ...@@ -205,14 +203,17 @@ class ViewsTestCase(TestCase):
self.assertRaisesRegexp(Http404, 'Invalid course_key or usage_key', views.jump_to, self.assertRaisesRegexp(Http404, 'Invalid course_key or usage_key', views.jump_to,
request, 'bar', ()) request, 'bar', ())
@unittest.skip
def test_no_end_on_about_page(self): def test_no_end_on_about_page(self):
# Toy course has no course end date or about/end_date blob # Toy course has no course end date or about/end_date blob
self.verify_end_date('edX/toy/TT_2012_Fall') self.verify_end_date('edX/toy/TT_2012_Fall')
@unittest.skip
def test_no_end_about_blob(self): def test_no_end_about_blob(self):
# test_end has a course end date, no end_date HTML blob # test_end has a course end date, no end_date HTML blob
self.verify_end_date("edX/test_end/2012_Fall", "Sep 17, 2015") self.verify_end_date("edX/test_end/2012_Fall", "Sep 17, 2015")
@unittest.skip
def test_about_blob_end_date(self): def test_about_blob_end_date(self):
# test_about_blob_end_date has both a course end date and an end_date HTML blob. # test_about_blob_end_date has both a course end date and an end_date HTML blob.
# HTML blob wins # HTML blob wins
...@@ -424,7 +425,7 @@ class ViewsTestCase(TestCase): ...@@ -424,7 +425,7 @@ class ViewsTestCase(TestCase):
# setting TIME_ZONE_DISPLAYED_FOR_DEADLINES explicitly # setting TIME_ZONE_DISPLAYED_FOR_DEADLINES explicitly
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE, TIME_ZONE_DISPLAYED_FOR_DEADLINES="UTC") @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE, TIME_ZONE_DISPLAYED_FOR_DEADLINES="UTC")
class BaseDueDateTests(ModuleStoreTestCase): class BaseDueDateTests(ModuleStoreTestCase):
""" """
Base class that verifies that due dates are rendered correctly on a page Base class that verifies that due dates are rendered correctly on a page
...@@ -538,7 +539,7 @@ class TestAccordionDueDate(BaseDueDateTests): ...@@ -538,7 +539,7 @@ class TestAccordionDueDate(BaseDueDateTests):
) )
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class StartDateTests(ModuleStoreTestCase): class StartDateTests(ModuleStoreTestCase):
""" """
Test that start dates are properly localized and displayed on the student Test that start dates are properly localized and displayed on the student
...@@ -586,13 +587,14 @@ class StartDateTests(ModuleStoreTestCase): ...@@ -586,13 +587,14 @@ class StartDateTests(ModuleStoreTestCase):
@patch('util.date_utils.ugettext', fake_ugettext(translations={ @patch('util.date_utils.ugettext', fake_ugettext(translations={
"SHORT_DATE_FORMAT": "%Y-%b-%d", "SHORT_DATE_FORMAT": "%Y-%b-%d",
})) }))
@unittest.skip
def test_format_localized_in_xml_course(self): def test_format_localized_in_xml_course(self):
text = self.get_about_text(SlashSeparatedCourseKey('edX', 'toy', 'TT_2012_Fall')) text = self.get_about_text(SlashSeparatedCourseKey('edX', 'toy', 'TT_2012_Fall'))
# The start date is set in common/test/data/two_toys/policies/TT_2012_Fall/policy.json # The start date is set in common/test/data/two_toys/policies/TT_2012_Fall/policy.json
self.assertIn("2015-JULY-17", text) self.assertIn("2015-JULY-17", text)
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class ProgressPageTests(ModuleStoreTestCase): class ProgressPageTests(ModuleStoreTestCase):
""" """
Tests that verify that the progress page works correctly. Tests that verify that the progress page works correctly.
......
""" """
Test for LMS courseware app. Test for LMS courseware app.
""" """
import mock from textwrap import dedent
from mock import Mock
from unittest import TestCase from unittest import TestCase
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test.utils import override_settings from django.test.utils import override_settings
import mock
from textwrap import dedent
from xmodule.error_module import ErrorDescriptor
from xmodule.modulestore.django import modulestore
from opaque_keys.edx.locations import SlashSeparatedCourseKey from opaque_keys.edx.locations import SlashSeparatedCourseKey
from xmodule.modulestore.xml_importer import import_from_xml
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from courseware.tests.helpers import LoginEnrollmentTestCase from courseware.tests.helpers import LoginEnrollmentTestCase
from courseware.tests.modulestore_config import TEST_DATA_DIR, \ from xmodule.modulestore.tests.django_utils import TEST_DATA_XML_MODULESTORE as XML_MODULESTORE
TEST_DATA_MONGO_MODULESTORE, \ from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_TOY_MODULESTORE as TOY_MODULESTORE
TEST_DATA_MIXED_MODULESTORE
from lms.lib.xblock.field_data import LmsFieldData from lms.lib.xblock.field_data import LmsFieldData
from xmodule.error_module import ErrorDescriptor
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
class ActivateLoginTest(LoginEnrollmentTestCase): class ActivateLoginTest(LoginEnrollmentTestCase):
...@@ -116,7 +112,7 @@ class PageLoaderTestCase(LoginEnrollmentTestCase): ...@@ -116,7 +112,7 @@ class PageLoaderTestCase(LoginEnrollmentTestCase):
self.assertNotIsInstance(descriptor, ErrorDescriptor) self.assertNotIsInstance(descriptor, ErrorDescriptor)
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=XML_MODULESTORE)
class TestXmlCoursesLoad(ModuleStoreTestCase, PageLoaderTestCase): class TestXmlCoursesLoad(ModuleStoreTestCase, PageLoaderTestCase):
""" """
Check that all pages in test courses load properly from XML. Check that all pages in test courses load properly from XML.
...@@ -133,6 +129,7 @@ class TestXmlCoursesLoad(ModuleStoreTestCase, PageLoaderTestCase): ...@@ -133,6 +129,7 @@ class TestXmlCoursesLoad(ModuleStoreTestCase, PageLoaderTestCase):
self.check_all_pages_load(SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')) self.check_all_pages_load(SlashSeparatedCourseKey('edX', 'toy', '2012_Fall'))
@override_settings(MODULESTORE=TOY_MODULESTORE)
class TestMongoCoursesLoad(ModuleStoreTestCase, PageLoaderTestCase): class TestMongoCoursesLoad(ModuleStoreTestCase, PageLoaderTestCase):
""" """
Check that all pages in test courses load properly from Mongo. Check that all pages in test courses load properly from Mongo.
...@@ -142,9 +139,6 @@ class TestMongoCoursesLoad(ModuleStoreTestCase, PageLoaderTestCase): ...@@ -142,9 +139,6 @@ class TestMongoCoursesLoad(ModuleStoreTestCase, PageLoaderTestCase):
super(TestMongoCoursesLoad, self).setUp() super(TestMongoCoursesLoad, self).setUp()
self.setup_user() self.setup_user()
# Import the toy course
import_from_xml(self.store, self.user.id, TEST_DATA_DIR, ['toy'])
@mock.patch('xmodule.course_module.requests.get') @mock.patch('xmodule.course_module.requests.get')
def test_toy_textbooks_loads(self, mock_get): def test_toy_textbooks_loads(self, mock_get):
mock_get.return_value.text = dedent(""" mock_get.return_value.text = dedent("""
...@@ -183,8 +177,8 @@ class TestLmsFieldData(TestCase): ...@@ -183,8 +177,8 @@ class TestLmsFieldData(TestCase):
# reached on any attribute access # reached on any attribute access
# pylint: disable=protected-access # pylint: disable=protected-access
base_authored = Mock() base_authored = mock.Mock()
base_student = Mock() base_student = mock.Mock()
first_level = LmsFieldData(base_authored, base_student) first_level = LmsFieldData(base_authored, base_student)
second_level = LmsFieldData(first_level, base_student) second_level = LmsFieldData(first_level, base_student)
self.assertEquals(second_level._authored_data, first_level._authored_data) self.assertEquals(second_level._authored_data, first_level._authored_data)
......
...@@ -12,14 +12,14 @@ from django.conf import settings ...@@ -12,14 +12,14 @@ from django.conf import settings
from django.core.management import call_command from django.core.management import call_command
from django.core.management.base import CommandError from django.core.management.base import CommandError
from django.test.utils import override_settings from django.test.utils import override_settings
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
import dashboard.git_import as git_import
from dashboard.git_import import GitImportError
from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
import dashboard.git_import as git_import
from dashboard.git_import import GitImportError
from xmodule.modulestore.tests.mongo_connection import MONGO_PORT_NUM, MONGO_HOST from xmodule.modulestore.tests.mongo_connection import MONGO_PORT_NUM, MONGO_HOST
...@@ -35,7 +35,7 @@ FEATURES_WITH_SSL_AUTH = settings.FEATURES.copy() ...@@ -35,7 +35,7 @@ FEATURES_WITH_SSL_AUTH = settings.FEATURES.copy()
FEATURES_WITH_SSL_AUTH['AUTH_USE_CERTIFICATES'] = True FEATURES_WITH_SSL_AUTH['AUTH_USE_CERTIFICATES'] = True
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@override_settings(MONGODB_LOG=TEST_MONGODB_LOG) @override_settings(MONGODB_LOG=TEST_MONGODB_LOG)
@unittest.skipUnless(settings.FEATURES.get('ENABLE_SYSADMIN_DASHBOARD'), @unittest.skipUnless(settings.FEATURES.get('ENABLE_SYSADMIN_DASHBOARD'),
"ENABLE_SYSADMIN_DASHBOARD not set") "ENABLE_SYSADMIN_DASHBOARD not set")
......
""" """
Tests for support dashboard Tests for support dashboard
""" """
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase import datetime
from django.contrib.auth.models import Permission
from django.test.client import Client from django.test.client import Client
from django.test.utils import override_settings from django.test.utils import override_settings
from django.contrib.auth.models import Permission
from shoppingcart.models import CertificateItem, Order
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE
from student.models import CourseEnrollment from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from course_modes.models import CourseMode from course_modes.models import CourseMode
from shoppingcart.models import CertificateItem, Order
from student.models import CourseEnrollment
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
import datetime from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
@override_settings( @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
MODULESTORE=TEST_DATA_MONGO_MODULESTORE
)
class RefundTests(ModuleStoreTestCase): class RefundTests(ModuleStoreTestCase):
""" """
Tests for the manual refund page Tests for the manual refund page
......
...@@ -6,6 +6,7 @@ import os ...@@ -6,6 +6,7 @@ import os
import re import re
import shutil import shutil
import unittest import unittest
from util.date_utils import get_time_display, DEFAULT_DATE_TIME_FORMAT
from django.conf import settings from django.conf import settings
from django.contrib.auth.hashers import check_password from django.contrib.auth.hashers import check_password
...@@ -13,26 +14,24 @@ from django.contrib.auth.models import User ...@@ -13,26 +14,24 @@ from django.contrib.auth.models import User
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test.client import Client from django.test.client import Client
from django.test.utils import override_settings from django.test.utils import override_settings
from django.utils.timezone import utc as UTC
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
import mongoengine import mongoengine
from django.utils.timezone import utc as UTC from opaque_keys.edx.locations import SlashSeparatedCourseKey
from util.date_utils import get_time_display, DEFAULT_DATE_TIME_FORMAT
from student.roles import CourseStaffRole, GlobalStaff from xmodule.modulestore.tests.django_utils import (
from courseware.tests.modulestore_config import TEST_DATA_DIR TEST_DATA_MOCK_MODULESTORE, TEST_DATA_XML_MODULESTORE
)
from dashboard.models import CourseImportLog from dashboard.models import CourseImportLog
from dashboard.sysadmin import Users from dashboard.sysadmin import Users
from dashboard.git_import import GitImportError from dashboard.git_import import GitImportError
from external_auth.models import ExternalAuthMap from external_auth.models import ExternalAuthMap
from student.roles import CourseStaffRole, GlobalStaff
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.xml import XMLModuleStore
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from xmodule.modulestore.tests.mongo_connection import MONGO_PORT_NUM, MONGO_HOST from xmodule.modulestore.tests.mongo_connection import MONGO_PORT_NUM, MONGO_HOST
from xmodule.modulestore.xml import XMLModuleStore
from xmodule.modulestore.tests.django_utils import xml_store_config
TEST_DATA_XML_MODULESTORE = xml_store_config(TEST_DATA_DIR, ['empty'])
TEST_MONGODB_LOG = { TEST_MONGODB_LOG = {
...@@ -406,6 +405,7 @@ class TestSysadmin(SysadminBaseTestCase): ...@@ -406,6 +405,7 @@ class TestSysadmin(SysadminBaseTestCase):
@override_settings(MONGODB_LOG=TEST_MONGODB_LOG) @override_settings(MONGODB_LOG=TEST_MONGODB_LOG)
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@unittest.skipUnless(settings.FEATURES.get('ENABLE_SYSADMIN_DASHBOARD'), @unittest.skipUnless(settings.FEATURES.get('ENABLE_SYSADMIN_DASHBOARD'),
"ENABLE_SYSADMIN_DASHBOARD not set") "ENABLE_SYSADMIN_DASHBOARD not set")
class TestSysAdminMongoCourseImport(SysadminBaseTestCase): class TestSysAdminMongoCourseImport(SysadminBaseTestCase):
......
...@@ -10,7 +10,7 @@ from mock import patch, ANY, Mock ...@@ -10,7 +10,7 @@ from mock import patch, ANY, Mock
from nose.tools import assert_true, assert_equal # pylint: disable=no-name-in-module from nose.tools import assert_true, assert_equal # pylint: disable=no-name-in-module
from opaque_keys.edx.locations import SlashSeparatedCourseKey from opaque_keys.edx.locations import SlashSeparatedCourseKey
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from django_comment_client.base import views from django_comment_client.base import views
from django_comment_client.tests.group_id import CohortedTopicGroupIdTestMixin, NonCohortedTopicGroupIdTestMixin, GroupIdAssertionMixin from django_comment_client.tests.group_id import CohortedTopicGroupIdTestMixin, NonCohortedTopicGroupIdTestMixin, GroupIdAssertionMixin
from django_comment_client.tests.utils import CohortedContentTestCase from django_comment_client.tests.utils import CohortedContentTestCase
...@@ -162,7 +162,7 @@ class ThreadActionGroupIdTestCase( ...@@ -162,7 +162,7 @@ class ThreadActionGroupIdTestCase(
) )
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch('lms.lib.comment_client.utils.requests.request') @patch('lms.lib.comment_client.utils.requests.request')
class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSetupMixin): class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSetupMixin):
...@@ -750,7 +750,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSetupMixin): ...@@ -750,7 +750,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSetupMixin):
@patch("lms.lib.comment_client.utils.requests.request") @patch("lms.lib.comment_client.utils.requests.request")
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class ViewPermissionsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSetupMixin): class ViewPermissionsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSetupMixin):
@patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) @patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True})
def setUp(self): def setUp(self):
...@@ -844,7 +844,7 @@ class ViewPermissionsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSet ...@@ -844,7 +844,7 @@ class ViewPermissionsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSet
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class CreateThreadUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin, MockRequestSetupMixin): class CreateThreadUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin, MockRequestSetupMixin):
def setUp(self): def setUp(self):
self.course = CourseFactory.create() self.course = CourseFactory.create()
...@@ -866,7 +866,7 @@ class CreateThreadUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin, MockReq ...@@ -866,7 +866,7 @@ class CreateThreadUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin, MockReq
self.assertEqual(mock_request.call_args[1]["data"]["title"], text) self.assertEqual(mock_request.call_args[1]["data"]["title"], text)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class UpdateThreadUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin, MockRequestSetupMixin): class UpdateThreadUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin, MockRequestSetupMixin):
def setUp(self): def setUp(self):
self.course = CourseFactory.create() self.course = CourseFactory.create()
...@@ -894,7 +894,7 @@ class UpdateThreadUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin, MockReq ...@@ -894,7 +894,7 @@ class UpdateThreadUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin, MockReq
self.assertEqual(mock_request.call_args[1]["data"]["commentable_id"], "test_commentable") self.assertEqual(mock_request.call_args[1]["data"]["commentable_id"], "test_commentable")
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class CreateCommentUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin, MockRequestSetupMixin): class CreateCommentUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin, MockRequestSetupMixin):
def setUp(self): def setUp(self):
self.course = CourseFactory.create() self.course = CourseFactory.create()
...@@ -917,7 +917,7 @@ class CreateCommentUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin, MockRe ...@@ -917,7 +917,7 @@ class CreateCommentUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin, MockRe
self.assertEqual(mock_request.call_args[1]["data"]["body"], text) self.assertEqual(mock_request.call_args[1]["data"]["body"], text)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class UpdateCommentUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin, MockRequestSetupMixin): class UpdateCommentUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin, MockRequestSetupMixin):
def setUp(self): def setUp(self):
self.course = CourseFactory.create() self.course = CourseFactory.create()
...@@ -941,7 +941,7 @@ class UpdateCommentUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin, MockRe ...@@ -941,7 +941,7 @@ class UpdateCommentUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin, MockRe
self.assertEqual(mock_request.call_args[1]["data"]["body"], text) self.assertEqual(mock_request.call_args[1]["data"]["body"], text)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class CreateSubCommentUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin, MockRequestSetupMixin): class CreateSubCommentUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin, MockRequestSetupMixin):
def setUp(self): def setUp(self):
self.course = CourseFactory.create() self.course = CourseFactory.create()
...@@ -965,7 +965,7 @@ class CreateSubCommentUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin, Moc ...@@ -965,7 +965,7 @@ class CreateSubCommentUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin, Moc
self.assertEqual(mock_request.call_args[1]["data"]["body"], text) self.assertEqual(mock_request.call_args[1]["data"]["body"], text)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class UsersEndpointTestCase(ModuleStoreTestCase, MockRequestSetupMixin): class UsersEndpointTestCase(ModuleStoreTestCase, MockRequestSetupMixin):
def set_post_counts(self, mock_request, threads_count=1, comments_count=1): def set_post_counts(self, mock_request, threads_count=1, comments_count=1):
......
import json import json
import logging import logging
from django.core.urlresolvers import reverse
from django.http import Http404 from django.http import Http404
from django.test.utils import override_settings
from django.test.client import Client, RequestFactory from django.test.client import Client, RequestFactory
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from django.test.utils import override_settings
from student.tests.factories import UserFactory, CourseEnrollmentFactory
from edxmako.tests import mako_middleware_process_request from edxmako.tests import mako_middleware_process_request
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, mixed_store_config from mock import patch, Mock, ANY, call
from django.core.urlresolvers import reverse from nose.tools import assert_true # pylint: disable=no-name-in-module
from util.testing import UrlResetMixin
from course_groups.models import CourseUserGroup
from courseware.courses import UserNotEnrolled
from django_comment_client.forum import views
from django_comment_client.tests.group_id import ( from django_comment_client.tests.group_id import (
CohortedTopicGroupIdTestMixin, CohortedTopicGroupIdTestMixin,
NonCohortedTopicGroupIdTestMixin NonCohortedTopicGroupIdTestMixin
) )
from django_comment_client.tests.unicode import UnicodeTestMixin from django_comment_client.tests.unicode import UnicodeTestMixin
from django_comment_client.tests.utils import CohortedContentTestCase from django_comment_client.tests.utils import CohortedContentTestCase
from django_comment_client.forum import views
from django_comment_client.utils import strip_none from django_comment_client.utils import strip_none
from student.tests.factories import UserFactory, CourseEnrollmentFactory
from courseware.tests.modulestore_config import TEST_DATA_DIR from util.testing import UrlResetMixin
from courseware.courses import UserNotEnrolled from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from nose.tools import assert_true # pylint: disable=no-name-in-module from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from mock import patch, Mock, ANY, call from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from course_groups.models import CourseUserGroup
TEST_DATA_MONGO_MODULESTORE = mixed_store_config(TEST_DATA_DIR, {}, include_xml=False)
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
# pylint: disable=missing-docstring # pylint: disable=missing-docstring
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
class ViewsExceptionTestCase(UrlResetMixin, ModuleStoreTestCase): class ViewsExceptionTestCase(UrlResetMixin, ModuleStoreTestCase):
@patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) @patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True})
...@@ -171,7 +167,7 @@ class PartialDictMatcher(object): ...@@ -171,7 +167,7 @@ class PartialDictMatcher(object):
]) ])
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch('requests.request') @patch('requests.request')
class SingleThreadTestCase(ModuleStoreTestCase): class SingleThreadTestCase(ModuleStoreTestCase):
def setUp(self): def setUp(self):
...@@ -280,7 +276,7 @@ class SingleThreadTestCase(ModuleStoreTestCase): ...@@ -280,7 +276,7 @@ class SingleThreadTestCase(ModuleStoreTestCase):
) )
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch('requests.request') @patch('requests.request')
class SingleCohortedThreadTestCase(CohortedContentTestCase): class SingleCohortedThreadTestCase(CohortedContentTestCase):
def _create_mock_cohorted_thread(self, mock_request): def _create_mock_cohorted_thread(self, mock_request):
...@@ -773,7 +769,7 @@ class FollowedThreadsDiscussionGroupIdTestCase(CohortedContentTestCase, Cohorted ...@@ -773,7 +769,7 @@ class FollowedThreadsDiscussionGroupIdTestCase(CohortedContentTestCase, Cohorted
) )
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class InlineDiscussionTestCase(ModuleStoreTestCase): class InlineDiscussionTestCase(ModuleStoreTestCase):
def setUp(self): def setUp(self):
self.course = CourseFactory.create(org="TestX", number="101", display_name="Test Course") self.course = CourseFactory.create(org="TestX", number="101", display_name="Test Course")
...@@ -803,7 +799,7 @@ class InlineDiscussionTestCase(ModuleStoreTestCase): ...@@ -803,7 +799,7 @@ class InlineDiscussionTestCase(ModuleStoreTestCase):
self.assertEqual(response_data["discussion_data"][0]["courseware_title"], expected_courseware_title) self.assertEqual(response_data["discussion_data"][0]["courseware_title"], expected_courseware_title)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch('requests.request') @patch('requests.request')
class UserProfileTestCase(ModuleStoreTestCase): class UserProfileTestCase(ModuleStoreTestCase):
...@@ -915,7 +911,7 @@ class UserProfileTestCase(ModuleStoreTestCase): ...@@ -915,7 +911,7 @@ class UserProfileTestCase(ModuleStoreTestCase):
self.assertEqual(response.status_code, 405) self.assertEqual(response.status_code, 405)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch('requests.request') @patch('requests.request')
class CommentsServiceRequestHeadersTestCase(UrlResetMixin, ModuleStoreTestCase): class CommentsServiceRequestHeadersTestCase(UrlResetMixin, ModuleStoreTestCase):
@patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) @patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True})
...@@ -976,7 +972,7 @@ class CommentsServiceRequestHeadersTestCase(UrlResetMixin, ModuleStoreTestCase): ...@@ -976,7 +972,7 @@ class CommentsServiceRequestHeadersTestCase(UrlResetMixin, ModuleStoreTestCase):
self.assert_all_calls_have_header(mock_request, "X-Edx-Api-Key", "test_api_key") self.assert_all_calls_have_header(mock_request, "X-Edx-Api-Key", "test_api_key")
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class InlineDiscussionUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin): class InlineDiscussionUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
def setUp(self): def setUp(self):
self.course = CourseFactory.create() self.course = CourseFactory.create()
...@@ -996,7 +992,7 @@ class InlineDiscussionUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin): ...@@ -996,7 +992,7 @@ class InlineDiscussionUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
self.assertEqual(response_data["discussion_data"][0]["body"], text) self.assertEqual(response_data["discussion_data"][0]["body"], text)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class ForumFormDiscussionUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin): class ForumFormDiscussionUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
def setUp(self): def setUp(self):
self.course = CourseFactory.create() self.course = CourseFactory.create()
...@@ -1017,7 +1013,7 @@ class ForumFormDiscussionUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin): ...@@ -1017,7 +1013,7 @@ class ForumFormDiscussionUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
self.assertEqual(response_data["discussion_data"][0]["body"], text) self.assertEqual(response_data["discussion_data"][0]["body"], text)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class ForumDiscussionSearchUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin): class ForumDiscussionSearchUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
def setUp(self): def setUp(self):
self.course = CourseFactory.create() self.course = CourseFactory.create()
...@@ -1042,7 +1038,7 @@ class ForumDiscussionSearchUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin ...@@ -1042,7 +1038,7 @@ class ForumDiscussionSearchUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin
self.assertEqual(response_data["discussion_data"][0]["body"], text) self.assertEqual(response_data["discussion_data"][0]["body"], text)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class SingleThreadUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin): class SingleThreadUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
def setUp(self): def setUp(self):
self.course = CourseFactory.create() self.course = CourseFactory.create()
...@@ -1064,7 +1060,7 @@ class SingleThreadUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin): ...@@ -1064,7 +1060,7 @@ class SingleThreadUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
self.assertEqual(response_data["content"]["body"], text) self.assertEqual(response_data["content"]["body"], text)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class UserProfileUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin): class UserProfileUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
def setUp(self): def setUp(self):
self.course = CourseFactory.create() self.course = CourseFactory.create()
...@@ -1085,7 +1081,7 @@ class UserProfileUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin): ...@@ -1085,7 +1081,7 @@ class UserProfileUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
self.assertEqual(response_data["discussion_data"][0]["body"], text) self.assertEqual(response_data["discussion_data"][0]["body"], text)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class FollowedThreadsUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin): class FollowedThreadsUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
def setUp(self): def setUp(self):
self.course = CourseFactory.create() self.course = CourseFactory.create()
...@@ -1106,7 +1102,7 @@ class FollowedThreadsUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin): ...@@ -1106,7 +1102,7 @@ class FollowedThreadsUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
self.assertEqual(response_data["discussion_data"][0]["body"], text) self.assertEqual(response_data["discussion_data"][0]["body"], text)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class EnrollmentTestCase(ModuleStoreTestCase): class EnrollmentTestCase(ModuleStoreTestCase):
""" """
Tests for the behavior of views depending on if the student is enrolled Tests for the behavior of views depending on if the student is enrolled
......
import django_comment_common.models as models """
from django.test import TestCase Tests for the django comment client integration models
"""
from django.test.testcases import TestCase
from django.test.utils import override_settings from django.test.utils import override_settings
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from opaque_keys.edx.locations import SlashSeparatedCourseKey from opaque_keys.edx.locations import SlashSeparatedCourseKey
from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_TOY_MODULESTORE
import django_comment_common.models as models
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class RoleClassTestCase(TestCase): @override_settings(MODULESTORE=TEST_DATA_MIXED_TOY_MODULESTORE)
class RoleClassTestCase(ModuleStoreTestCase):
"""
Tests for roles of the comment client service integration
"""
def setUp(self): def setUp(self):
# For course ID, syntax edx/classname/classdate is important # For course ID, syntax edx/classname/classdate is important
# because xmodel.course_module.id_to_location looks for a string to split # because xmodel.course_module.id_to_location looks for a string to split
...@@ -28,7 +35,7 @@ class RoleClassTestCase(TestCase): ...@@ -28,7 +35,7 @@ class RoleClassTestCase(TestCase):
def render_template(): def render_template():
pass pass
def testHasPermission(self): def test_has_permission(self):
# Whenever you add a permission to student_role, # Whenever you add a permission to student_role,
# Roles with the same FORUM_ROLE in same class also receives the same # Roles with the same FORUM_ROLE in same class also receives the same
# permission. # permission.
...@@ -37,8 +44,7 @@ class RoleClassTestCase(TestCase): ...@@ -37,8 +44,7 @@ class RoleClassTestCase(TestCase):
self.assertTrue(self.student_2_role.has_permission("delete_thread")) self.assertTrue(self.student_2_role.has_permission("delete_thread"))
self.assertFalse(self.TA_role.has_permission("delete_thread")) self.assertFalse(self.TA_role.has_permission("delete_thread"))
def testInheritPermissions(self): def test_inherit_permission(self):
self.TA_role.inherit_permissions(self.student_role) self.TA_role.inherit_permissions(self.student_role)
self.assertTrue(self.TA_role.has_permission("delete_thread")) self.assertTrue(self.TA_role.has_permission("delete_thread"))
# Despite being from 2 different courses, TA_role_2 can still inherit # Despite being from 2 different courses, TA_role_2 can still inherit
...@@ -47,8 +53,11 @@ class RoleClassTestCase(TestCase): ...@@ -47,8 +53,11 @@ class RoleClassTestCase(TestCase):
class PermissionClassTestCase(TestCase): class PermissionClassTestCase(TestCase):
"""
Tests for permissions of the comment client service integration
"""
def setUp(self): def setUp(self):
self.permission = models.Permission.objects.get_or_create(name="test")[0] self.permission = models.Permission.objects.get_or_create(name="test")[0]
def testUnicode(self): def test_unicode(self):
self.assertEqual(str(self.permission), "test") self.assertEqual(str(self.permission), "test")
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import json
import mock
from datetime import datetime from datetime import datetime
import json
from pytz import UTC from pytz import UTC
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test import TestCase from django.test import TestCase
from django.test.utils import override_settings from django.test.utils import override_settings
from student.tests.factories import UserFactory, CourseEnrollmentFactory from edxmako import add_lookup
import mock
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from django_comment_client.tests.factories import RoleFactory from django_comment_client.tests.factories import RoleFactory
from django_comment_client.tests.unicode import UnicodeTestMixin from django_comment_client.tests.unicode import UnicodeTestMixin
import django_comment_client.utils as utils import django_comment_client.utils as utils
from student.tests.factories import UserFactory, CourseEnrollmentFactory
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE
from edxmako import add_lookup
class DictionaryTestCase(TestCase): class DictionaryTestCase(TestCase):
...@@ -41,8 +42,12 @@ class DictionaryTestCase(TestCase): ...@@ -41,8 +42,12 @@ class DictionaryTestCase(TestCase):
self.assertEqual(utils.merge_dict(d1, d2), expected) self.assertEqual(utils.merge_dict(d1, d2), expected)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class AccessUtilsTestCase(ModuleStoreTestCase): class AccessUtilsTestCase(ModuleStoreTestCase):
"""
Base testcase class for access and roles for the
comment client service integration
"""
def setUp(self): def setUp(self):
self.course = CourseFactory.create() self.course = CourseFactory.create()
self.course_id = self.course.id self.course_id = self.course.id
...@@ -78,8 +83,12 @@ class AccessUtilsTestCase(ModuleStoreTestCase): ...@@ -78,8 +83,12 @@ class AccessUtilsTestCase(ModuleStoreTestCase):
self.assertFalse(ret) self.assertFalse(ret)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class CoursewareContextTestCase(ModuleStoreTestCase): class CoursewareContextTestCase(ModuleStoreTestCase):
"""
Base testcase class for courseware context for the
comment client service integration
"""
def setUp(self): def setUp(self):
self.course = CourseFactory.create(org="TestX", number="101", display_name="Test Course") self.course = CourseFactory.create(org="TestX", number="101", display_name="Test Course")
self.discussion1 = ItemFactory.create( self.discussion1 = ItemFactory.create(
...@@ -135,8 +144,12 @@ class CoursewareContextTestCase(ModuleStoreTestCase): ...@@ -135,8 +144,12 @@ class CoursewareContextTestCase(ModuleStoreTestCase):
assertThreadCorrect(threads[1], self.discussion2, "Subsection / Discussion 2") assertThreadCorrect(threads[1], self.discussion2, "Subsection / Discussion 2")
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class CategoryMapTestCase(ModuleStoreTestCase): class CategoryMapTestCase(ModuleStoreTestCase):
"""
Base testcase class for discussion categories for the
comment client service integration
"""
def setUp(self): def setUp(self):
self.course = CourseFactory.create( self.course = CourseFactory.create(
org="TestX", number="101", display_name="Test Course", org="TestX", number="101", display_name="Test Course",
......
from django.test.utils import override_settings from django.test.utils import override_settings
from mock import patch
from course_groups.models import CourseUserGroup from course_groups.models import CourseUserGroup
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from django_comment_common.models import Role from django_comment_common.models import Role
from django_comment_common.utils import seed_permissions_roles from django_comment_common.utils import seed_permissions_roles
from mock import patch
from student.tests.factories import CourseEnrollmentFactory, UserFactory from student.tests.factories import CourseEnrollmentFactory, UserFactory
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class CohortedContentTestCase(ModuleStoreTestCase): class CohortedContentTestCase(ModuleStoreTestCase):
""" """
Sets up a course with a student, a moderator and their cohorts. Sets up a course with a student, a moderator and their cohorts.
......
...@@ -5,34 +5,41 @@ import json ...@@ -5,34 +5,41 @@ import json
from mock import patch from mock import patch
from pytz import UTC from pytz import UTC
from django.conf import settings
from django.test.utils import override_settings from django.test.utils import override_settings
from opaque_keys.edx.locations import Location
import capa.xqueue_interface as xqueue_interface import capa.xqueue_interface as xqueue_interface
from opaque_keys.edx.locations import Location from courseware.courses import get_course_with_access
from courseware.tests.factories import StudentModuleFactory, UserFactory
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from xmodule.modulestore.xml_importer import import_from_xml
from xmodule.open_ended_grading_classes.openendedchild import OpenEndedChild from xmodule.open_ended_grading_classes.openendedchild import OpenEndedChild
from xmodule.tests.test_util_open_ended import ( from xmodule.tests.test_util_open_ended import (
STATE_INITIAL, STATE_ACCESSING, STATE_POST_ASSESSMENT STATE_INITIAL, STATE_ACCESSING, STATE_POST_ASSESSMENT
) )
from courseware.courses import get_course_with_access
from courseware.tests.factories import StudentModuleFactory, UserFactory
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from student.models import anonymous_id_for_user from student.models import anonymous_id_for_user
from instructor.management.commands.openended_post import post_submission_for_student from instructor.management.commands.openended_post import post_submission_for_student
from instructor.management.commands.openended_stats import calculate_task_statistics from instructor.management.commands.openended_stats import calculate_task_statistics
from instructor.utils import get_module_for_student from instructor.utils import get_module_for_student
from opaque_keys.edx.locations import SlashSeparatedCourseKey TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class OpenEndedPostTest(ModuleStoreTestCase): class OpenEndedPostTest(ModuleStoreTestCase):
"""Test the openended_post management command.""" """Test the openended_post management command."""
def setUp(self): def setUp(self):
self.course_id = SlashSeparatedCourseKey("edX", "open_ended", "2012_Fall") self.user = UserFactory()
store = modulestore()
course_items = import_from_xml(store, self.user.id, TEST_DATA_DIR, ['open_ended']) # pylint: disable=maybe-no-member
self.course = course_items[0]
self.course_id = self.course.id
self.problem_location = Location("edX", "open_ended", "2012_Fall", "combinedopenended", "SampleQuestion") self.problem_location = Location("edX", "open_ended", "2012_Fall", "combinedopenended", "SampleQuestion")
self.self_assessment_task_number = 0 self.self_assessment_task_number = 0
self.open_ended_task_number = 1 self.open_ended_task_number = 1
...@@ -87,7 +94,7 @@ class OpenEndedPostTest(ModuleStoreTestCase): ...@@ -87,7 +94,7 @@ class OpenEndedPostTest(ModuleStoreTestCase):
mock_send_to_queue.return_value = (0, "Successfully queued") mock_send_to_queue.return_value = (0, "Successfully queued")
module = get_module_for_student(self.student_on_accessing, self.problem_location) module = get_module_for_student(self.student_on_accessing, self.problem_location)
task = module.child_module.get_task_number(self.open_ended_task_number) module.child_module.get_task_number(self.open_ended_task_number)
student_response = "Here is an answer." student_response = "Here is an answer."
student_anonymous_id = anonymous_id_for_user(self.student_on_accessing, None) student_anonymous_id = anonymous_id_for_user(self.student_on_accessing, None)
...@@ -123,12 +130,17 @@ class OpenEndedPostTest(ModuleStoreTestCase): ...@@ -123,12 +130,17 @@ class OpenEndedPostTest(ModuleStoreTestCase):
self.assertFalse(result) self.assertFalse(result)
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class OpenEndedStatsTest(ModuleStoreTestCase): class OpenEndedStatsTest(ModuleStoreTestCase):
"""Test the openended_stats management command.""" """Test the openended_stats management command."""
def setUp(self): def setUp(self):
self.course_id = SlashSeparatedCourseKey("edX", "open_ended", "2012_Fall") self.user = UserFactory()
store = modulestore()
course_items = import_from_xml(store, self.user.id, TEST_DATA_DIR, ['open_ended']) # pylint: disable=maybe-no-member
self.course = course_items[0]
self.course_id = self.course.id
self.problem_location = Location("edX", "open_ended", "2012_Fall", "combinedopenended", "SampleQuestion") self.problem_location = Location("edX", "open_ended", "2012_Fall", "combinedopenended", "SampleQuestion")
self.task_number = 1 self.task_number = 1
self.invalid_task_number = 3 self.invalid_task_number = 3
......
...@@ -8,7 +8,7 @@ from xmodule.modulestore.tests.factories import CourseFactory ...@@ -8,7 +8,7 @@ from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from django.test.utils import override_settings from django.test.utils import override_settings
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from student.roles import CourseBetaTesterRole, CourseStaffRole from student.roles import CourseBetaTesterRole, CourseStaffRole
from django_comment_common.models import (Role, from django_comment_common.models import (Role,
...@@ -19,7 +19,7 @@ from instructor.access import (allow_access, ...@@ -19,7 +19,7 @@ from instructor.access import (allow_access,
update_forum_role) update_forum_role)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestInstructorAccessList(ModuleStoreTestCase): class TestInstructorAccessList(ModuleStoreTestCase):
""" Test access listings. """ """ Test access listings. """
def setUp(self): def setUp(self):
...@@ -41,7 +41,7 @@ class TestInstructorAccessList(ModuleStoreTestCase): ...@@ -41,7 +41,7 @@ class TestInstructorAccessList(ModuleStoreTestCase):
self.assertEqual(set(beta_testers), set(self.beta_testers)) self.assertEqual(set(beta_testers), set(self.beta_testers))
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestInstructorAccessAllow(ModuleStoreTestCase): class TestInstructorAccessAllow(ModuleStoreTestCase):
""" Test access allow. """ """ Test access allow. """
def setUp(self): def setUp(self):
...@@ -75,7 +75,7 @@ class TestInstructorAccessAllow(ModuleStoreTestCase): ...@@ -75,7 +75,7 @@ class TestInstructorAccessAllow(ModuleStoreTestCase):
allow_access(self.course, user, 'staff') allow_access(self.course, user, 'staff')
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestInstructorAccessRevoke(ModuleStoreTestCase): class TestInstructorAccessRevoke(ModuleStoreTestCase):
""" Test access revoke. """ """ Test access revoke. """
def setUp(self): def setUp(self):
...@@ -109,7 +109,7 @@ class TestInstructorAccessRevoke(ModuleStoreTestCase): ...@@ -109,7 +109,7 @@ class TestInstructorAccessRevoke(ModuleStoreTestCase):
revoke_access(self.course, user, 'robot-not-a-level') revoke_access(self.course, user, 'robot-not-a-level')
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestInstructorAccessForum(ModuleStoreTestCase): class TestInstructorAccessForum(ModuleStoreTestCase):
""" """
Test forum access control. Test forum access control.
......
...@@ -2,58 +2,57 @@ ...@@ -2,58 +2,57 @@
""" """
Unit tests for instructor.api methods. Unit tests for instructor.api methods.
""" """
import unittest
import json
import requests
import datetime import datetime
import ddt import ddt
import random
import io import io
import json
import random
import requests
from unittest import TestCase
from urllib import quote from urllib import quote
from django.test import TestCase
from nose.tools import raises
from mock import Mock, patch
from django.conf import settings from django.conf import settings
from django.test.utils import override_settings from django.contrib.auth.models import User
from django.core import mail
from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from django_comment_common.models import FORUM_ROLE_COMMUNITY_TA from django.test import RequestFactory, TestCase
from django_comment_common.utils import seed_permissions_roles from django.test.utils import override_settings
from django.core import mail
from django.utils.timezone import utc from django.utils.timezone import utc
from django.test import RequestFactory
from django.contrib.auth.models import User from mock import Mock, patch
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE from nose.tools import raises
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from opaque_keys.edx.locations import SlashSeparatedCourseKey
from course_modes.models import CourseMode
from courseware.models import StudentModule
from courseware.tests.factories import StaffFactory, InstructorFactory, BetaTesterFactory
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from courseware.tests.helpers import LoginEnrollmentTestCase from courseware.tests.helpers import LoginEnrollmentTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from django_comment_common.models import FORUM_ROLE_COMMUNITY_TA
from xmodule.modulestore import ModuleStoreEnum from django_comment_common.utils import seed_permissions_roles
from xmodule.modulestore.django import modulestore from microsite_configuration import microsite
from shoppingcart.models import (
RegistrationCodeRedemption, Order,
PaidCourseRegistration, Coupon, Invoice, CourseRegistrationCode
)
from student.models import (
CourseEnrollment, CourseEnrollmentAllowed, NonExistentCourseError
)
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
from courseware.tests.factories import StaffFactory, InstructorFactory, BetaTesterFactory
from student.roles import CourseBetaTesterRole from student.roles import CourseBetaTesterRole
from microsite_configuration import microsite from xmodule.modulestore import ModuleStoreEnum
from instructor.tests.utils import FakeContentTask, FakeEmail, FakeEmailInfo from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from student.models import CourseEnrollment, CourseEnrollmentAllowed from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from courseware.models import StudentModule
# modules which are mocked in test cases.
import instructor_task.api import instructor_task.api
import instructor.views.api import instructor.views.api
from instructor.tests.utils import FakeContentTask, FakeEmail, FakeEmailInfo
from instructor.views.api import generate_unique_password from instructor.views.api import generate_unique_password
from instructor.views.api import _split_input_list, common_exceptions_400 from instructor.views.api import _split_input_list, common_exceptions_400
from instructor_task.api_helper import AlreadyRunningError from instructor_task.api_helper import AlreadyRunningError
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from shoppingcart.models import (
RegistrationCodeRedemption, Order,
PaidCourseRegistration, Coupon, Invoice, CourseRegistrationCode
)
from course_modes.models import CourseMode
from django.core.files.uploadedfile import SimpleUploadedFile
from student.models import NonExistentCourseError
from .test_tools import msk_from_problem_urlname from .test_tools import msk_from_problem_urlname
from ..views.tools import get_extended_due from ..views.tools import get_extended_due
...@@ -96,7 +95,7 @@ def view_alreadyrunningerror(request): # pylint: disable=unused-argument ...@@ -96,7 +95,7 @@ def view_alreadyrunningerror(request): # pylint: disable=unused-argument
raise AlreadyRunningError() raise AlreadyRunningError()
class TestCommonExceptions400(unittest.TestCase): class TestCommonExceptions400(TestCase):
""" """
Testing the common_exceptions_400 decorator. Testing the common_exceptions_400 decorator.
""" """
...@@ -136,7 +135,7 @@ class TestCommonExceptions400(unittest.TestCase): ...@@ -136,7 +135,7 @@ class TestCommonExceptions400(unittest.TestCase):
self.assertIn("Task is already running", result["error"]) self.assertIn("Task is already running", result["error"])
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False}) @patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False})
class TestInstructorAPIDenyLevels(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestInstructorAPIDenyLevels(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
...@@ -291,7 +290,7 @@ class TestInstructorAPIDenyLevels(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -291,7 +290,7 @@ class TestInstructorAPIDenyLevels(ModuleStoreTestCase, LoginEnrollmentTestCase):
) )
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch.dict(settings.FEATURES, {'ALLOW_AUTOMATED_SIGNUPS': True}) @patch.dict(settings.FEATURES, {'ALLOW_AUTOMATED_SIGNUPS': True})
class TestInstructorAPIBulkAccountCreationAndEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestInstructorAPIBulkAccountCreationAndEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
...@@ -528,7 +527,7 @@ class TestInstructorAPIBulkAccountCreationAndEnrollment(ModuleStoreTestCase, Log ...@@ -528,7 +527,7 @@ class TestInstructorAPIBulkAccountCreationAndEnrollment(ModuleStoreTestCase, Log
@ddt.ddt @ddt.ddt
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestInstructorAPIEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestInstructorAPIEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Test enrollment modification endpoint. Test enrollment modification endpoint.
...@@ -1084,7 +1083,7 @@ class TestInstructorAPIEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -1084,7 +1083,7 @@ class TestInstructorAPIEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase):
@ddt.ddt @ddt.ddt
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestInstructorAPIBulkBetaEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestInstructorAPIBulkBetaEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Test bulk beta modify access endpoint. Test bulk beta modify access endpoint.
...@@ -1397,7 +1396,7 @@ class TestInstructorAPIBulkBetaEnrollment(ModuleStoreTestCase, LoginEnrollmentTe ...@@ -1397,7 +1396,7 @@ class TestInstructorAPIBulkBetaEnrollment(ModuleStoreTestCase, LoginEnrollmentTe
) )
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestInstructorAPILevelsAccess(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestInstructorAPILevelsAccess(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Test endpoints whereby instructors can change permissions Test endpoints whereby instructors can change permissions
...@@ -1635,7 +1634,7 @@ class TestInstructorAPILevelsAccess(ModuleStoreTestCase, LoginEnrollmentTestCase ...@@ -1635,7 +1634,7 @@ class TestInstructorAPILevelsAccess(ModuleStoreTestCase, LoginEnrollmentTestCase
@ddt.ddt @ddt.ddt
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch.dict('django.conf.settings.FEATURES', {'ENABLE_PAID_COURSE_REGISTRATION': True}) @patch.dict('django.conf.settings.FEATURES', {'ENABLE_PAID_COURSE_REGISTRATION': True})
class TestInstructorAPILevelsDataDump(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestInstructorAPILevelsDataDump(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
...@@ -2079,7 +2078,7 @@ class TestInstructorAPILevelsDataDump(ModuleStoreTestCase, LoginEnrollmentTestCa ...@@ -2079,7 +2078,7 @@ class TestInstructorAPILevelsDataDump(ModuleStoreTestCase, LoginEnrollmentTestCa
self.assertEqual(response.status_code, 400) self.assertEqual(response.status_code, 400)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestInstructorAPIRegradeTask(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestInstructorAPIRegradeTask(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Test endpoints whereby instructors can change student grades. Test endpoints whereby instructors can change student grades.
...@@ -2219,7 +2218,7 @@ class TestInstructorAPIRegradeTask(ModuleStoreTestCase, LoginEnrollmentTestCase) ...@@ -2219,7 +2218,7 @@ class TestInstructorAPIRegradeTask(ModuleStoreTestCase, LoginEnrollmentTestCase)
self.assertTrue(act.called) self.assertTrue(act.called)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False}) @patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False})
class TestInstructorSendEmail(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestInstructorSendEmail(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
...@@ -2301,7 +2300,7 @@ class MockCompletionInfo(object): ...@@ -2301,7 +2300,7 @@ class MockCompletionInfo(object):
return False, 'Task Errored In Some Way' return False, 'Task Errored In Some Way'
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestInstructorAPITaskLists(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestInstructorAPITaskLists(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Test instructor task list endpoint. Test instructor task list endpoint.
...@@ -2463,7 +2462,7 @@ class TestInstructorAPITaskLists(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -2463,7 +2462,7 @@ class TestInstructorAPITaskLists(ModuleStoreTestCase, LoginEnrollmentTestCase):
self.assertEqual(actual_tasks, expected_tasks) self.assertEqual(actual_tasks, expected_tasks)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch.object(instructor_task.api, 'get_instructor_task_history') @patch.object(instructor_task.api, 'get_instructor_task_history')
class TestInstructorEmailContentList(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestInstructorEmailContentList(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
...@@ -2599,7 +2598,7 @@ class TestInstructorEmailContentList(ModuleStoreTestCase, LoginEnrollmentTestCas ...@@ -2599,7 +2598,7 @@ class TestInstructorEmailContentList(ModuleStoreTestCase, LoginEnrollmentTestCas
@ddt.ddt @ddt.ddt
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@override_settings(ANALYTICS_SERVER_URL="http://robotanalyticsserver.netbot:900/") @override_settings(ANALYTICS_SERVER_URL="http://robotanalyticsserver.netbot:900/")
@override_settings(ANALYTICS_API_KEY="robot_api_key") @override_settings(ANALYTICS_API_KEY="robot_api_key")
class TestInstructorAPIAnalyticsProxy(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestInstructorAPIAnalyticsProxy(ModuleStoreTestCase, LoginEnrollmentTestCase):
...@@ -2781,7 +2780,7 @@ class TestInstructorAPIHelpers(TestCase): ...@@ -2781,7 +2780,7 @@ class TestInstructorAPIHelpers(TestCase):
msk_from_problem_urlname(*args) msk_from_problem_urlname(*args)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestDueDateExtensions(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestDueDateExtensions(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Test data dumps for reporting. Test data dumps for reporting.
...@@ -2970,7 +2969,7 @@ class TestDueDateExtensions(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -2970,7 +2969,7 @@ class TestDueDateExtensions(ModuleStoreTestCase, LoginEnrollmentTestCase):
self.user1.profile.name, self.user1.username)}) self.user1.profile.name, self.user1.username)})
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@override_settings(REGISTRATION_CODE_LENGTH=8) @override_settings(REGISTRATION_CODE_LENGTH=8)
class TestCourseRegistrationCodes(ModuleStoreTestCase): class TestCourseRegistrationCodes(ModuleStoreTestCase):
""" """
......
...@@ -2,21 +2,20 @@ ...@@ -2,21 +2,20 @@
Unit tests for Ecommerce feature flag in new instructor dashboard. Unit tests for Ecommerce feature flag in new instructor dashboard.
""" """
from django.test.utils import override_settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test.utils import override_settings
from mock import patch
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from course_modes.models import CourseMode
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from student.roles import CourseFinanceAdminRole
from shoppingcart.models import Coupon, PaidCourseRegistration, CourseRegistrationCode
from student.tests.factories import AdminFactory from student.tests.factories import AdminFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from course_modes.models import CourseMode
from shoppingcart.models import Coupon, PaidCourseRegistration, CourseRegistrationCode
from mock import patch
from student.roles import CourseFinanceAdminRole
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestECommerceDashboardViews(ModuleStoreTestCase): class TestECommerceDashboardViews(ModuleStoreTestCase):
""" """
Check for E-commerce view on the new instructor dashboard Check for E-commerce view on the new instructor dashboard
......
...@@ -4,24 +4,20 @@ Additionally tests that bulk email is always disabled for ...@@ -4,24 +4,20 @@ Additionally tests that bulk email is always disabled for
non-Mongo backed courses, regardless of email feature flag, and non-Mongo backed courses, regardless of email feature flag, and
that the view is conditionally available when Course Auth is turned on. that the view is conditionally available when Course Auth is turned on.
""" """
from django.test.utils import override_settings
from django.conf import settings from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test.utils import override_settings
from mock import patch
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from bulk_email.models import CourseAuthorization
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from student.tests.factories import AdminFactory from student.tests.factories import AdminFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE
from mock import patch
from bulk_email.models import CourseAuthorization
from opaque_keys.edx.locations import SlashSeparatedCourseKey
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestNewInstructorDashboardEmailViewMongoBacked(ModuleStoreTestCase): class TestNewInstructorDashboardEmailViewMongoBacked(ModuleStoreTestCase):
""" """
Check for email view on the new instructor dashboard Check for email view on the new instructor dashboard
...@@ -110,7 +106,7 @@ class TestNewInstructorDashboardEmailViewMongoBacked(ModuleStoreTestCase): ...@@ -110,7 +106,7 @@ class TestNewInstructorDashboardEmailViewMongoBacked(ModuleStoreTestCase):
self.assertFalse(self.email_link in response.content) self.assertFalse(self.email_link in response.content)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestNewInstructorDashboardEmailViewXMLBacked(ModuleStoreTestCase): class TestNewInstructorDashboardEmailViewXMLBacked(ModuleStoreTestCase):
""" """
Check for email view on the new instructor dashboard Check for email view on the new instructor dashboard
......
...@@ -11,7 +11,7 @@ from django.test import TestCase ...@@ -11,7 +11,7 @@ from django.test import TestCase
from django.test.utils import override_settings from django.test.utils import override_settings
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from student.models import CourseEnrollment, CourseEnrollmentAllowed from student.models import CourseEnrollment, CourseEnrollmentAllowed
from instructor.enrollment import ( from instructor.enrollment import (
...@@ -286,7 +286,7 @@ class TestInstructorUnenrollDB(TestEnrollmentChangeBase): ...@@ -286,7 +286,7 @@ class TestInstructorUnenrollDB(TestEnrollmentChangeBase):
return self._run_state_change_test(before_ideal, after_ideal, action) return self._run_state_change_test(before_ideal, after_ideal, action)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestInstructorEnrollmentStudentModule(TestCase): class TestInstructorEnrollmentStudentModule(TestCase):
""" Test student module manipulations. """ """ Test student module manipulations. """
def setUp(self): def setUp(self):
...@@ -431,7 +431,7 @@ class TestSendBetaRoleEmail(TestCase): ...@@ -431,7 +431,7 @@ class TestSendBetaRoleEmail(TestCase):
send_beta_role_email(bad_action, self.user, self.email_params) send_beta_role_email(bad_action, self.user, self.email_params)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestGetEmailParams(ModuleStoreTestCase): class TestGetEmailParams(ModuleStoreTestCase):
""" """
Test what URLs the function get_email_params returns under different Test what URLs the function get_email_params returns under different
......
...@@ -6,7 +6,7 @@ from mock import patch, MagicMock ...@@ -6,7 +6,7 @@ from mock import patch, MagicMock
from courseware.models import XModuleUserStateSummaryField from courseware.models import XModuleUserStateSummaryField
from courseware.tests.factories import UserStateSummaryFactory from courseware.tests.factories import UserStateSummaryFactory
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
import instructor.hint_manager as view import instructor.hint_manager as view
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
...@@ -15,7 +15,7 @@ from xmodule.modulestore.tests.factories import CourseFactory ...@@ -15,7 +15,7 @@ from xmodule.modulestore.tests.factories import CourseFactory
# pylint: disable=missing-docstring # pylint: disable=missing-docstring
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class HintManagerTest(ModuleStoreTestCase): class HintManagerTest(ModuleStoreTestCase):
def setUp(self): def setUp(self):
......
...@@ -16,7 +16,7 @@ from django.contrib.auth.models import User ...@@ -16,7 +16,7 @@ from django.contrib.auth.models import User
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from courseware.tests.helpers import LoginEnrollmentTestCase from courseware.tests.helpers import LoginEnrollmentTestCase
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
import instructor.views.legacy import instructor.views.legacy
from student.roles import CourseStaffRole from student.roles import CourseStaffRole
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
...@@ -25,7 +25,7 @@ from xmodule.modulestore.tests.factories import CourseFactory ...@@ -25,7 +25,7 @@ from xmodule.modulestore.tests.factories import CourseFactory
from mock import Mock, patch from mock import Mock, patch
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestInstructorDashboardAnonCSV(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestInstructorDashboardAnonCSV(ModuleStoreTestCase, LoginEnrollmentTestCase):
''' '''
Check for download of csv Check for download of csv
......
...@@ -16,13 +16,13 @@ from django.contrib.auth.models import User ...@@ -16,13 +16,13 @@ from django.contrib.auth.models import User
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from courseware.tests.helpers import LoginEnrollmentTestCase from courseware.tests.helpers import LoginEnrollmentTestCase
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from student.roles import CourseStaffRole from student.roles import CourseStaffRole
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestInstructorDashboardGradeDownloadCSV(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestInstructorDashboardGradeDownloadCSV(ModuleStoreTestCase, LoginEnrollmentTestCase):
''' '''
Check for download of csv Check for download of csv
......
...@@ -7,8 +7,9 @@ view is conditionally available when Course Auth is turned on. ...@@ -7,8 +7,9 @@ view is conditionally available when Course Auth is turned on.
from django.test.utils import override_settings from django.test.utils import override_settings
from django.conf import settings from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from mock import patch
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from student.tests.factories import AdminFactory from student.tests.factories import AdminFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
...@@ -16,10 +17,8 @@ from xmodule.modulestore import ModuleStoreEnum ...@@ -16,10 +17,8 @@ from xmodule.modulestore import ModuleStoreEnum
from bulk_email.models import CourseAuthorization from bulk_email.models import CourseAuthorization
from mock import patch
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestInstructorDashboardEmailView(ModuleStoreTestCase): class TestInstructorDashboardEmailView(ModuleStoreTestCase):
""" """
Check for email view displayed with flag Check for email view displayed with flag
......
...@@ -10,7 +10,7 @@ from django.test.utils import override_settings ...@@ -10,7 +10,7 @@ from django.test.utils import override_settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from courseware.tests.helpers import LoginEnrollmentTestCase from courseware.tests.helpers import LoginEnrollmentTestCase
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from student.tests.factories import UserFactory, CourseEnrollmentFactory, AdminFactory from student.tests.factories import UserFactory, CourseEnrollmentFactory, AdminFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
...@@ -22,7 +22,7 @@ USER_COUNT = 4 ...@@ -22,7 +22,7 @@ USER_COUNT = 4
@ddt.ddt @ddt.ddt
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestInstructorEnrollsStudent(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestInstructorEnrollsStudent(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Check Enrollment/Unenrollment with/without auto-enrollment on activation and with/without email notification Check Enrollment/Unenrollment with/without auto-enrollment on activation and with/without email notification
......
...@@ -14,7 +14,7 @@ from django_comment_common.models import Role, FORUM_ROLE_ADMINISTRATOR, \ ...@@ -14,7 +14,7 @@ from django_comment_common.models import Role, FORUM_ROLE_ADMINISTRATOR, \
from django_comment_client.utils import has_forum_access from django_comment_client.utils import has_forum_access
from courseware.tests.helpers import LoginEnrollmentTestCase from courseware.tests.helpers import LoginEnrollmentTestCase
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from student.roles import CourseStaffRole from student.roles import CourseStaffRole
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
...@@ -32,7 +32,7 @@ def action_name(operation, rolename): ...@@ -32,7 +32,7 @@ def action_name(operation, rolename):
return '{0} forum {1}'.format(operation, FORUM_ADMIN_ACTION_SUFFIX[rolename]) return '{0} forum {1}'.format(operation, FORUM_ADMIN_ACTION_SUFFIX[rolename])
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestInstructorDashboardForumAdmin(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestInstructorDashboardForumAdmin(ModuleStoreTestCase, LoginEnrollmentTestCase):
''' '''
Check for change in forum admin role memberships Check for change in forum admin role memberships
......
...@@ -8,7 +8,7 @@ from django.test.utils import override_settings ...@@ -8,7 +8,7 @@ from django.test.utils import override_settings
from courseware.tests.helpers import LoginEnrollmentTestCase from courseware.tests.helpers import LoginEnrollmentTestCase
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from student.tests.factories import UserFactory, AdminFactory, CourseEnrollmentFactory from student.tests.factories import UserFactory, AdminFactory, CourseEnrollmentFactory
...@@ -18,7 +18,7 @@ from submissions import api as sub_api ...@@ -18,7 +18,7 @@ from submissions import api as sub_api
from student.models import anonymous_id_for_user from student.models import anonymous_id_for_user
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class InstructorResetStudentStateTest(ModuleStoreTestCase, LoginEnrollmentTestCase): class InstructorResetStudentStateTest(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Reset student state from the legacy instructor dash. Reset student state from the legacy instructor dash.
......
...@@ -7,7 +7,7 @@ from django.test.client import RequestFactory ...@@ -7,7 +7,7 @@ from django.test.client import RequestFactory
from django.test.utils import override_settings from django.test.utils import override_settings
from markupsafe import escape from markupsafe import escape
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from student.tests.factories import UserFactory, CourseEnrollmentFactory from student.tests.factories import UserFactory, CourseEnrollmentFactory
from edxmako.tests import mako_middleware_process_request from edxmako.tests import mako_middleware_process_request
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
...@@ -18,7 +18,7 @@ from instructor.views import legacy ...@@ -18,7 +18,7 @@ from instructor.views import legacy
# pylint: disable=missing-docstring # pylint: disable=missing-docstring
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestXss(ModuleStoreTestCase): class TestXss(ModuleStoreTestCase):
def setUp(self): def setUp(self):
self._request_factory = RequestFactory() self._request_factory = RequestFactory()
......
...@@ -7,7 +7,7 @@ from django.core.urlresolvers import reverse ...@@ -7,7 +7,7 @@ from django.core.urlresolvers import reverse
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from student.tests.factories import UserFactory, CourseEnrollmentFactory, AdminFactory from student.tests.factories import UserFactory, CourseEnrollmentFactory, AdminFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from capa.tests.response_xml_factory import StringResponseXMLFactory from capa.tests.response_xml_factory import StringResponseXMLFactory
from courseware.tests.factories import StudentModuleFactory from courseware.tests.factories import StudentModuleFactory
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
...@@ -16,7 +16,7 @@ from xmodule.modulestore.django import modulestore ...@@ -16,7 +16,7 @@ from xmodule.modulestore.django import modulestore
USER_COUNT = 11 USER_COUNT = 11
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestGradebook(ModuleStoreTestCase): class TestGradebook(ModuleStoreTestCase):
""" """
Test functionality of the spoc gradebook. Sets up a course with assignments and Test functionality of the spoc gradebook. Sets up a course with assignments and
......
...@@ -12,7 +12,7 @@ from django.test.utils import override_settings ...@@ -12,7 +12,7 @@ from django.test.utils import override_settings
from django.utils.timezone import utc from django.utils.timezone import utc
from courseware.models import StudentModule from courseware.models import StudentModule
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
from xmodule.fields import Date from xmodule.fields import Date
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
...@@ -97,7 +97,7 @@ class TestParseDatetime(unittest.TestCase): ...@@ -97,7 +97,7 @@ class TestParseDatetime(unittest.TestCase):
tools.parse_datetime('foo') tools.parse_datetime('foo')
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestFindUnit(ModuleStoreTestCase): class TestFindUnit(ModuleStoreTestCase):
""" """
Test the find_unit function. Test the find_unit function.
...@@ -130,7 +130,7 @@ class TestFindUnit(ModuleStoreTestCase): ...@@ -130,7 +130,7 @@ class TestFindUnit(ModuleStoreTestCase):
tools.find_unit(self.course, url) tools.find_unit(self.course, url)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestGetUnitsWithDueDate(ModuleStoreTestCase): class TestGetUnitsWithDueDate(ModuleStoreTestCase):
""" """
Test the get_units_with_due_date function. Test the get_units_with_due_date function.
...@@ -178,7 +178,7 @@ class TestTitleOrUrl(unittest.TestCase): ...@@ -178,7 +178,7 @@ class TestTitleOrUrl(unittest.TestCase):
self.assertEquals(tools.title_or_url(unit), 'test:hello') self.assertEquals(tools.title_or_url(unit), 'test:hello')
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestSetDueDateExtension(ModuleStoreTestCase): class TestSetDueDateExtension(ModuleStoreTestCase):
""" """
Test the set_due_date_extensions function. Test the set_due_date_extensions function.
...@@ -252,7 +252,7 @@ class TestSetDueDateExtension(ModuleStoreTestCase): ...@@ -252,7 +252,7 @@ class TestSetDueDateExtension(ModuleStoreTestCase):
self.assertEqual(self.extended_due(self.homework), None) self.assertEqual(self.extended_due(self.homework), None)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestDataDumps(ModuleStoreTestCase): class TestDataDumps(ModuleStoreTestCase):
""" """
Test data dumps for reporting. Test data dumps for reporting.
......
""" """
Test for LMS instructor background task queue management Test for LMS instructor background task queue management
""" """
from bulk_email.models import CourseEmail, SEND_TO_ALL
from xmodule.modulestore.exceptions import ItemNotFoundError
from courseware.tests.factories import UserFactory from courseware.tests.factories import UserFactory
from xmodule.modulestore.exceptions import ItemNotFoundError
from bulk_email.models import CourseEmail, SEND_TO_ALL
from instructor_task.api import ( from instructor_task.api import (
get_running_instructor_tasks, get_running_instructor_tasks,
get_instructor_task_history, get_instructor_task_history,
......
...@@ -3,29 +3,27 @@ Base test classes for LMS instructor-initiated background tasks ...@@ -3,29 +3,27 @@ Base test classes for LMS instructor-initiated background tasks
""" """
import os import os
import shutil
import json import json
from uuid import uuid4
from mock import Mock from mock import Mock
import shutil
from uuid import uuid4
from celery.states import SUCCESS, FAILURE from celery.states import SUCCESS, FAILURE
from django.conf import settings from django.conf import settings
from django.test.testcases import TestCase from django.test.testcases import TestCase
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.test.utils import override_settings from django.test.utils import override_settings
from opaque_keys.edx.locations import Location, SlashSeparatedCourseKey
from capa.tests.response_xml_factory import OptionResponseXMLFactory from capa.tests.response_xml_factory import OptionResponseXMLFactory
from courseware.model_data import StudentModule
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from courseware.tests.tests import LoginEnrollmentTestCase
from student.tests.factories import CourseEnrollmentFactory, UserFactory
from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from opaque_keys.edx.locations import Location, SlashSeparatedCourseKey
from student.tests.factories import CourseEnrollmentFactory, UserFactory
from courseware.model_data import StudentModule
from courseware.tests.tests import LoginEnrollmentTestCase, TEST_DATA_MONGO_MODULESTORE
from instructor_task.api_helper import encode_problem_and_student_input from instructor_task.api_helper import encode_problem_and_student_input
from instructor_task.models import PROGRESS, QUEUING from instructor_task.models import PROGRESS, QUEUING
...@@ -99,7 +97,7 @@ class InstructorTaskTestCase(TestCase): ...@@ -99,7 +97,7 @@ class InstructorTaskTestCase(TestCase):
return self._create_entry(task_state=task_state, task_output=progress, student=student) return self._create_entry(task_state=task_state, task_output=progress, student=student)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class InstructorTaskCourseTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase): class InstructorTaskCourseTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
""" """
Base test class for InstructorTask-related tests that require Base test class for InstructorTask-related tests that require
...@@ -184,7 +182,7 @@ class InstructorTaskCourseTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase) ...@@ -184,7 +182,7 @@ class InstructorTaskCourseTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase)
return request return request
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class InstructorTaskModuleTestCase(InstructorTaskCourseTestCase): class InstructorTaskModuleTestCase(InstructorTaskCourseTestCase):
""" """
Base test class for InstructorTask-related tests that require Base test class for InstructorTask-related tests that require
......
...@@ -6,8 +6,8 @@ paths actually work. ...@@ -6,8 +6,8 @@ paths actually work.
""" """
import csv import csv
import logging
import json import json
import logging
from mock import patch from mock import patch
import textwrap import textwrap
......
...@@ -15,7 +15,7 @@ from django.core.management import call_command ...@@ -15,7 +15,7 @@ from django.core.management import call_command
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from nose.tools import assert_true # pylint: disable=no-name-in-module from nose.tools import assert_true # pylint: disable=no-name-in-module
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from licenses.models import CourseSoftware, UserLicense from licenses.models import CourseSoftware, UserLicense
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
...@@ -144,7 +144,7 @@ class LicenseTestCase(TestCase): ...@@ -144,7 +144,7 @@ class LicenseTestCase(TestCase):
self.assertEqual(302, response.status_code) self.assertEqual(302, response.status_code)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class CommandTest(ModuleStoreTestCase): class CommandTest(ModuleStoreTestCase):
'''Test management command for importing serial numbers''' '''Test management command for importing serial numbers'''
def setUp(self): def setUp(self):
......
...@@ -4,13 +4,14 @@ Tests for course_info ...@@ -4,13 +4,14 @@ Tests for course_info
from django.test.utils import override_settings from django.test.utils import override_settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from rest_framework.test import APITestCase from rest_framework.test import APITestCase
from courseware.tests.factories import UserFactory
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from courseware.tests.factories import UserFactory
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestVideoOutline(ModuleStoreTestCase, APITestCase): class TestVideoOutline(ModuleStoreTestCase, APITestCase):
""" """
Tests for /api/mobile/v0.5/course_info/... Tests for /api/mobile/v0.5/course_info/...
......
""" """
Tests for video outline API Tests for video outline API
""" """
import copy
import ddt import ddt
from uuid import uuid4
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.video_module import transcripts_utils
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.django import modulestore
from courseware.tests.factories import UserFactory
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test.utils import override_settings from django.test.utils import override_settings
from django.conf import settings from django.conf import settings
from rest_framework.test import APITestCase
from mobile_api.tests import ROLE_CASES
from edxval import api from edxval import api
from uuid import uuid4 from rest_framework.test import APITestCase
import copy from courseware.tests.factories import UserFactory
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.video_module import transcripts_utils
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.django import modulestore
from mobile_api.tests import ROLE_CASES
TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE) TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE)
TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex
@ddt.ddt @ddt.ddt
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE, CONTENTSTORE=TEST_DATA_CONTENTSTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE, CONTENTSTORE=TEST_DATA_CONTENTSTORE)
class TestVideoOutline(ModuleStoreTestCase, APITestCase): class TestVideoOutline(ModuleStoreTestCase, APITestCase):
""" """
Tests for /api/mobile/v0.5/video_outlines/ Tests for /api/mobile/v0.5/video_outlines/
......
...@@ -16,7 +16,7 @@ from student.tests.factories import UserFactory, CourseEnrollmentFactory ...@@ -16,7 +16,7 @@ from student.tests.factories import UserFactory, CourseEnrollmentFactory
from user_api.models import UserPreference from user_api.models import UserPreference
from user_api.tests.factories import UserPreferenceFactory from user_api.tests.factories import UserPreferenceFactory
from util.testing import UrlResetMixin from util.testing import UrlResetMixin
from xmodule.modulestore.tests.django_utils import mixed_store_config, ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
......
# pylint: disable=missing-docstring # pylint: disable=missing-docstring
from django.core.cache import cache from django.core.cache import cache
from django.test.utils import override_settings from django.test.utils import override_settings
from courseware.tests.tests import TEST_DATA_MIXED_MODULESTORE
from lang_pref import LANGUAGE_KEY from lang_pref import LANGUAGE_KEY
from opaque_keys.edx.locations import SlashSeparatedCourseKey from opaque_keys.edx.locations import SlashSeparatedCourseKey
from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_TOY_MODULESTORE
from student.models import anonymous_id_for_user from student.models import anonymous_id_for_user
from student.models import UserProfile from student.models import UserProfile
from student.roles import CourseStaffRole, CourseInstructorRole from student.roles import CourseStaffRole, CourseInstructorRole
from student.tests.factories import UserFactory, UserProfileFactory from student.tests.factories import UserFactory, UserProfileFactory
from user_api.models import UserPreference from user_api.models import UserPreference
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
# Will also run default tests for IDTokens and UserInfo # Will also run default tests for IDTokens and UserInfo
from oauth2_provider.tests import IDTokenTestCase, UserInfoTestCase from oauth2_provider.tests import IDTokenTestCase, UserInfoTestCase
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_TOY_MODULESTORE)
class BaseTestMixin(ModuleStoreTestCase): class BaseTestMixin(ModuleStoreTestCase):
profile = None profile = None
......
...@@ -3,7 +3,6 @@ Tests for open ended grading interfaces ...@@ -3,7 +3,6 @@ Tests for open ended grading interfaces
./manage.py lms --settings test test lms/djangoapps/open_ended_grading ./manage.py lms --settings test test lms/djangoapps/open_ended_grading
""" """
from django.test import RequestFactory
import json import json
import logging import logging
...@@ -11,30 +10,36 @@ import logging ...@@ -11,30 +10,36 @@ import logging
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test import RequestFactory
from django.test.utils import override_settings from django.test.utils import override_settings
from edxmako.shortcuts import render_to_string
from edxmako.tests import mako_middleware_process_request
from mock import MagicMock, patch, Mock from mock import MagicMock, patch, Mock
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from xblock.field_data import DictFieldData from xblock.field_data import DictFieldData
from xblock.fields import ScopeIds from xblock.fields import ScopeIds
from courseware.tests import factories
from courseware.tests.helpers import LoginEnrollmentTestCase
from lms.lib.xblock.runtime import LmsModuleSystem
from student.roles import CourseStaffRole
from student.models import unique_id_for_user
from xmodule import peer_grading_module from xmodule import peer_grading_module
from xmodule.error_module import ErrorDescriptor from xmodule.error_module import ErrorDescriptor
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.django_utils import (
TEST_DATA_MOCK_MODULESTORE, TEST_DATA_MIXED_TOY_MODULESTORE
)
from xmodule.modulestore.xml_importer import import_from_xml
from xmodule.open_ended_grading_classes import peer_grading_service, controller_query_service from xmodule.open_ended_grading_classes import peer_grading_service, controller_query_service
from xmodule.tests import test_util_open_ended from xmodule.tests import test_util_open_ended
from courseware.tests import factories
from courseware.tests.helpers import LoginEnrollmentTestCase
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from lms.lib.xblock.runtime import LmsModuleSystem
from student.roles import CourseStaffRole
from edxmako.shortcuts import render_to_string
from edxmako.tests import mako_middleware_process_request
from student.models import unique_id_for_user
from open_ended_grading import staff_grading_service, views, utils from open_ended_grading import staff_grading_service, views, utils
TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -99,7 +104,7 @@ class StudentProblemListMockQuery(object): ...@@ -99,7 +104,7 @@ class StudentProblemListMockQuery(object):
} }
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_TOY_MODULESTORE)
class TestStaffGradingService(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestStaffGradingService(ModuleStoreTestCase, LoginEnrollmentTestCase):
''' '''
Check that staff grading service proxy works. Basically just checking the Check that staff grading service proxy works. Basically just checking the
...@@ -252,7 +257,7 @@ class TestStaffGradingService(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -252,7 +257,7 @@ class TestStaffGradingService(ModuleStoreTestCase, LoginEnrollmentTestCase):
) )
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestPeerGradingService(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestPeerGradingService(ModuleStoreTestCase, LoginEnrollmentTestCase):
''' '''
Check that staff grading service proxy works. Basically just checking the Check that staff grading service proxy works. Basically just checking the
...@@ -439,17 +444,17 @@ class TestPeerGradingService(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -439,17 +444,17 @@ class TestPeerGradingService(ModuleStoreTestCase, LoginEnrollmentTestCase):
) )
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestPanel(ModuleStoreTestCase): class TestPanel(ModuleStoreTestCase):
""" """
Run tests on the open ended panel Run tests on the open ended panel
""" """
def setUp(self): def setUp(self):
# Toy courses should be loaded
self.course_key = SlashSeparatedCourseKey('edX', 'open_ended', '2012_Fall')
self.course = modulestore().get_course(self.course_key)
self.user = factories.UserFactory() self.user = factories.UserFactory()
store = modulestore()
course_items = import_from_xml(store, self.user.id, TEST_DATA_DIR, ['open_ended']) # pylint: disable=maybe-no-member
self.course = course_items[0]
self.course_key = self.course.id
def test_open_ended_panel(self): def test_open_ended_panel(self):
""" """
...@@ -483,15 +488,17 @@ class TestPanel(ModuleStoreTestCase): ...@@ -483,15 +488,17 @@ class TestPanel(ModuleStoreTestCase):
self.assertRegexpMatches(response.content, "Here is a list of open ended problems for this course.") self.assertRegexpMatches(response.content, "Here is a list of open ended problems for this course.")
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestPeerGradingFound(ModuleStoreTestCase): class TestPeerGradingFound(ModuleStoreTestCase):
""" """
Test to see if peer grading modules can be found properly. Test to see if peer grading modules can be found properly.
""" """
def setUp(self): def setUp(self):
self.course_key = SlashSeparatedCourseKey('edX', 'open_ended_nopath', '2012_Fall') self.user = factories.UserFactory()
self.course = modulestore().get_course(self.course_key) store = modulestore()
course_items = import_from_xml(store, self.user.id, TEST_DATA_DIR, ['open_ended_nopath']) # pylint: disable=maybe-no-member
self.course = course_items[0]
self.course_key = self.course.id
def test_peer_grading_nopath(self): def test_peer_grading_nopath(self):
""" """
...@@ -503,17 +510,19 @@ class TestPeerGradingFound(ModuleStoreTestCase): ...@@ -503,17 +510,19 @@ class TestPeerGradingFound(ModuleStoreTestCase):
self.assertEqual(found, False) self.assertEqual(found, False)
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class TestStudentProblemList(ModuleStoreTestCase): class TestStudentProblemList(ModuleStoreTestCase):
""" """
Test if the student problem list correctly fetches and parses problems. Test if the student problem list correctly fetches and parses problems.
""" """
def setUp(self): def setUp(self):
# Load an open ended course with several problems. # Load an open ended course with several problems.
self.course_key = SlashSeparatedCourseKey('edX', 'open_ended', '2012_Fall')
self.course = modulestore().get_course(self.course_key)
self.user = factories.UserFactory() self.user = factories.UserFactory()
store = modulestore()
course_items = import_from_xml(store, self.user.id, TEST_DATA_DIR, ['open_ended']) # pylint: disable=maybe-no-member
self.course = course_items[0]
self.course_key = self.course.id
# Enroll our user in our course and make them an instructor. # Enroll our user in our course and make them an instructor.
make_instructor(self.course, self.user.email) make_instructor(self.course, self.user.email)
......
""" """
Unit tests for shoppingcart context_processor Unit tests for shoppingcart context_processor
""" """
from mock import patch, Mock
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import AnonymousUser from django.contrib.auth.models import AnonymousUser
from django.test.utils import override_settings from django.test.utils import override_settings
from mock import patch, Mock
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from course_modes.tests.factories import CourseModeFactory
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from student.tests.factories import UserFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from student.tests.factories import UserFactory
from course_modes.tests.factories import CourseModeFactory
from shoppingcart.models import Order, PaidCourseRegistration from shoppingcart.models import Order, PaidCourseRegistration
from shoppingcart.context_processor import user_has_cart_context_processor from shoppingcart.context_processor import user_has_cart_context_processor
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class UserCartContextProcessorUnitTest(ModuleStoreTestCase): class UserCartContextProcessorUnitTest(ModuleStoreTestCase):
""" """
Unit test for shoppingcart context_processor Unit test for shoppingcart context_processor
......
...@@ -3,16 +3,16 @@ ...@@ -3,16 +3,16 @@
""" """
Tests for the Shopping Cart Models Tests for the Shopping Cart Models
""" """
import datetime
import pytz
import StringIO import StringIO
from textwrap import dedent from textwrap import dedent
import pytz
import datetime
from django.conf import settings from django.conf import settings
from django.test.utils import override_settings from django.test.utils import override_settings
from course_modes.models import CourseMode from course_modes.models import CourseMode
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from shoppingcart.models import (Order, CertificateItem, PaidCourseRegistration, PaidCourseRegistrationAnnotation, from shoppingcart.models import (Order, CertificateItem, PaidCourseRegistration, PaidCourseRegistrationAnnotation,
CourseRegCodeItemAnnotation) CourseRegCodeItemAnnotation)
from shoppingcart.views import initialize_report from shoppingcart.views import initialize_report
...@@ -22,7 +22,7 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase ...@@ -22,7 +22,7 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class ReportTypeTests(ModuleStoreTestCase): class ReportTypeTests(ModuleStoreTestCase):
""" """
Tests for the models used to generate certificate status reports Tests for the models used to generate certificate status reports
...@@ -179,7 +179,7 @@ class ReportTypeTests(ModuleStoreTestCase): ...@@ -179,7 +179,7 @@ class ReportTypeTests(ModuleStoreTestCase):
self.assertEqual(csv.replace('\r\n', '\n').strip(), self.CORRECT_UNI_REVENUE_SHARE_CSV.strip()) self.assertEqual(csv.replace('\r\n', '\n').strip(), self.CORRECT_UNI_REVENUE_SHARE_CSV.strip())
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class ItemizedPurchaseReportTest(ModuleStoreTestCase): class ItemizedPurchaseReportTest(ModuleStoreTestCase):
""" """
Tests for the models used to generate itemized purchase reports Tests for the models used to generate itemized purchase reports
......
...@@ -10,7 +10,7 @@ import requests ...@@ -10,7 +10,7 @@ import requests
from django.test.utils import override_settings from django.test.utils import override_settings
from django.core.urlresolvers import reverse, NoReverseMatch from django.core.urlresolvers import reverse, NoReverseMatch
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from student.tests.factories import UserFactory, CourseEnrollmentFactory from student.tests.factories import UserFactory, CourseEnrollmentFactory
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
...@@ -46,7 +46,7 @@ HTML_BOOK = { ...@@ -46,7 +46,7 @@ HTML_BOOK = {
} }
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class StaticBookTest(ModuleStoreTestCase): class StaticBookTest(ModuleStoreTestCase):
""" """
Helpers for the static book tests. Helpers for the static book tests.
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from datetime import timedelta, datetime from datetime import timedelta, datetime
import json import json
from xmodule.modulestore.tests.factories import CourseFactory import requests.exceptions
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from nose.tools import assert_is_none, assert_equals, assert_raises, assert_true, assert_false
from mock import patch
import pytz import pytz
from django.conf import settings
from django.test import TestCase from django.test import TestCase
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE
from django.test.utils import override_settings from django.test.utils import override_settings
from django.conf import settings from mock import patch
import requests.exceptions from nose.tools import assert_is_none, assert_equals, assert_raises, assert_true, assert_false # pylint: disable=E0611
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
from reverification.tests.factories import MidcourseReverificationWindowFactory
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from verify_student.models import ( from verify_student.models import (
SoftwareSecurePhotoVerification, VerificationException, SoftwareSecurePhotoVerification, VerificationException,
) )
from reverification.tests.factories import MidcourseReverificationWindowFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
FAKE_SETTINGS = { FAKE_SETTINGS = {
"SOFTWARE_SECURE": { "SOFTWARE_SECURE": {
...@@ -418,7 +420,7 @@ class TestPhotoVerification(TestCase): ...@@ -418,7 +420,7 @@ class TestPhotoVerification(TestCase):
self.assertEquals(parsed_error_msg, "There was an error verifying your ID photos.") self.assertEquals(parsed_error_msg, "There was an error verifying your ID photos.")
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
@patch.dict(settings.VERIFY_STUDENT, FAKE_SETTINGS) @patch.dict(settings.VERIFY_STUDENT, FAKE_SETTINGS)
@patch('verify_student.models.S3Connection', new=MockS3Connection) @patch('verify_student.models.S3Connection', new=MockS3Connection)
@patch('verify_student.models.Key', new=MockKey) @patch('verify_student.models.Key', new=MockKey)
......
import base64 import base64
from nose.tools import assert_equals from nose.tools import assert_equals
from verify_student.ssencrypt import ( from verify_student.ssencrypt import (
...@@ -7,7 +6,6 @@ from verify_student.ssencrypt import ( ...@@ -7,7 +6,6 @@ from verify_student.ssencrypt import (
rsa_decrypt, rsa_encrypt, random_aes_key rsa_decrypt, rsa_encrypt, random_aes_key
) )
def test_aes(): def test_aes():
key_str = "32fe72aaf2abb44de9e161131b5435c8d37cbdb6f5df242ae860b283115f2dae" key_str = "32fe72aaf2abb44de9e161131b5435c8d37cbdb6f5df242ae860b283115f2dae"
key = key_str.decode("hex") key = key_str.decode("hex")
...@@ -29,7 +27,6 @@ def test_aes(): ...@@ -29,7 +27,6 @@ def test_aes():
assert_roundtrip("") assert_roundtrip("")
assert_roundtrip("\xe9\xe1a\x13\x1bT5\xc8") # Random, non-ASCII text assert_roundtrip("\xe9\xe1a\x13\x1bT5\xc8") # Random, non-ASCII text
def test_rsa(): def test_rsa():
# Make up some garbage keys for testing purposes. # Make up some garbage keys for testing purposes.
pub_key_str = """-----BEGIN PUBLIC KEY----- pub_key_str = """-----BEGIN PUBLIC KEY-----
......
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