Skip to content

Commit

Permalink
Clean up all modulestore testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Zoldak committed Nov 26, 2014
1 parent 667e27c commit 51c9f38
Show file tree
Hide file tree
Showing 86 changed files with 636 additions and 664 deletions.
24 changes: 8 additions & 16 deletions common/djangoapps/course_groups/tests/test_cohorts.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
import django.test
from django.contrib.auth.models import User
from django.conf import settings
from django.contrib.auth.models import User
from django.http import Http404

import django.test
from django.test.utils import override_settings
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.models import CourseUserGroup
from course_groups.tests.helpers import topic_name_to_id, config_course_cohorts, CohortFactory

from courseware.tests.modulestore_config import TEST_DATA_MIXED_TOY_MODULESTORE
from student.models import CourseEnrollment
from student.tests.factories import UserFactory
from xmodule.modulestore.django import modulestore, clear_existing_modulestores
from opaque_keys.edx.locations import SlashSeparatedCourseKey

from xmodule.modulestore.tests.django_utils import mixed_store_config

# NOTE: running this with the lms.envs.test config works without
# manually overriding the modulestore. However, running with
# 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")
class TestCohortSignals(django.test.TestCase):
def setUp(self):
Expand Down Expand Up @@ -123,7 +115,7 @@ def assert_events(event_name_suffix, user_list, cohort_list):
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):

def setUp(self):
Expand Down
25 changes: 14 additions & 11 deletions common/djangoapps/course_groups/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
from collections import namedtuple
import json

from django.contrib.auth.models import User
from django.http import Http404
from django.test.client import RequestFactory
from django.test.utils import override_settings
from course_groups.tests.helpers import config_course_cohorts, CohortFactory
from collections import namedtuple
from opaque_keys.edx.locations import SlashSeparatedCourseKey

from django.http import Http404
from django.contrib.auth.models import User
from courseware.tests.tests import TEST_DATA_MIXED_MODULESTORE
from course_groups.cohorts import (
get_cohort, CohortAssignmentType, get_cohort_by_name, DEFAULT_COHORT_NAME
)
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 courseware.tests.modulestore_config import TEST_DATA_MOCK_MODULESTORE
from student.models import CourseEnrollment
from student.tests.factories import UserFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
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):
"""
Base class which sets up a course and staff/non-staff users.
Expand Down
4 changes: 2 additions & 2 deletions common/djangoapps/embargo/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

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_MOCK_MODULESTORE


@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)
class EmbargoCourseFormTest(ModuleStoreTestCase):
"""Test the course form properly validates course IDs"""

Expand Down
26 changes: 12 additions & 14 deletions common/djangoapps/external_auth/tests/test_shib.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
@jbau
"""
import unittest
from mock import patch
from ddt import ddt, data

from ddt import ddt, data
from django.conf import settings
from django.http import HttpResponseRedirect
from django.test import TestCase
Expand All @@ -15,22 +14,21 @@
from django.core.urlresolvers import reverse
from django.contrib.auth.models import AnonymousUser, User
from django.utils.importlib import import_module

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 edxmako.tests import mako_middleware_process_request
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 courseware.tests.modulestore_config import TEST_DATA_MOCK_MODULESTORE
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 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'
# attributes via request.META. We can count on 'Shib-Identity-Provider', and 'REMOTE_USER' being present
Expand Down Expand Up @@ -75,7 +73,7 @@ def _build_identity_dict(mail, display_name, given_name, surname):


@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):
"""
Tests for the Shibboleth SP, which communicates via request.META
Expand Down
16 changes: 6 additions & 10 deletions common/djangoapps/external_auth/tests/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Provides unit tests for SSL based authentication portions
of the external_auth app.
"""

import unittest

from django.conf import settings
Expand All @@ -13,17 +12,16 @@
from django.test.client import Client
from django.test.client import RequestFactory
from django.test.utils import override_settings
from mock import Mock

import external_auth.views
from edxmako.middleware import MakoMiddleware
from external_auth.models import ExternalAuthMap
from opaque_keys import InvalidKeyError
import external_auth.views
from mock import Mock

from courseware.tests.modulestore_config import TEST_DATA_MOCK_MODULESTORE
from student.models import CourseEnrollment
from student.roles import CourseStaffRole
from student.tests.factories import UserFactory
from xmodule.modulestore.tests.django_utils import (ModuleStoreTestCase,
mixed_store_config)
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory

