Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions cms/djangoapps/contentstore/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@
'''
Utilities for contentstore tests
'''

import json

from django.test.client import Client
from django.conf import settings
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.modulestore import ModuleStoreEnum
from xmodule.modulestore.inheritance import own_metadata
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.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

Expand Down Expand Up @@ -66,7 +67,12 @@ def get_json(self, path, data=None, follow=False, **extra):
return self.get(path, data or {}, follow, HTTP_ACCEPT="application/json", **extra)


@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review note: This will make sure that the studio tests use the lightest weight modulestore by default. The studio testcases rely on this CourseTestCase class rather than ModuleStoreTestCase directly.

class CourseTestCase(ModuleStoreTestCase):
"""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks SO much for the doc. I had wanted to docstring this and other classes before but didn't understand them enough to describe them. Very useful to have doc!

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):
"""
These tests need a user in the DB so that the django Test Client can log them in.
Expand Down
32 changes: 13 additions & 19 deletions common/djangoapps/course_groups/tests/test_cohorts.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
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

from django.test import TestCase
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 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 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
# 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):
class TestCohortSignals(TestCase):
def setUp(self):
self.course_key = SlashSeparatedCourseKey("dummy", "dummy", "dummy")

Expand Down Expand Up @@ -123,9 +115,11 @@ def assert_events(event_name_suffix, user_list, cohort_list):
self.assertFalse(mock_tracker.emit.called)


@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestCohorts(django.test.TestCase):

@override_settings(MODULESTORE=TEST_DATA_MIXED_TOY_MODULESTORE)
class TestCohorts(TestCase):
"""
Test the cohorts feature
"""
def setUp(self):
"""
Make sure that course is reloaded every time--clear out the modulestore.
Expand Down
28 changes: 17 additions & 11 deletions common/djangoapps/course_groups/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
"""
Tests for course group views
"""
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 xmodule.modulestore.tests.django_utils 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 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):
"""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 xmodule.modulestore.tests.django_utils 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 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: either combine this or move it up a few lines to be under the other 'from xmodule.modulstore.tests.django_utils'

from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
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 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):
"""
Tests of CountryMiddleware.
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 xmodule.modulestore.tests.django_utils 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
22 changes: 12 additions & 10 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,27 @@
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 student.tests.factories import UserFactory, CourseEnrollmentFactory
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 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
# This import is for an lms djangoapp.
# Its testcases are only run under lms.
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')
class TestStudentDashboardEmailView(ModuleStoreTestCase):
"""
Expand Down Expand Up @@ -88,7 +90,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 xmodule.modulestore.tests.django_utils 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