FEATURES_WITH_SSL_AUTH = settings.FEATURES.copy()
Expand All @@ -35,8 +33,6 @@
FEATURES_WITHOUT_SSL_AUTH = settings.FEATURES.copy()
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)
class SSLClientTest(ModuleStoreTestCase):
Expand Down Expand Up @@ -325,7 +321,7 @@ def test_ssl_decorator_auto_signup(self):

@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
@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):
"""
Auto signup auth user and ensure they return to the original
Expand Down
14 changes: 6 additions & 8 deletions common/djangoapps/geoinfo/tests/test_middleware.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
"""
Tests for CountryMiddleware.
"""

from mock import Mock, patch
from mock import patch
import pygeoip

from django.contrib.sessions.middleware import SessionMiddleware
from django.test import TestCase
from django.test.utils import override_settings
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 courseware.tests.modulestore_config 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):
"""
Tests of CountryMiddleware.
Expand Down
10 changes: 7 additions & 3 deletions common/djangoapps/heartbeat/tests/test_heartbeat.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"""
Test the heartbeat
"""
from django.test.client import Client
from django.core.urlresolvers import reverse
import json

from django.core.urlresolvers import reverse
from django.db.utils import DatabaseError
import mock
from django.test.client import Client
from django.test.testcases import TestCase
import mock
from nose.plugins.attrib import attr


class HeartbeatTestCase(TestCase):
Expand All @@ -26,6 +28,7 @@ def test_success(self):
response = self.client.get(self.heartbeat_url)
self.assertEqual(response.status_code, 200)

@attr('mongo')
def test_sql_fail(self):
with mock.patch('heartbeat.views.connection') as mock_connection:
mock_connection.cursor.return_value.execute.side_effect = DatabaseError
Expand All @@ -34,6 +37,7 @@ def test_sql_fail(self):
response_dict = json.loads(response.content)
self.assertIn('SQL', response_dict)

@attr('mongo')
def test_mongo_fail(self):
with mock.patch('pymongo.MongoClient.alive', return_value=False):
response = self.client.get(self.heartbeat_url)
Expand Down
4 changes: 2 additions & 2 deletions common/djangoapps/reverification/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
from django.core.exceptions import ValidationError
from django.test.utils import override_settings

from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE
from courseware.tests.modulestore_config import TEST_DATA_MOCK_MODULESTORE
from reverification.models import MidcourseReverificationWindow
from reverification.tests.factories import MidcourseReverificationWindowFactory
from xmodule.modulestore.tests.factories import CourseFactory
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):
""" Tests for MidcourseReverificationWindow objects """

Expand Down
20 changes: 9 additions & 11 deletions common/djangoapps/student/tests/test_bulk_email_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@
of email feature flag, and that the view is conditionally available when
Course Auth is turned on.
"""
import unittest

from django.test.utils import override_settings
from django.conf import settings
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 bulk_email.models import CourseAuthorization
from courseware.tests.modulestore_config import TEST_DATA_MOCK_MODULESTORE
from courseware.tests.modulestore_config import TEST_DATA_MIXED_TOY_MODULESTORE
from student.tests.factories import UserFactory, CourseEnrollmentFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
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

from mock import patch


@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')
class TestStudentDashboardEmailView(ModuleStoreTestCase):
"""
Expand Down Expand Up @@ -88,7 +86,7 @@ def test_email_authorized(self):
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')
class TestStudentDashboardEmailViewXMLBacked(ModuleStoreTestCase):
"""
Expand Down
17 changes: 7 additions & 10 deletions common/djangoapps/student/tests/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
'''
import json
import unittest
from mock import patch

from django.test import TestCase
from django.test.client import Client
Expand All @@ -12,23 +11,21 @@
from django.core.cache import cache
from django.core.urlresolvers import reverse, NoReverseMatch
from django.http import HttpResponseBadRequest, HttpResponse
from external_auth.models import ExternalAuthMap
import httpretty
from mock import patch
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from social.apps.django_app.default.models import UserSocialAuth

from courseware.tests.modulestore_config import TEST_DATA_MOCK_MODULESTORE
from student.tests.factories import UserFactory, RegistrationFactory, UserProfileFactory
from student.views import (
_parse_course_id_from_string,
_get_course_enrollment_domain,
login_oauth_token,
)

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 external_auth.models import ExternalAuthMap
from opaque_keys.edx.locations import SlashSeparatedCourseKey

TEST_DATA_MIXED_MODULESTORE = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {})
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase


class LoginTest(TestCase):
Expand Down Expand Up @@ -345,7 +342,7 @@ def test__parse_course_id_from_string(self):
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):
"""
Tests how login_user() interacts with ExternalAuth, in particular Shib
Expand Down
Loading

0 comments on commit 51c9f38

Please sign in to comment.