From bf3b87bc64725850b2bd84fecaf1994142f63f8e Mon Sep 17 00:00:00 2001 From: Jesse Zoldak Date: Tue, 25 Nov 2014 13:33:09 -0500 Subject: [PATCH 1/2] 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 --- cms/djangoapps/contentstore/tests/utils.py | 20 ++-- .../course_groups/tests/test_cohorts.py | 32 +++---- .../course_groups/tests/test_views.py | 28 +++--- common/djangoapps/embargo/tests/test_forms.py | 4 +- .../external_auth/tests/test_shib.py | 26 +++-- .../external_auth/tests/test_ssl.py | 16 ++-- .../geoinfo/tests/test_middleware.py | 14 ++- .../reverification/tests/test_models.py | 4 +- .../student/tests/test_bulk_email_settings.py | 22 +++-- common/djangoapps/student/tests/test_login.py | 17 ++-- common/djangoapps/student/tests/tests.py | 45 +++++---- .../xmodule/modulestore/tests/django_utils.py | 71 +++++++++++--- .../modulestore/tests/test_assetstore.py | 7 +- .../test_cross_modulestore_import_export.py | 10 +- .../tests/test_mixed_modulestore.py | 14 +-- .../xmodule/modulestore/tests/test_publish.py | 5 +- .../modulestore/tests/test_split_migrator.py | 6 +- .../tests/test_split_modulestore.py | 7 +- .../tests/test_split_w_old_mongo.py | 15 +-- lms/djangoapps/branding/tests.py | 15 ++- .../bulk_email/tests/test_course_optout.py | 7 +- lms/djangoapps/bulk_email/tests/test_email.py | 14 ++- .../bulk_email/tests/test_err_handling.py | 21 ++-- lms/djangoapps/bulk_email/tests/test_forms.py | 24 +++-- .../tests/test_dashboard_data.py | 13 +-- .../class_dashboard/tests/test_views.py | 13 ++- .../course_wiki/tests/test_access.py | 4 +- .../course_wiki/tests/test_middleware.py | 4 +- lms/djangoapps/course_wiki/tests/tests.py | 4 +- .../commands/tests/test_dump_course.py | 38 ++++---- lms/djangoapps/courseware/tests/__init__.py | 2 +- .../courseware/tests/modulestore_config.py | 31 ------ lms/djangoapps/courseware/tests/test_about.py | 48 +++++----- .../courseware/tests/test_access.py | 16 ++-- .../courseware/tests/test_course_info.py | 28 ++++-- .../courseware/tests/test_courses.py | 82 +++++++++++----- .../tests/test_draft_modulestore.py | 7 +- .../courseware/tests/test_grades.py | 9 +- lms/djangoapps/courseware/tests/test_i18n.py | 8 +- .../courseware/tests/test_lti_integration.py | 21 ++-- .../courseware/tests/test_masquerade.py | 19 ++-- .../courseware/tests/test_microsites.py | 13 ++- .../courseware/tests/test_middleware.py | 4 +- .../courseware/tests/test_module_render.py | 67 +++++++------ .../courseware/tests/test_navigation.py | 14 +-- .../courseware/tests/test_split_module.py | 9 +- .../tests/test_submitting_problems.py | 23 ++--- lms/djangoapps/courseware/tests/test_tabs.py | 24 ++--- .../tests/test_view_authentication.py | 24 ++--- lms/djangoapps/courseware/tests/test_views.py | 54 ++++++----- lms/djangoapps/courseware/tests/tests.py | 30 +++--- .../commands/tests/test_git_add_course.py | 10 +- .../dashboard/tests/test_support.py | 17 ++-- .../dashboard/tests/test_sysadmin.py | 18 ++-- .../django_comment_client/base/tests.py | 18 ++-- .../django_comment_client/forum/tests.py | 56 +++++------ .../tests/test_models.py | 29 ++++-- .../django_comment_client/tests/test_utils.py | 31 ++++-- .../django_comment_client/tests/utils.py | 6 +- .../tests/test_openended_commands.py | 34 ++++--- .../instructor/tests/test_access.py | 10 +- lms/djangoapps/instructor/tests/test_api.py | 95 +++++++++---------- .../instructor/tests/test_ecommerce.py | 15 ++- lms/djangoapps/instructor/tests/test_email.py | 18 ++-- .../instructor/tests/test_enrollment.py | 6 +- .../instructor/tests/test_hint_manager.py | 4 +- .../instructor/tests/test_legacy_anon_csv.py | 4 +- .../tests/test_legacy_download_csv.py | 4 +- .../instructor/tests/test_legacy_email.py | 7 +- .../tests/test_legacy_enrollment.py | 4 +- .../tests/test_legacy_forum_admin.py | 4 +- .../instructor/tests/test_legacy_reset.py | 4 +- .../instructor/tests/test_legacy_xss.py | 4 +- .../instructor/tests/test_spoc_gradebook.py | 4 +- lms/djangoapps/instructor/tests/test_tools.py | 10 +- .../instructor_task/tests/test_api.py | 6 +- .../instructor_task/tests/test_base.py | 20 ++-- .../instructor_task/tests/test_integration.py | 2 +- lms/djangoapps/licenses/tests.py | 4 +- .../mobile_api/course_info/tests.py | 7 +- .../mobile_api/video_outlines/tests.py | 24 ++--- lms/djangoapps/notifier_api/tests.py | 2 +- lms/djangoapps/oauth2_handler/tests.py | 9 +- lms/djangoapps/open_ended_grading/tests.py | 61 +++++++----- .../tests/test_context_processor.py | 11 ++- .../shoppingcart/tests/test_reports.py | 10 +- lms/djangoapps/staticbook/tests.py | 4 +- .../verify_student/tests/test_models.py | 22 +++-- .../verify_student/tests/test_ssencrypt.py | 3 - 89 files changed, 870 insertions(+), 780 deletions(-) delete mode 100644 lms/djangoapps/courseware/tests/modulestore_config.py diff --git a/cms/djangoapps/contentstore/tests/utils.py b/cms/djangoapps/contentstore/tests/utils.py index 439eccad98cb..a147ad30f620 100644 --- a/cms/djangoapps/contentstore/tests/utils.py +++ b/cms/djangoapps/contentstore/tests/utils.py @@ -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 @@ -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) 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): """ These tests need a user in the DB so that the django Test Client can log them in. diff --git a/common/djangoapps/course_groups/tests/test_cohorts.py b/common/djangoapps/course_groups/tests/test_cohorts.py index 7e87ee4ba9cc..b4a16af27c92 100644 --- a/common/djangoapps/course_groups/tests/test_cohorts.py +++ b/common/djangoapps/course_groups/tests/test_cohorts.py @@ -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") @@ -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. diff --git a/common/djangoapps/course_groups/tests/test_views.py b/common/djangoapps/course_groups/tests/test_views.py index 78fe1b623b94..580b469c8868 100644 --- a/common/djangoapps/course_groups/tests/test_views.py +++ b/common/djangoapps/course_groups/tests/test_views.py @@ -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. diff --git a/common/djangoapps/embargo/tests/test_forms.py b/common/djangoapps/embargo/tests/test_forms.py index b8aa08f35330..a909a7a6e760 100644 --- a/common/djangoapps/embargo/tests/test_forms.py +++ b/common/djangoapps/embargo/tests/test_forms.py @@ -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""" diff --git a/common/djangoapps/external_auth/tests/test_shib.py b/common/djangoapps/external_auth/tests/test_shib.py index ac2f49c3d25f..c5f86b9b9f82 100644 --- a/common/djangoapps/external_auth/tests/test_shib.py +++ b/common/djangoapps/external_auth/tests/test_shib.py @@ -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 @@ -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 @@ -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 diff --git a/common/djangoapps/external_auth/tests/test_ssl.py b/common/djangoapps/external_auth/tests/test_ssl.py index a81168d98e67..1bcecdded01a 100644 --- a/common/djangoapps/external_auth/tests/test_ssl.py +++ b/common/djangoapps/external_auth/tests/test_ssl.py @@ -2,7 +2,6 @@ Provides unit tests for SSL based authentication portions of the external_auth app. """ - import unittest from django.conf import settings @@ -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 xmodule.modulestore.tests.django_utils 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() @@ -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): @@ -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 diff --git a/common/djangoapps/geoinfo/tests/test_middleware.py b/common/djangoapps/geoinfo/tests/test_middleware.py index 3e6b7159acf2..860f21f08c17 100644 --- a/common/djangoapps/geoinfo/tests/test_middleware.py +++ b/common/djangoapps/geoinfo/tests/test_middleware.py @@ -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. diff --git a/common/djangoapps/reverification/tests/test_models.py b/common/djangoapps/reverification/tests/test_models.py index ca548f4ffbea..8ffddc8a1772 100644 --- a/common/djangoapps/reverification/tests/test_models.py +++ b/common/djangoapps/reverification/tests/test_models.py @@ -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 """ diff --git a/common/djangoapps/student/tests/test_bulk_email_settings.py b/common/djangoapps/student/tests/test_bulk_email_settings.py index a0e5a1b401df..4410320aae89 100644 --- a/common/djangoapps/student/tests/test_bulk_email_settings.py +++ b/common/djangoapps/student/tests/test_bulk_email_settings.py @@ -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): """ @@ -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): """ diff --git a/common/djangoapps/student/tests/test_login.py b/common/djangoapps/student/tests/test_login.py index 5b515873624a..828e951cbbf6 100644 --- a/common/djangoapps/student/tests/test_login.py +++ b/common/djangoapps/student/tests/test_login.py @@ -3,7 +3,6 @@ ''' import json import unittest -from mock import patch from django.test import TestCase from django.test.client import Client @@ -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): @@ -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 diff --git a/common/djangoapps/student/tests/tests.py b/common/djangoapps/student/tests/tests.py index 4c4177d18b92..898d2cc0b9b1 100644 --- a/common/djangoapps/student/tests/tests.py +++ b/common/djangoapps/student/tests/tests.py @@ -5,35 +5,38 @@ Replace this with more appropriate tests for your application. """ -import logging -import unittest from datetime import datetime, timedelta +import logging import pytz +import unittest 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.core.urlresolvers import reverse from django.contrib.sessions.middleware import SessionMiddleware - -from xmodule.modulestore.tests.factories import CourseFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from courseware.tests.tests import TEST_DATA_MIXED_MODULESTORE -from opaque_keys.edx.locations import SlashSeparatedCourseKey - +from django.core.urlresolvers import reverse +from django.test import TestCase +from django.test.client import RequestFactory, Client +from django.test.utils import override_settings 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, change_enrollment, complete_course_mode_info) from student.tests.factories import UserFactory, CourseModeFactory +from xmodule.modulestore.tests.factories import CourseFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE + +# These imports refer to lms djangoapps. +# Their testcases are only run under lms. +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__) @@ -176,7 +179,7 @@ def test_cert_info(self): 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): """ Tests for dashboard utility functions @@ -580,7 +583,7 @@ def test_change_enrollment_modes(self): 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') class ChangeEnrollmentViewTest(ModuleStoreTestCase): """Tests the student.views.change_enrollment view""" @@ -663,7 +666,7 @@ def test_change_to_honor_if_verified_not_active(self): self.assertEqual(enrollment_mode, u'honor') -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class PaidRegistrationTest(ModuleStoreTestCase): """ Tests for paid registration functionality (not verified student), involves shoppingcart @@ -696,7 +699,7 @@ def test_change_enrollment_add_to_cart(self): 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): """ Tests for anonymous_id_functions diff --git a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py index bac06d756e80..422c43220efc 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py @@ -2,21 +2,25 @@ """ Modulestore configuration for test cases. """ +import datetime +import pytz +from tempfile import mkdtemp from uuid import uuid4 -from django.test import TestCase + +from django.conf import settings 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.modulestore.django import modulestore, clear_existing_modulestores from xmodule.modulestore import ModuleStoreEnum -import datetime -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.django import modulestore, clear_existing_modulestores from xmodule.modulestore.tests.mongo_connection import MONGO_PORT_NUM, MONGO_HOST +from xmodule.modulestore.tests.sample_courses import default_block_info_tree, TOY_BLOCK_INFO_TREE +from xmodule.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 access to both Mongo- and XML-backed courses. @@ -36,9 +40,12 @@ def mixed_store_config(data_dir, mappings, include_xml=True): Keyword Args: include_xml (boolean): If True, include an XML modulestore in the configuration. - Note that this will require importing multiple XML courses from disk, - so unless your tests really needs XML course fixtures or is explicitly - testing mixed modulestore, set this to False. + xml_course_dirs (list): The directories containing XML courses to load from disk. + + 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 = [ @@ -47,7 +54,7 @@ def mixed_store_config(data_dir, mappings, include_xml=True): ] 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 = { 'default': { @@ -80,7 +87,7 @@ def draft_mongo_store_config(data_dir): 'host': MONGO_HOST, 'port': MONGO_PORT_NUM, 'db': 'test_xmodule', - 'collection': 'modulestore{0}'.format(uuid4().hex[:5]), + 'collection': 'modulestore_{0}'.format(uuid4().hex[:5]), }, 'OPTIONS': modulestore_options } @@ -107,7 +114,7 @@ def split_mongo_store_config(data_dir): 'host': MONGO_HOST, 'port': MONGO_PORT_NUM, 'db': 'test_xmodule', - 'collection': 'modulestore{0}'.format(uuid4().hex[:5]), + 'collection': 'modulestore_{0}'.format(uuid4().hex[:5]), }, 'OPTIONS': modulestore_options } @@ -119,6 +126,9 @@ def split_mongo_store_config(data_dir): def xml_store_config(data_dir, course_dirs=None): """ 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 = { 'default': { @@ -134,6 +144,39 @@ def xml_store_config(data_dir, course_dirs=None): 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): """ diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_assetstore.py b/common/lib/xmodule/xmodule/modulestore/tests/test_assetstore.py index 52feb63ed769..4d10ac87f31f 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_assetstore.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_assetstore.py @@ -3,17 +3,17 @@ too. """ from datetime import datetime, timedelta +import ddt +from nose.plugins.attrib import attr import pytz import unittest -import ddt from xmodule.assetstore import AssetMetadata from xmodule.modulestore import ModuleStoreEnum - from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.test_cross_modulestore_import_export import ( MIXED_MODULESTORE_BOTH_SETUP, MODULESTORE_SETUPS, MongoContentstoreBuilder, - XmlModulestoreBuilder, MixedModulestoreBuilder, MongoModulestoreBuilder + XmlModulestoreBuilder, MixedModulestoreBuilder ) @@ -43,6 +43,7 @@ class AssetStoreTestData(object): ) +@attr('mongo') @ddt.ddt class TestMongoAssetMetadataStorage(unittest.TestCase): """ diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_cross_modulestore_import_export.py b/common/lib/xmodule/xmodule/modulestore/tests/test_cross_modulestore_import_export.py index 7fdae012b1d9..c8f5b5f0eaff 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_cross_modulestore_import_export.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_cross_modulestore_import_export.py @@ -11,16 +11,17 @@ 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 +from path import path import random -from contextlib import contextmanager, nested from shutil import rmtree 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.draft import DraftModuleStore from xmodule.modulestore.mixed import MixedModuleStore @@ -289,6 +290,7 @@ def __repr__(self): @ddt.ddt +@attr('mongo') class CrossStoreXMLRoundtrip(CourseComparisonTest): """ This class exists to test XML import and export between different modulestore diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py b/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py index 87e1dc34d78f..19e8664955fa 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py @@ -2,25 +2,26 @@ """ Unit tests for the Mixed Modulestore, with DDT for the various stores (Split, Draft, XML) """ +from collections import namedtuple import datetime import ddt -import itertools -import pymongo - -from collections import namedtuple from importlib import import_module -from pytz import UTC +import itertools +import mimetypes from uuid import uuid4 # Mixed modulestore depends on django, so we'll manually configure some django settings # before importing the module # TODO remove this import and the configuration -- xmodule should not depend on django! 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.inheritance import InheritanceMixin from xmodule.modulestore.tests.test_cross_modulestore_import_export import MongoContentstoreBuilder from xmodule.contentstore.content import StaticContent -import mimetypes from opaque_keys.edx.keys import CourseKey from xmodule.modulestore.xml_importer import import_from_xml from nose import SkipTest @@ -43,6 +44,7 @@ @ddt.ddt +@attr('mongo') class TestMixedModuleStore(CourseComparisonTest): """ Quasi-superclass which tests Location based apps against both split and mongo dbs (Locator and diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_publish.py b/common/lib/xmodule/xmodule/modulestore/tests/test_publish.py index ff0ddc2e0431..b067a8bc5c03 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_publish.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_publish.py @@ -1,12 +1,15 @@ """ 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.tests.test_split_w_old_mongo import SplitWMongoCourseBoostrapper from xmodule.modulestore.tests.factories import check_mongo_calls, mongo_uses_error_check -from xmodule.modulestore import ModuleStoreEnum +@attr('mongo') class TestPublish(SplitWMongoCourseBoostrapper): """ Test the publish code (primary causing orphans) diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_split_migrator.py b/common/lib/xmodule/xmodule/modulestore/tests/test_split_migrator.py index 835375ae7ed9..442a98d85778 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_split_migrator.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_split_migrator.py @@ -2,14 +2,18 @@ Tests for split_migrator """ -import uuid import random +import uuid + import mock +from nose.plugins.attrib import attr + from xblock.fields import Reference, ReferenceList, ReferenceValueDict from xmodule.modulestore.split_migrator import SplitMigrator from xmodule.modulestore.tests.test_split_w_old_mongo import SplitWMongoCourseBoostrapper +@attr('mongo') class TestMigration(SplitWMongoCourseBoostrapper): """ Test the split migrator diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore.py b/common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore.py index f41ec6acad23..4b399de14785 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore.py @@ -2,13 +2,15 @@ Test split modulestore w/o using any django stuff. """ import datetime +from importlib import import_module +from path import path import random import re import unittest import uuid + from contracts import contract -from importlib import import_module -from path import path +from nose.plugins.attrib import attr from xblock.fields import Reference, ReferenceList, ReferenceValueDict from xmodule.course_module import CourseDescriptor @@ -33,6 +35,7 @@ BRANCH_NAME_PUBLISHED = ModuleStoreEnum.BranchName.published +@attr('mongo') class SplitModuleTest(unittest.TestCase): ''' The base set of tests manually populates a db w/ courses which have diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_split_w_old_mongo.py b/common/lib/xmodule/xmodule/modulestore/tests/test_split_w_old_mongo.py index bab04573e449..939d2d09b805 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_split_w_old_mongo.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_split_w_old_mongo.py @@ -1,18 +1,21 @@ -import unittest -import mock import datetime -import uuid 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 xmodule.modulestore.split_mongo.split import SplitMongoModuleStore -from xmodule.modulestore.mongo import DraftMongoModuleStore 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.test_cross_modulestore_import_export import MemoryCache +@attr('mongo') class SplitWMongoCourseBoostrapper(unittest.TestCase): """ Helper for tests which need to construct split mongo & old mongo based courses to get interesting internal structure. diff --git a/lms/djangoapps/branding/tests.py b/lms/djangoapps/branding/tests.py index a18c2afad3ba..520b00a4b5cf 100644 --- a/lms/djangoapps/branding/tests.py +++ b/lms/djangoapps/branding/tests.py @@ -2,20 +2,19 @@ Tests for branding page """ import datetime -from django.http import HttpResponseRedirect -from pytz import UTC from django.conf import settings from django.contrib.auth.models import AnonymousUser +from django.http import HttpResponseRedirect from django.test.utils import override_settings 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 xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE 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['DISABLE_START_DATES'] = False @@ -23,7 +22,7 @@ FEATURES_WO_STARTDATE['DISABLE_START_DATES'] = True -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class AnonymousIndexPageTest(ModuleStoreTestCase): """ Tests that anonymous users can access the '/' page, Need courses with start date diff --git a/lms/djangoapps/bulk_email/tests/test_course_optout.py b/lms/djangoapps/bulk_email/tests/test_course_optout.py index ed3a73855abb..88926561e05a 100644 --- a/lms/djangoapps/bulk_email/tests/test_course_optout.py +++ b/lms/djangoapps/bulk_email/tests/test_course_optout.py @@ -3,6 +3,7 @@ Unit tests for student optouts from course email """ import json +from mock import patch from django.core import mail from django.core.management import call_command @@ -10,16 +11,14 @@ from django.conf import 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.models import CourseEnrollment from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase 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): """ diff --git a/lms/djangoapps/bulk_email/tests/test_email.py b/lms/djangoapps/bulk_email/tests/test_email.py index 0231449ceb87..dad65d6e66b9 100644 --- a/lms/djangoapps/bulk_email/tests/test_email.py +++ b/lms/djangoapps/bulk_email/tests/test_email.py @@ -3,7 +3,6 @@ Unit tests for sending course email """ import json - from mock import patch from django.conf import settings @@ -12,16 +11,15 @@ from django.core.management import call_command 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 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 student.roles import CourseStaffRole 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 STUDENT_COUNT = 10 @@ -44,7 +42,7 @@ def mock_update_subtask_status(entry_id, current_task_id, new_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}) class TestEmailSendFromDashboard(ModuleStoreTestCase): """ diff --git a/lms/djangoapps/bulk_email/tests/test_err_handling.py b/lms/djangoapps/bulk_email/tests/test_err_handling.py index 6734fbc9d565..fc889f36aa5a 100644 --- a/lms/djangoapps/bulk_email/tests/test_err_handling.py +++ b/lms/djangoapps/bulk_email/tests/test_err_handling.py @@ -2,28 +2,21 @@ """ Unit tests for handling email sending errors """ -import json - from itertools import cycle -from mock import patch -from smtplib import SMTPDataError, SMTPServerDisconnected, SMTPConnectError from celery.states import SUCCESS, RETRY - from django.test.utils import override_settings from django.conf import settings from django.core.management import call_command from django.core.urlresolvers import reverse from django.db import DatabaseError - -from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory -from opaque_keys.edx.locations import SlashSeparatedCourseKey -from student.tests.factories import UserFactory, AdminFactory, CourseEnrollmentFactory +import json +from mock import patch +from smtplib import SMTPDataError, SMTPServerDisconnected, SMTPConnectError from bulk_email.models import CourseEmail, SEND_TO_ALL 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.subtasks import ( initialize_subtask_info, @@ -33,6 +26,10 @@ DuplicateTaskException, 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): @@ -40,7 +37,7 @@ class EmailTestException(Exception): 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}) class TestEmailErrors(ModuleStoreTestCase): """ diff --git a/lms/djangoapps/bulk_email/tests/test_forms.py b/lms/djangoapps/bulk_email/tests/test_forms.py index 9e311882c82d..558758f58459 100644 --- a/lms/djangoapps/bulk_email/tests/test_forms.py +++ b/lms/djangoapps/bulk_email/tests/test_forms.py @@ -2,25 +2,23 @@ """ Unit tests for bulk-email-related forms. """ -from django.test.utils import override_settings from django.conf import 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 django.test.utils import override_settings from mock import patch from bulk_email.models import CourseAuthorization, CourseEmailTemplate 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 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): """Test the CourseAuthorizationAdminForm form for Mongo-backed courses.""" @@ -124,7 +122,7 @@ def test_course_name_only(self): form.save() -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MIXED_TOY_MODULESTORE) class CourseAuthorizationXMLFormTest(ModuleStoreTestCase): """Check that XML courses cannot be authorized for email.""" @@ -147,7 +145,7 @@ def test_xml_course_authorization(self): form.save() -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class CourseEmailTemplateFormTest(ModuleStoreTestCase): """Test the CourseEmailTemplateForm that is used in the Django admin subsystem.""" diff --git a/lms/djangoapps/class_dashboard/tests/test_dashboard_data.py b/lms/djangoapps/class_dashboard/tests/test_dashboard_data.py index e2281597423d..73a7601397e2 100644 --- a/lms/djangoapps/class_dashboard/tests/test_dashboard_data.py +++ b/lms/djangoapps/class_dashboard/tests/test_dashboard_data.py @@ -3,17 +3,18 @@ """ import json -from mock import patch from django.test.utils import override_settings from django.core.urlresolvers import reverse from django.test.client import RequestFactory -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE +from mock import patch + +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 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, get_problem_set_grade_distrib, get_d3_problem_grade_distrib, @@ -26,7 +27,7 @@ USER_COUNT = 11 -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestGetProblemGradeDistribution(ModuleStoreTestCase): """ Tests related to class_dashboard/dashboard_data.py diff --git a/lms/djangoapps/class_dashboard/tests/test_views.py b/lms/djangoapps/class_dashboard/tests/test_views.py index f2c49324ddfa..f4b5f31941f1 100644 --- a/lms/djangoapps/class_dashboard/tests/test_views.py +++ b/lms/djangoapps/class_dashboard/tests/test_views.py @@ -1,21 +1,20 @@ """ Tests for class dashboard (Metrics tab in instructor dashboard) """ -from mock import patch from django.test.utils import override_settings - -from django.test import TestCase 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 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 class_dashboard import views -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestViews(ModuleStoreTestCase): """ Tests related to class_dashboard/views.py diff --git a/lms/djangoapps/course_wiki/tests/test_access.py b/lms/djangoapps/course_wiki/tests/test_access.py index 04cbe0e62ca5..39480c5618e9 100644 --- a/lms/djangoapps/course_wiki/tests/test_access.py +++ b/lms/djangoapps/course_wiki/tests/test_access.py @@ -9,7 +9,7 @@ from django.test.utils import override_settings 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 course_wiki.views import get_or_create_root @@ -17,7 +17,7 @@ from course_wiki import settings -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestWikiAccessBase(ModuleStoreTestCase): """Base class for testing wiki access.""" def setUp(self): diff --git a/lms/djangoapps/course_wiki/tests/test_middleware.py b/lms/djangoapps/course_wiki/tests/test_middleware.py index 28e548996e54..519d3a8ccbe8 100644 --- a/lms/djangoapps/course_wiki/tests/test_middleware.py +++ b/lms/djangoapps/course_wiki/tests/test_middleware.py @@ -10,11 +10,11 @@ from xmodule.modulestore.tests.factories import CourseFactory 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 -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestWikiAccessMiddleware(ModuleStoreTestCase): """Tests for WikiAccessMiddleware.""" diff --git a/lms/djangoapps/course_wiki/tests/tests.py b/lms/djangoapps/course_wiki/tests/tests.py index 30e57774b1bc..a3428c77a901 100644 --- a/lms/djangoapps/course_wiki/tests/tests.py +++ b/lms/djangoapps/course_wiki/tests/tests.py @@ -2,13 +2,13 @@ from django.test.utils import override_settings 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 mock import patch -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class WikiRedirectTestCase(LoginEnrollmentTestCase): """ Tests for wiki course redirection. diff --git a/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py b/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py index 433a494c8467..55be6cc8cd2c 100644 --- a/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py +++ b/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py @@ -3,33 +3,37 @@ """Tests for Django management commands""" import json +from path import path import shutil from StringIO import StringIO import tarfile from tempfile import mkdtemp -from path import path - +from django.conf import settings from django.core.management import call_command from django.test.utils import override_settings from django.test.testcases import TestCase - -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 opaque_keys.edx.locations import SlashSeparatedCourseKey from xmodule.modulestore import ModuleStoreEnum 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.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 - 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): """ @@ -58,7 +62,7 @@ def load_courses(self): courses = store.get_courses() # 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]: - 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()] @@ -194,7 +198,7 @@ def check_export_file(self, tar_file): # pylint: disable=missing-docstring 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): """ Test case for management commands using the xml modulestore. @@ -205,14 +209,6 @@ class CommandsXMLTestCase(CommandsTestBase, ModuleStoreTestCase): @override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) class CommandsMongoTestCase(CommandsTestBase, ModuleStoreTestCase): """ - Test case for management commands using the mongo modulestore. - - """ - - -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) -class CommandsMixedTestCase(CommandsTestBase, ModuleStoreTestCase): - """ - Test case for management commands. Using the mixed modulestore. + Test case for management commands using the mixed mongo modulestore. """ diff --git a/lms/djangoapps/courseware/tests/__init__.py b/lms/djangoapps/courseware/tests/__init__.py index 29f07391d581..c0cf78fdb314 100644 --- a/lms/djangoapps/courseware/tests/__init__.py +++ b/lms/djangoapps/courseware/tests/__init__.py @@ -13,7 +13,7 @@ from edxmako.shortcuts import render_to_string 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 xmodule.tests import get_test_system, get_test_descriptor_system from opaque_keys.edx.locations import Location diff --git a/lms/djangoapps/courseware/tests/modulestore_config.py b/lms/djangoapps/courseware/tests/modulestore_config.py deleted file mode 100644 index 9b7908c57591..000000000000 --- a/lms/djangoapps/courseware/tests/modulestore_config.py +++ /dev/null @@ -1,31 +0,0 @@ -""" -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, {}) diff --git a/lms/djangoapps/courseware/tests/test_about.py b/lms/djangoapps/courseware/tests/test_about.py index bd4cb510138a..0231656313e0 100644 --- a/lms/djangoapps/courseware/tests/test_about.py +++ b/lms/djangoapps/courseware/tests/test_about.py @@ -1,33 +1,34 @@ """ Test the about xblock """ -import mock -from mock import patch -import pytz import datetime -from django.test.utils import override_settings -from django.core.urlresolvers import reverse -from django.conf import settings +import pytz -from .helpers import LoginEnrollmentTestCase -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE, TEST_DATA_MIXED_MODULESTORE -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory +from django.conf import settings +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 student.tests.factories import UserFactory, CourseEnrollmentAllowedFactory + 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.tests.factories import UserFactory, CourseEnrollmentAllowedFactory from shoppingcart.models import Order, PaidCourseRegistration - 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 REG_STR = "
" 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): """ Tests about xblock. @@ -120,8 +121,11 @@ def test_logged_in_marketing(self): 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): + """ + Tests for the course about page + """ # The following XML test course (which lives at common/test/data/2014) # is closed; we're testing that an about page still appears when # the course is already closed @@ -131,7 +135,7 @@ class AboutTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase): # common/test/data/2014/about/overview.html 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): self.setup_user() url = reverse('about_course', args=[self.xml_course_id.to_deprecated_string()]) @@ -139,7 +143,7 @@ def test_logged_in_xml(self): self.assertEqual(resp.status_code, 200) 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): url = reverse('about_course', args=[self.xml_course_id.to_deprecated_string()]) resp = self.client.get(url) @@ -147,7 +151,7 @@ def test_anonymous_user_xml(self): 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): """ This test case will check the About page when a course has a capped enrollment @@ -197,7 +201,7 @@ def test_enrollment_cap(self): self.assertNotIn(REG_STR, resp.content) -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class AboutWithInvitationOnly(ModuleStoreTestCase): """ This test case will check the About page when a course is invitation only. @@ -244,7 +248,7 @@ def test_invitation_only_but_allowed(self): @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): """ Test cases covering about page behavior for courses that use shib enrollment domain ("shib courses") @@ -283,7 +287,7 @@ def test_anonymous_user_shib_course(self): self.assertIn(REG_STR, resp.content) -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class AboutWithClosedEnrollment(ModuleStoreTestCase): """ This test case will check the About page for a course that has enrollment start/end @@ -319,7 +323,7 @@ def test_closed_enrollmement(self): 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_PAID_COURSE_REGISTRATION': True}) class AboutPurchaseCourseTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase): diff --git a/lms/djangoapps/courseware/tests/test_access.py b/lms/djangoapps/courseware/tests/test_access.py index 0963b74489c1..59a9a5b86b09 100644 --- a/lms/djangoapps/courseware/tests/test_access.py +++ b/lms/djangoapps/courseware/tests/test_access.py @@ -1,19 +1,17 @@ -import courseware.access as access import datetime - -import mock -from mock import Mock +import pytz 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 student.tests.factories import AnonymousUserFactory, CourseEnrollmentAllowedFactory -import pytz -from opaque_keys.edx.locations import SlashSeparatedCourseKey - from xmodule.course_module import ( CATALOG_VISIBILITY_CATALOG_AND_ABOUT, CATALOG_VISIBILITY_ABOUT, - CATALOG_VISIBILITY_NONE) + CATALOG_VISIBILITY_NONE +) # pylint: disable=missing-docstring # pylint: disable=protected-access @@ -115,7 +113,7 @@ def test__has_access_descriptor(self): with self.assertRaises(ValueError): 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): """ Tests that "visible_to_staff_only" overrides start date. diff --git a/lms/djangoapps/courseware/tests/test_course_info.py b/lms/djangoapps/courseware/tests/test_course_info.py index d1f01b528813..25e516f3999b 100644 --- a/lms/djangoapps/courseware/tests/test_course_info.py +++ b/lms/djangoapps/courseware/tests/test_course_info.py @@ -1,18 +1,25 @@ """ Test the course_info xblock """ -import mock -from django.test.utils import override_settings 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 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 .helpers import LoginEnrollmentTestCase + -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class CourseInfoTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase): + """ + Tests for the Course Info page + """ def setUp(self): self.course = CourseFactory.create() self.page = ItemFactory.create( @@ -41,12 +48,15 @@ def test_anonymous_user(self): 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): + """ + Tests for the Course Info page for an XML course + """ # The following XML test course (which lives at common/test/data/2014) # is closed; we're testing that a course info page still appears when # the course is already closed - 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 # common/test/data/2014/info/updates.html @@ -55,14 +65,14 @@ class CourseInfoTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase): @mock.patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False}) def test_logged_in_xml(self): 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) self.assertEqual(resp.status_code, 200) self.assertIn(self.xml_data, resp.content) @mock.patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False}) 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) self.assertEqual(resp.status_code, 200) self.assertNotIn(self.xml_data, resp.content) diff --git a/lms/djangoapps/courseware/tests/test_courses.py b/lms/djangoapps/courseware/tests/test_courses.py index cd00abc120eb..465ab9824180 100644 --- a/lms/djangoapps/courseware/tests/test_courses.py +++ b/lms/djangoapps/courseware/tests/test_courses.py @@ -2,34 +2,38 @@ """ Tests for course access """ +from django.conf import settings +from django.test.utils import override_settings 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 import xmodule.modulestore.django as store_django 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 ( + TEST_DATA_MOCK_MODULESTORE, TEST_DATA_MIXED_TOY_MODULESTORE +) from xmodule.modulestore.tests.factories import CourseFactory from xmodule.tests.xml import factories as xml 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' +TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT class CoursesTest(ModuleStoreTestCase): """Test methods related to fetching courses.""" @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): """ @@ -71,7 +75,7 @@ def test_default_modulestore_branch_mapping(self): @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): """Tests for course image URLs when using a mongo modulestore.""" @@ -144,35 +148,43 @@ def test_spaces_in_image_name(self): 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): """Test methods related to rendering courses content.""" - 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()) + # 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): + """ + 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 - course_info = get_course_info_section(request, course, 'handouts') - self.assertEqual(course_info, "Sample") + course_info = get_course_info_section(self.request, self.course, 'handouts') + self.assertEqual(course_info, u"Sample") # 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') + course_info = get_course_info_section(self.request, self.course, 'handouts') self.assertIn("this module is temporarily unavailable", course_info) @mock.patch('courseware.courses.get_request_for_thread') def test_get_course_about_section_render(self, mock_get_request): - course = get_course_by_id(self.toy_course_key) - request = get_request_for_user(UserFactory.create()) - mock_get_request.return_value = request + mock_get_request.return_value = self.request # 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.") # Test when render raises an exception @@ -180,5 +192,27 @@ def test_get_course_about_section_render(self, mock_get_request): mock_module_render.return_value = mock.MagicMock( 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) + + +@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, "Sample") + + # 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) diff --git a/lms/djangoapps/courseware/tests/test_draft_modulestore.py b/lms/djangoapps/courseware/tests/test_draft_modulestore.py index 991c18cc133c..aa3341cc8ab2 100644 --- a/lms/djangoapps/courseware/tests/test_draft_modulestore.py +++ b/lms/djangoapps/courseware/tests/test_draft_modulestore.py @@ -4,11 +4,14 @@ from xmodule.modulestore.django import modulestore 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): + """ + Test the draft modulestore + """ def test_get_items_with_course_items(self): store = modulestore() diff --git a/lms/djangoapps/courseware/tests/test_grades.py b/lms/djangoapps/courseware/tests/test_grades.py index 9518f76c660d..89f2dd8cfdc2 100644 --- a/lms/djangoapps/courseware/tests/test_grades.py +++ b/lms/djangoapps/courseware/tests/test_grades.py @@ -4,14 +4,13 @@ from django.http import Http404 from django.test.utils import override_settings 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 xmodule.modulestore.tests.factories import CourseFactory 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): @@ -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) -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestGradeIteration(ModuleStoreTestCase): """ Test iteration through student gradesets. diff --git a/lms/djangoapps/courseware/tests/test_i18n.py b/lms/djangoapps/courseware/tests/test_i18n.py index 88843689cbed..9de159756d60 100644 --- a/lms/djangoapps/courseware/tests/test_i18n.py +++ b/lms/djangoapps/courseware/tests/test_i18n.py @@ -1,13 +1,15 @@ """ Tests i18n in courseware """ +import re + from django.test import TestCase 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): """ Tests for i18n diff --git a/lms/djangoapps/courseware/tests/test_lti_integration.py b/lms/djangoapps/courseware/tests/test_lti_integration.py index 03b9e576c447..0811cf09a7ee 100644 --- a/lms/djangoapps/courseware/tests/test_lti_integration.py +++ b/lms/djangoapps/courseware/tests/test_lti_integration.py @@ -1,25 +1,22 @@ """LTI integration tests""" -import oauthlib from collections import OrderedDict +import json import mock +import oauthlib import urllib -import json -from django.test.utils import override_settings -from django.core.urlresolvers import reverse from django.conf import settings - -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 CourseFactory, ItemFactory -from xmodule.x_module import STUDENT_VIEW +from django.core.urlresolvers import reverse +from django.test.utils import override_settings 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 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): @@ -126,7 +123,7 @@ def test_lti_preview_handler(self): self.assertEqual(generated_content, expected_content) -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestLTIModuleListing(ModuleStoreTestCase): """ a test for the rest endpoint that lists LTI modules in a course diff --git a/lms/djangoapps/courseware/tests/test_masquerade.py b/lms/djangoapps/courseware/tests/test_masquerade.py index 65b29d24eaf5..0703659ad9e3 100644 --- a/lms/djangoapps/courseware/tests/test_masquerade.py +++ b/lms/djangoapps/courseware/tests/test_masquerade.py @@ -7,32 +7,33 @@ ./manage.py lms --settings test test lms/djangoapps/courseware """ - import json -from django.test.utils import override_settings 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.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 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): """ Check for staff being able to masquerade as student. """ def setUp(self): - # Clear out the modulestores, causing them to reload clear_existing_modulestores() - self.graded_course = modulestore().get_course(SlashSeparatedCourseKey("edX", "graded", "2012_Fall")) # Create staff account diff --git a/lms/djangoapps/courseware/tests/test_microsites.py b/lms/djangoapps/courseware/tests/test_microsites.py index 633c7b9d7f2e..b39b756b8138 100644 --- a/lms/djangoapps/courseware/tests/test_microsites.py +++ b/lms/djangoapps/courseware/tests/test_microsites.py @@ -1,21 +1,20 @@ """ Tests related to the Microsites feature """ +from django.conf import settings from django.core.urlresolvers import reverse from django.test.utils import override_settings -from django.conf import settings -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase - -from helpers import LoginEnrollmentTestCase -from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE +from courseware.tests.helpers import LoginEnrollmentTestCase +from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE from course_modes.models import CourseMode from xmodule.course_module import ( 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): """ This is testing of the Microsite feature diff --git a/lms/djangoapps/courseware/tests/test_middleware.py b/lms/djangoapps/courseware/tests/test_middleware.py index ff92b33e92db..f07b9b33ebf2 100644 --- a/lms/djangoapps/courseware/tests/test_middleware.py +++ b/lms/djangoapps/courseware/tests/test_middleware.py @@ -8,14 +8,14 @@ from django.http import Http404 from mock import patch -from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE import courseware.courses as courses 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.factories import CourseFactory -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class CoursewareMiddlewareTestCase(ModuleStoreTestCase): """Tests that courseware middleware is correctly redirected""" diff --git a/lms/djangoapps/courseware/tests/test_module_render.py b/lms/djangoapps/courseware/tests/test_module_render.py index a08902eb50e8..caed8a430155 100644 --- a/lms/djangoapps/courseware/tests/test_module_render.py +++ b/lms/djangoapps/courseware/tests/test_module_render.py @@ -1,45 +1,46 @@ """ Test for lms courseware app, module render unit """ -import ddt from functools import partial -from mock import MagicMock, patch, Mock import json +from unittest import skip +import ddt from django.http import Http404, HttpResponse from django.core.urlresolvers import reverse from django.conf import settings from django.test.client import RequestFactory from django.test.utils import override_settings from django.contrib.auth.models import AnonymousUser - -from capa.tests.response_xml_factory import OptionResponseXMLFactory +from mock import MagicMock, patch, Mock +from opaque_keys.edx.locations import SlashSeparatedCourseKey from xblock.field_data import FieldData from xblock.runtime import Runtime from xblock.fields import ScopeIds 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.courses import get_course_with_access, course_image_url, get_course_info_section from courseware.model_data import FieldDataCache from courseware.models import StudentModule from courseware.tests.factories import StudentModuleFactory, UserFactory, GlobalStaffFactory from courseware.tests.tests import LoginEnrollmentTestCase - -from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE -from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE -from courseware.tests.modulestore_config import TEST_DATA_XML_MODULESTORE +from xmodule.modulestore.tests.django_utils import ( + TEST_DATA_MOCK_MODULESTORE, TEST_DATA_MIXED_TOY_MODULESTORE, + TEST_DATA_XML_MODULESTORE +) 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 student.models import anonymous_id_for_user +from xmodule.lti_module import LTIDescriptor 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): @@ -50,14 +51,20 @@ class PureXBlock(XBlock): @ddt.ddt -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class ModuleRenderTestCase(ModuleStoreTestCase, LoginEnrollmentTestCase): """ 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): - 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.mock_user = UserFactory() self.mock_user.id = 1 @@ -182,14 +189,16 @@ def test_rebinding_same_user(self, block_type): 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): """ Test the handle_xblock_callback function """ 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.toy_course = modulestore().get_course(self.course_key) self.mock_user = UserFactory() @@ -335,7 +344,7 @@ def test_missing_handler(self): @ddt.ddt -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestTOC(ModuleStoreTestCase): """Check the Table of Contents for a course""" def setup_modulestore(self, default_ms, num_finds, num_sends): @@ -364,6 +373,7 @@ def setup_modulestore(self, default_ms, num_finds, num_sends): # - it loads the active version at the start of the bulk operation # - it loads the course definition for inheritance, because it's outside # 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.unpack def test_toc_toy_from_chapter(self, default_ms, setup_finds, setup_sends, toc_finds): @@ -402,6 +412,7 @@ def test_toc_toy_from_chapter(self, default_ms, setup_finds, setup_sends, toc_fi # - it loads the active version at the start of the bulk operation # - it loads the course definition for inheritance, because it's outside # 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.unpack def test_toc_toy_from_section(self, default_ms, setup_finds, setup_sends, toc_finds): @@ -429,7 +440,7 @@ def test_toc_toy_from_section(self, default_ms, setup_finds, setup_sends, toc_fi self.assertIn(toc_section, actual) -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestHtmlModifiers(ModuleStoreTestCase): """ Tests to verify that standard modifications to the output of XModule/XBlock @@ -623,7 +634,7 @@ def setup_xml_course(self): 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): """Test the 'View in Studio' link visibility in a mongo backed course.""" @@ -655,7 +666,7 @@ def test_view_in_studio_link_xml_authored(self): 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): """Test the 'View in Studio' link visibility in a mixed mongo backed course.""" @@ -695,7 +706,7 @@ def test_view_in_studio_link_xml_backed(self): 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('courseware.module_render.has_access', Mock(return_value=True)) class TestStaffDebugInfo(ModuleStoreTestCase): @@ -816,7 +827,7 @@ def test_histogram_enabled_for_scored_xmodules(self): @ddt.ddt -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestAnonymousStudentId(ModuleStoreTestCase, LoginEnrollmentTestCase): """ Test that anonymous_student_id is set correctly across a variety of XBlock types @@ -883,7 +894,7 @@ def test_per_course_anonymized_id(self, descriptor_class): ) -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) @patch('track.views.tracker') class TestModuleTrackingContext(ModuleStoreTestCase): """ diff --git a/lms/djangoapps/courseware/tests/test_navigation.py b/lms/djangoapps/courseware/tests/test_navigation.py index d9b36ebd01de..212658eaa6e5 100644 --- a/lms/djangoapps/courseware/tests/test_navigation.py +++ b/lms/djangoapps/courseware/tests/test_navigation.py @@ -2,21 +2,20 @@ This test file will run through some LMS test scenarios regarding access and navigation of the LMS """ import time -from django.conf import settings +import unittest +from django.conf import settings from django.core.urlresolvers import reverse 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.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 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): """ Check that navigation state is saved properly. @@ -122,6 +121,7 @@ def test_chrome_settings(self): self.assertTabActive('progress', response) self.assertTabInactive('courseware', response) + @unittest.skip @override_settings(SESSION_INACTIVITY_TIMEOUT_IN_SECONDS=1) def test_inactive_session_timeout(self): """ diff --git a/lms/djangoapps/courseware/tests/test_split_module.py b/lms/djangoapps/courseware/tests/test_split_module.py index ccdc863d51ff..2fe280c12cdb 100644 --- a/lms/djangoapps/courseware/tests/test_split_module.py +++ b/lms/djangoapps/courseware/tests/test_split_module.py @@ -5,18 +5,17 @@ from django.test.utils import override_settings from mock import MagicMock -from student.tests.factories import UserFactory, CourseEnrollmentFactory -from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE +from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE from courseware.module_render import get_module_for_descriptor 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.django_utils import ModuleStoreTestCase - from xmodule.partitions.partitions import Group, UserPartition from user_api.tests.factories import UserCourseTagFactory -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class SplitTestBase(ModuleStoreTestCase): """ Sets up a basic course and user for split test testing. @@ -271,7 +270,7 @@ def setUp(self): html1 = self._html(cond1vert, 1) -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class SplitTestPosition(ModuleStoreTestCase): """ Check that we can change positions in a course with partitions defined diff --git a/lms/djangoapps/courseware/tests/test_submitting_problems.py b/lms/djangoapps/courseware/tests/test_submitting_problems.py index 0c864938fb5a..a51aaa6ad555 100644 --- a/lms/djangoapps/courseware/tests/test_submitting_problems.py +++ b/lms/djangoapps/courseware/tests/test_submitting_problems.py @@ -2,41 +2,35 @@ """ Integration tests for submitting problem responses and getting grades. """ -# text processing dependencies import json import os from textwrap import dedent -from mock import patch - from django.conf import settings from django.contrib.auth.models import User -from django.test.client import RequestFactory from django.core.urlresolvers import reverse +from django.test.client import RequestFactory 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 ( OptionResponseXMLFactory, CustomResponseXMLFactory, SchematicResponseXMLFactory, CodeResponseXMLFactory, ) +from courseware import grades +from courseware.models import StudentModule 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 student.tests.factories import UserFactory 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 user_api.tests.factories import UserCourseTagFactory -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestSubmittingProblems(ModuleStoreTestCase, LoginEnrollmentTestCase): """ Check that a course gets graded properly. @@ -651,6 +645,7 @@ def test_three_files(self): self.assertItemsEqual(kwargs['files'].keys(), filenames.split()) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestPythonGradedResponse(TestSubmittingProblems): """ Check that we can submit a schematic and custom response, and it answers properly. diff --git a/lms/djangoapps/courseware/tests/test_tabs.py b/lms/djangoapps/courseware/tests/test_tabs.py index 0cb978fb7992..e1d770b80424 100644 --- a/lms/djangoapps/courseware/tests/test_tabs.py +++ b/lms/djangoapps/courseware/tests/test_tabs.py @@ -1,25 +1,25 @@ """ 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 opaque_keys.edx.locations import SlashSeparatedCourseKey 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 django.http import Http404 -from django.test.utils import override_settings -from django.core.urlresolvers import reverse - from student.tests.factories import UserFactory from xmodule.tabs import CourseTabList from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase 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): """Test cases for Static Tab Dates.""" @@ -49,7 +49,6 @@ def test_invalid_course_key(self): with self.assertRaises(Http404): 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): course = get_course_by_id(self.toy_course_key) request = get_request_for_user(UserFactory.create()) @@ -69,8 +68,11 @@ def test_get_static_tab_contents(self): 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): + """ + Tests for the static tab dates of an XML course + """ # The following XML test course (which lives at common/test/data/2014) # is closed; we're testing that tabs still appear when # the course is already closed diff --git a/lms/djangoapps/courseware/tests/test_view_authentication.py b/lms/djangoapps/courseware/tests/test_view_authentication.py index a9584499ec20..17862a5cb277 100644 --- a/lms/djangoapps/courseware/tests/test_view_authentication.py +++ b/lms/djangoapps/courseware/tests/test_view_authentication.py @@ -1,22 +1,13 @@ import datetime import pytz -from mock import patch - from django.core.urlresolvers import reverse 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 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.modulestore_config import TEST_DATA_MIXED_MODULESTORE +from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE from courseware.tests.factories import ( BetaTesterFactory, StaffFactory, @@ -26,9 +17,12 @@ OrgInstructorFactory, ) 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): """ Check that view authentication works properly. @@ -395,9 +389,11 @@ def test_enrollment_period(self): self.assertTrue(self.enroll(self.course)) -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestBetatesterAccess(ModuleStoreTestCase): - + """ + Tests for the beta tester feature + """ def setUp(self): now = datetime.datetime.now(pytz.UTC) diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index 7556530daaac..48e5e3366b26 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -2,44 +2,39 @@ """ Tests courseware views.py """ -import unittest import cgi from datetime import datetime - -from mock import MagicMock, patch, create_autospec from pytz import UTC - -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 +import unittest from django.conf import settings +from django.contrib.auth.models import User, AnonymousUser from django.core.urlresolvers import reverse - -from student.models import CourseEnrollment -from student.tests.factories import AdminFactory +from django.http import Http404 +from django.test import TestCase +from django.test.client import RequestFactory +from django.test.utils import override_settings from edxmako.middleware import MakoMiddleware from edxmako.tests import mako_middleware_process_request - -from opaque_keys.edx.locations import Location -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 +from mock import MagicMock, patch, create_autospec +from opaque_keys.edx.locations import Location, SlashSeparatedCourseKey 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 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.views import ensure_valid_course_key -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MIXED_TOY_MODULESTORE) class TestJumpTo(TestCase): """ Check the jumpto link for a course. @@ -57,6 +52,7 @@ def test_jumpto_invalid_location(self): response = self.client.get(jumpto_url) self.assertEqual(response.status_code, 404) + @unittest.skip def test_jumpto_from_chapter(self): 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()) @@ -64,6 +60,7 @@ def test_jumpto_from_chapter(self): response = self.client.get(jumpto_url) self.assertRedirects(response, expected, status_code=302, target_status_code=302) + @unittest.skip def test_jumpto_id(self): 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/' @@ -77,7 +74,7 @@ def test_jumpto_id_invalid_location(self): self.assertEqual(response.status_code, 404) -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class ViewsTestCase(TestCase): """ Tests for views.py methods. @@ -173,6 +170,7 @@ def test_index_invalid_position(self): response = self.client.get(request_url) self.assertEqual(response.status_code, 404) + @unittest.skip def test_unicode_handling_in_url(self): url_parts = [ '/courses', @@ -205,14 +203,17 @@ def test_jump_to_invalid(self): self.assertRaisesRegexp(Http404, 'Invalid course_key or usage_key', views.jump_to, request, 'bar', ()) + @unittest.skip def test_no_end_on_about_page(self): # Toy course has no course end date or about/end_date blob self.verify_end_date('edX/toy/TT_2012_Fall') + @unittest.skip def test_no_end_about_blob(self): # test_end has a course end date, no end_date HTML blob self.verify_end_date("edX/test_end/2012_Fall", "Sep 17, 2015") + @unittest.skip def test_about_blob_end_date(self): # test_about_blob_end_date has both a course end date and an end_date HTML blob. # HTML blob wins @@ -424,7 +425,7 @@ def _email_opt_in_checkbox(self, response, organization_full_name=None): # 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): """ Base class that verifies that due dates are rendered correctly on a page @@ -538,7 +539,7 @@ def get_text(self, course): ) -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class StartDateTests(ModuleStoreTestCase): """ Test that start dates are properly localized and displayed on the student @@ -586,13 +587,14 @@ def test_format_localized_in_studio_course(self): @patch('util.date_utils.ugettext', fake_ugettext(translations={ "SHORT_DATE_FORMAT": "%Y-%b-%d", })) + @unittest.skip def test_format_localized_in_xml_course(self): 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 self.assertIn("2015-JULY-17", text) -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class ProgressPageTests(ModuleStoreTestCase): """ Tests that verify that the progress page works correctly. diff --git a/lms/djangoapps/courseware/tests/tests.py b/lms/djangoapps/courseware/tests/tests.py index dbb17f061fd5..a748f93666ad 100644 --- a/lms/djangoapps/courseware/tests/tests.py +++ b/lms/djangoapps/courseware/tests/tests.py @@ -1,25 +1,21 @@ """ Test for LMS courseware app. """ -import mock -from mock import Mock +from textwrap import dedent from unittest import TestCase + from django.core.urlresolvers import reverse from django.test.utils import override_settings - -from textwrap import dedent - -from xmodule.error_module import ErrorDescriptor -from xmodule.modulestore.django import modulestore +import mock 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.modulestore_config import TEST_DATA_DIR, \ - TEST_DATA_MONGO_MODULESTORE, \ - TEST_DATA_MIXED_MODULESTORE +from xmodule.modulestore.tests.django_utils import TEST_DATA_XML_MODULESTORE as XML_MODULESTORE +from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_TOY_MODULESTORE as TOY_MODULESTORE 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): @@ -116,7 +112,7 @@ def _assert_loads(self, django_url, kwargs, descriptor, self.assertNotIsInstance(descriptor, ErrorDescriptor) -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=XML_MODULESTORE) class TestXmlCoursesLoad(ModuleStoreTestCase, PageLoaderTestCase): """ Check that all pages in test courses load properly from XML. @@ -133,6 +129,7 @@ def test_toy_course_loads(self): self.check_all_pages_load(SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')) +@override_settings(MODULESTORE=TOY_MODULESTORE) class TestMongoCoursesLoad(ModuleStoreTestCase, PageLoaderTestCase): """ Check that all pages in test courses load properly from Mongo. @@ -142,9 +139,6 @@ def setUp(self): super(TestMongoCoursesLoad, self).setUp() 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') def test_toy_textbooks_loads(self, mock_get): mock_get.return_value.text = dedent(""" @@ -183,8 +177,8 @@ def test_lms_field_data_wont_nest(self): # reached on any attribute access # pylint: disable=protected-access - base_authored = Mock() - base_student = Mock() + base_authored = mock.Mock() + base_student = mock.Mock() first_level = LmsFieldData(base_authored, base_student) second_level = LmsFieldData(first_level, base_student) self.assertEquals(second_level._authored_data, first_level._authored_data) diff --git a/lms/djangoapps/dashboard/management/commands/tests/test_git_add_course.py b/lms/djangoapps/dashboard/management/commands/tests/test_git_add_course.py index 06cf8984ffe1..d199a57631f9 100644 --- a/lms/djangoapps/dashboard/management/commands/tests/test_git_add_course.py +++ b/lms/djangoapps/dashboard/management/commands/tests/test_git_add_course.py @@ -12,14 +12,14 @@ from django.core.management import call_command from django.core.management.base import CommandError 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.django import modulestore -from opaque_keys.edx.locations import SlashSeparatedCourseKey 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 @@ -35,7 +35,7 @@ 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) @unittest.skipUnless(settings.FEATURES.get('ENABLE_SYSADMIN_DASHBOARD'), "ENABLE_SYSADMIN_DASHBOARD not set") diff --git a/lms/djangoapps/dashboard/tests/test_support.py b/lms/djangoapps/dashboard/tests/test_support.py index a2173879cf28..61984d185d21 100644 --- a/lms/djangoapps/dashboard/tests/test_support.py +++ b/lms/djangoapps/dashboard/tests/test_support.py @@ -1,23 +1,22 @@ """ 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.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 shoppingcart.models import CertificateItem, Order +from student.models import CourseEnrollment from student.tests.factories import UserFactory from xmodule.modulestore.tests.factories import CourseFactory -import datetime +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -@override_settings( - MODULESTORE=TEST_DATA_MONGO_MODULESTORE -) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class RefundTests(ModuleStoreTestCase): """ Tests for the manual refund page diff --git a/lms/djangoapps/dashboard/tests/test_sysadmin.py b/lms/djangoapps/dashboard/tests/test_sysadmin.py index 7d3ee1022528..a674abee4a8b 100644 --- a/lms/djangoapps/dashboard/tests/test_sysadmin.py +++ b/lms/djangoapps/dashboard/tests/test_sysadmin.py @@ -6,6 +6,7 @@ import re import shutil import unittest +from util.date_utils import get_time_display, DEFAULT_DATE_TIME_FORMAT from django.conf import settings from django.contrib.auth.hashers import check_password @@ -13,26 +14,24 @@ from django.core.urlresolvers import reverse from django.test.client import Client from django.test.utils import override_settings +from django.utils.timezone import utc as UTC from django.utils.translation import ugettext as _ import mongoengine -from django.utils.timezone import utc as UTC -from util.date_utils import get_time_display, DEFAULT_DATE_TIME_FORMAT +from opaque_keys.edx.locations import SlashSeparatedCourseKey -from student.roles import CourseStaffRole, GlobalStaff -from courseware.tests.modulestore_config import TEST_DATA_DIR +from xmodule.modulestore.tests.django_utils import ( + TEST_DATA_MOCK_MODULESTORE, TEST_DATA_XML_MODULESTORE +) from dashboard.models import CourseImportLog from dashboard.sysadmin import Users from dashboard.git_import import GitImportError from external_auth.models import ExternalAuthMap +from student.roles import CourseStaffRole, GlobalStaff from student.tests.factories import UserFactory from xmodule.modulestore.django import modulestore 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.django_utils import xml_store_config -TEST_DATA_XML_MODULESTORE = xml_store_config(TEST_DATA_DIR, ['empty']) +from xmodule.modulestore.xml import XMLModuleStore TEST_MONGODB_LOG = { @@ -406,6 +405,7 @@ def test_enrollment_page(self): @override_settings(MONGODB_LOG=TEST_MONGODB_LOG) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) @unittest.skipUnless(settings.FEATURES.get('ENABLE_SYSADMIN_DASHBOARD'), "ENABLE_SYSADMIN_DASHBOARD not set") class TestSysAdminMongoCourseImport(SysadminBaseTestCase): diff --git a/lms/djangoapps/django_comment_client/base/tests.py b/lms/djangoapps/django_comment_client/base/tests.py index 3595eef34833..41a8ce5ff010 100644 --- a/lms/djangoapps/django_comment_client/base/tests.py +++ b/lms/djangoapps/django_comment_client/base/tests.py @@ -10,7 +10,7 @@ from nose.tools import assert_true, assert_equal # pylint: disable=no-name-in-module 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.tests.group_id import CohortedTopicGroupIdTestMixin, NonCohortedTopicGroupIdTestMixin, GroupIdAssertionMixin from django_comment_client.tests.utils import CohortedContentTestCase @@ -162,7 +162,7 @@ def test_openclose(self, mock_request): ) -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) @patch('lms.lib.comment_client.utils.requests.request') class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSetupMixin): @@ -750,7 +750,7 @@ def un_flag_comment(self, mock_request, is_closed): @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): @patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) def setUp(self): @@ -844,7 +844,7 @@ def test_endorse_response_as_student_question_author(self, mock_request): 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): def setUp(self): self.course = CourseFactory.create() @@ -866,7 +866,7 @@ def _test_unicode_data(self, text, mock_request): 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): def setUp(self): self.course = CourseFactory.create() @@ -894,7 +894,7 @@ def _test_unicode_data(self, text, mock_request, mock_get_discussion_id_map): 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): def setUp(self): self.course = CourseFactory.create() @@ -917,7 +917,7 @@ def _test_unicode_data(self, text, mock_request): 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): def setUp(self): self.course = CourseFactory.create() @@ -941,7 +941,7 @@ def _test_unicode_data(self, text, mock_request): 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): def setUp(self): self.course = CourseFactory.create() @@ -965,7 +965,7 @@ def _test_unicode_data(self, text, mock_request): 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): def set_post_counts(self, mock_request, threads_count=1, comments_count=1): diff --git a/lms/djangoapps/django_comment_client/forum/tests.py b/lms/djangoapps/django_comment_client/forum/tests.py index 9a2d3b54c0fd..5563202ba0ce 100644 --- a/lms/djangoapps/django_comment_client/forum/tests.py +++ b/lms/djangoapps/django_comment_client/forum/tests.py @@ -1,39 +1,35 @@ import json import logging +from django.core.urlresolvers import reverse from django.http import Http404 -from django.test.utils import override_settings from django.test.client import Client, RequestFactory -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory -from student.tests.factories import UserFactory, CourseEnrollmentFactory +from django.test.utils import override_settings from edxmako.tests import mako_middleware_process_request -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, mixed_store_config -from django.core.urlresolvers import reverse -from util.testing import UrlResetMixin +from mock import patch, Mock, ANY, call +from nose.tools import assert_true # pylint: disable=no-name-in-module + +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 ( CohortedTopicGroupIdTestMixin, NonCohortedTopicGroupIdTestMixin ) from django_comment_client.tests.unicode import UnicodeTestMixin from django_comment_client.tests.utils import CohortedContentTestCase -from django_comment_client.forum import views from django_comment_client.utils import strip_none - -from courseware.tests.modulestore_config import TEST_DATA_DIR -from courseware.courses import UserNotEnrolled -from nose.tools import assert_true # pylint: disable=no-name-in-module -from mock import patch, Mock, ANY, call - -from course_groups.models import CourseUserGroup - -TEST_DATA_MONGO_MODULESTORE = mixed_store_config(TEST_DATA_DIR, {}, include_xml=False) +from student.tests.factories import UserFactory, CourseEnrollmentFactory +from util.testing import UrlResetMixin +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 log = logging.getLogger(__name__) # pylint: disable=missing-docstring - -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class ViewsExceptionTestCase(UrlResetMixin, ModuleStoreTestCase): @patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) @@ -171,7 +167,7 @@ def __eq__(self, other): ]) -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) @patch('requests.request') class SingleThreadTestCase(ModuleStoreTestCase): def setUp(self): @@ -280,7 +276,7 @@ def test_not_found(self, mock_request): ) -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) @patch('requests.request') class SingleCohortedThreadTestCase(CohortedContentTestCase): def _create_mock_cohorted_thread(self, mock_request): @@ -773,7 +769,7 @@ def test_group_info_in_ajax_response(self, mock_request): ) -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class InlineDiscussionTestCase(ModuleStoreTestCase): def setUp(self): self.course = CourseFactory.create(org="TestX", number="101", display_name="Test Course") @@ -803,7 +799,7 @@ def test_courseware_data(self, mock_request): 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') class UserProfileTestCase(ModuleStoreTestCase): @@ -915,7 +911,7 @@ def test_post(self, mock_request): self.assertEqual(response.status_code, 405) -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) @patch('requests.request') class CommentsServiceRequestHeadersTestCase(UrlResetMixin, ModuleStoreTestCase): @patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) @@ -976,7 +972,7 @@ def test_api_key(self, mock_request): 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): def setUp(self): self.course = CourseFactory.create() @@ -996,7 +992,7 @@ def _test_unicode_data(self, text, mock_request): 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): def setUp(self): self.course = CourseFactory.create() @@ -1017,7 +1013,7 @@ def _test_unicode_data(self, text, mock_request): 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): def setUp(self): self.course = CourseFactory.create() @@ -1042,7 +1038,7 @@ def _test_unicode_data(self, text, mock_request): 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): def setUp(self): self.course = CourseFactory.create() @@ -1064,7 +1060,7 @@ def _test_unicode_data(self, text, mock_request): 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): def setUp(self): self.course = CourseFactory.create() @@ -1085,7 +1081,7 @@ def _test_unicode_data(self, text, mock_request): 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): def setUp(self): self.course = CourseFactory.create() @@ -1106,7 +1102,7 @@ def _test_unicode_data(self, text, mock_request): 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): """ Tests for the behavior of views depending on if the student is enrolled diff --git a/lms/djangoapps/django_comment_client/tests/test_models.py b/lms/djangoapps/django_comment_client/tests/test_models.py index fd4955c80a86..ad844767d031 100644 --- a/lms/djangoapps/django_comment_client/tests/test_models.py +++ b/lms/djangoapps/django_comment_client/tests/test_models.py @@ -1,13 +1,20 @@ -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 courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE - 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): # For course ID, syntax edx/classname/classdate is important # because xmodel.course_module.id_to_location looks for a string to split @@ -28,7 +35,7 @@ class Dummy(): def render_template(): pass - def testHasPermission(self): + def test_has_permission(self): # Whenever you add a permission to student_role, # Roles with the same FORUM_ROLE in same class also receives the same # permission. @@ -37,8 +44,7 @@ def testHasPermission(self): self.assertTrue(self.student_2_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.assertTrue(self.TA_role.has_permission("delete_thread")) # Despite being from 2 different courses, TA_role_2 can still inherit @@ -47,8 +53,11 @@ def testInheritPermissions(self): class PermissionClassTestCase(TestCase): + """ + Tests for permissions of the comment client service integration + """ def setUp(self): self.permission = models.Permission.objects.get_or_create(name="test")[0] - def testUnicode(self): + def test_unicode(self): self.assertEqual(str(self.permission), "test") diff --git a/lms/djangoapps/django_comment_client/tests/test_utils.py b/lms/djangoapps/django_comment_client/tests/test_utils.py index 50ffbe638190..949f7eb056de 100644 --- a/lms/djangoapps/django_comment_client/tests/test_utils.py +++ b/lms/djangoapps/django_comment_client/tests/test_utils.py @@ -1,20 +1,21 @@ # -*- coding: utf-8 -*- - -import json -import mock from datetime import datetime +import json from pytz import UTC + from django.core.urlresolvers import reverse from django.test import TestCase 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.unicode import UnicodeTestMixin 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.django_utils import ModuleStoreTestCase -from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE -from edxmako import add_lookup class DictionaryTestCase(TestCase): @@ -41,8 +42,12 @@ def test_merge_dict(self): 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): + """ + Base testcase class for access and roles for the + comment client service integration + """ def setUp(self): self.course = CourseFactory.create() self.course_id = self.course.id @@ -78,8 +83,12 @@ def test_has_forum_access(self): self.assertFalse(ret) -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class CoursewareContextTestCase(ModuleStoreTestCase): + """ + Base testcase class for courseware context for the + comment client service integration + """ def setUp(self): self.course = CourseFactory.create(org="TestX", number="101", display_name="Test Course") self.discussion1 = ItemFactory.create( @@ -135,8 +144,12 @@ def assertThreadCorrect(thread, discussion, expected_title): # pylint: disable= 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): + """ + Base testcase class for discussion categories for the + comment client service integration + """ def setUp(self): self.course = CourseFactory.create( org="TestX", number="101", display_name="Test Course", diff --git a/lms/djangoapps/django_comment_client/tests/utils.py b/lms/djangoapps/django_comment_client/tests/utils.py index 38b4c48e6d1a..8afde0a02147 100644 --- a/lms/djangoapps/django_comment_client/tests/utils.py +++ b/lms/djangoapps/django_comment_client/tests/utils.py @@ -1,16 +1,16 @@ from django.test.utils import override_settings +from mock import patch 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.utils import seed_permissions_roles -from mock import patch from student.tests.factories import CourseEnrollmentFactory, UserFactory from xmodule.modulestore.tests.factories import CourseFactory 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): """ Sets up a course with a student, a moderator and their cohorts. diff --git a/lms/djangoapps/instructor/management/tests/test_openended_commands.py b/lms/djangoapps/instructor/management/tests/test_openended_commands.py index 8e83e5489147..b1d0efcaa50b 100644 --- a/lms/djangoapps/instructor/management/tests/test_openended_commands.py +++ b/lms/djangoapps/instructor/management/tests/test_openended_commands.py @@ -5,34 +5,41 @@ from mock import patch from pytz import UTC +from django.conf import settings from django.test.utils import override_settings +from opaque_keys.edx.locations import Location 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 TEST_DATA_MOCK_MODULESTORE +from xmodule.modulestore.xml_importer import import_from_xml from xmodule.open_ended_grading_classes.openendedchild import OpenEndedChild from xmodule.tests.test_util_open_ended import ( 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 instructor.management.commands.openended_post import post_submission_for_student from instructor.management.commands.openended_stats import calculate_task_statistics 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): """Test the openended_post management command.""" 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.self_assessment_task_number = 0 self.open_ended_task_number = 1 @@ -87,7 +94,7 @@ def test_post_submission_for_student_on_accessing(self): mock_send_to_queue.return_value = (0, "Successfully queued") 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_anonymous_id = anonymous_id_for_user(self.student_on_accessing, None) @@ -123,12 +130,17 @@ def test_post_submission_for_student_invalid_task(self): self.assertFalse(result) -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class OpenEndedStatsTest(ModuleStoreTestCase): """Test the openended_stats management command.""" 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.task_number = 1 self.invalid_task_number = 3 diff --git a/lms/djangoapps/instructor/tests/test_access.py b/lms/djangoapps/instructor/tests/test_access.py index 499a5c7158f4..0bb0b891fa42 100644 --- a/lms/djangoapps/instructor/tests/test_access.py +++ b/lms/djangoapps/instructor/tests/test_access.py @@ -8,7 +8,7 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase 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 django_comment_common.models import (Role, @@ -19,7 +19,7 @@ update_forum_role) -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestInstructorAccessList(ModuleStoreTestCase): """ Test access listings. """ def setUp(self): @@ -41,7 +41,7 @@ def test_list_beta(self): 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): """ Test access allow. """ def setUp(self): @@ -75,7 +75,7 @@ def test_allow_noneuser(self): allow_access(self.course, user, 'staff') -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestInstructorAccessRevoke(ModuleStoreTestCase): """ Test access revoke. """ def setUp(self): @@ -109,7 +109,7 @@ def test_revoke_badrolename(self): 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): """ Test forum access control. diff --git a/lms/djangoapps/instructor/tests/test_api.py b/lms/djangoapps/instructor/tests/test_api.py index c2fc7c465ec3..a9e670162228 100644 --- a/lms/djangoapps/instructor/tests/test_api.py +++ b/lms/djangoapps/instructor/tests/test_api.py @@ -2,58 +2,57 @@ """ Unit tests for instructor.api methods. """ - -import unittest -import json -import requests import datetime import ddt -import random import io +import json +import random +import requests +from unittest import TestCase 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.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.http import HttpRequest, HttpResponse -from django_comment_common.models import FORUM_ROLE_COMMUNITY_TA -from django_comment_common.utils import seed_permissions_roles -from django.core import mail +from django.test import RequestFactory, TestCase +from django.test.utils import override_settings from django.utils.timezone import utc -from django.test import RequestFactory -from django.contrib.auth.models import User -from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from mock import Mock, patch +from nose.tools import raises +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 xmodule.modulestore.tests.factories import CourseFactory, ItemFactory -from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.django import modulestore +from django_comment_common.models import FORUM_ROLE_COMMUNITY_TA +from django_comment_common.utils import seed_permissions_roles +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 courseware.tests.factories import StaffFactory, InstructorFactory, BetaTesterFactory from student.roles import CourseBetaTesterRole -from microsite_configuration import microsite -from instructor.tests.utils import FakeContentTask, FakeEmail, FakeEmailInfo - -from student.models import CourseEnrollment, CourseEnrollmentAllowed -from courseware.models import StudentModule +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 CourseFactory, ItemFactory -# modules which are mocked in test cases. import instructor_task.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 _split_input_list, common_exceptions_400 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 ..views.tools import get_extended_due @@ -96,7 +95,7 @@ def view_alreadyrunningerror(request): # pylint: disable=unused-argument raise AlreadyRunningError() -class TestCommonExceptions400(unittest.TestCase): +class TestCommonExceptions400(TestCase): """ Testing the common_exceptions_400 decorator. """ @@ -136,7 +135,7 @@ def test_alreadyrunningerror_ajax(self): 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}) class TestInstructorAPIDenyLevels(ModuleStoreTestCase, LoginEnrollmentTestCase): """ @@ -291,7 +290,7 @@ def test_instructor_level(self): ) -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) @patch.dict(settings.FEATURES, {'ALLOW_AUTOMATED_SIGNUPS': True}) class TestInstructorAPIBulkAccountCreationAndEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase): """ @@ -528,7 +527,7 @@ def test_allow_automated_signups_flag_not_set(self): @ddt.ddt -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestInstructorAPIEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase): """ Test enrollment modification endpoint. @@ -1084,7 +1083,7 @@ def test_enroll_already_enrolled_student(self): @ddt.ddt -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestInstructorAPIBulkBetaEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase): """ Test bulk beta modify access endpoint. @@ -1397,7 +1396,7 @@ def test_remove_with_email(self): ) -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestInstructorAPILevelsAccess(ModuleStoreTestCase, LoginEnrollmentTestCase): """ Test endpoints whereby instructors can change permissions @@ -1635,7 +1634,7 @@ def assert_update_forum_role_membership(self, current_user, identifier, rolename @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}) class TestInstructorAPILevelsDataDump(ModuleStoreTestCase, LoginEnrollmentTestCase): """ @@ -2079,7 +2078,7 @@ def test_get_student_progress_url_nostudent(self): self.assertEqual(response.status_code, 400) -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestInstructorAPIRegradeTask(ModuleStoreTestCase, LoginEnrollmentTestCase): """ Test endpoints whereby instructors can change student grades. @@ -2219,7 +2218,7 @@ def test_rescore_problem_all(self, act): 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}) class TestInstructorSendEmail(ModuleStoreTestCase, LoginEnrollmentTestCase): """ @@ -2301,7 +2300,7 @@ def mock_get_task_completion_info(self, *args): # pylint: disable=unused-argume 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): """ Test instructor task list endpoint. @@ -2463,7 +2462,7 @@ def test_list_instructor_tasks_problem_student(self, act): 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') class TestInstructorEmailContentList(ModuleStoreTestCase, LoginEnrollmentTestCase): """ @@ -2599,7 +2598,7 @@ def test_list_email_with_no_successes(self, task_history_request): @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_API_KEY="robot_api_key") class TestInstructorAPIAnalyticsProxy(ModuleStoreTestCase, LoginEnrollmentTestCase): @@ -2781,7 +2780,7 @@ def test_msk_from_problem_urlname_error(self): msk_from_problem_urlname(*args) -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestDueDateExtensions(ModuleStoreTestCase, LoginEnrollmentTestCase): """ Test data dumps for reporting. @@ -2970,7 +2969,7 @@ def test_show_student_extensions(self): 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) class TestCourseRegistrationCodes(ModuleStoreTestCase): """ diff --git a/lms/djangoapps/instructor/tests/test_ecommerce.py b/lms/djangoapps/instructor/tests/test_ecommerce.py index cb0dba349390..7b146cb3a959 100644 --- a/lms/djangoapps/instructor/tests/test_ecommerce.py +++ b/lms/djangoapps/instructor/tests/test_ecommerce.py @@ -2,21 +2,20 @@ 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.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 xmodule.modulestore.tests.django_utils import ModuleStoreTestCase 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): """ Check for E-commerce view on the new instructor dashboard diff --git a/lms/djangoapps/instructor/tests/test_email.py b/lms/djangoapps/instructor/tests/test_email.py index 8fd3288bd46a..f51e991b4147 100644 --- a/lms/djangoapps/instructor/tests/test_email.py +++ b/lms/djangoapps/instructor/tests/test_email.py @@ -4,24 +4,20 @@ non-Mongo backed courses, regardless of email feature flag, and 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.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 xmodule.modulestore.tests.django_utils import ModuleStoreTestCase 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): """ Check for email view on the new instructor dashboard @@ -110,7 +106,7 @@ def test_course_authorized_feature_off(self): 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): """ Check for email view on the new instructor dashboard diff --git a/lms/djangoapps/instructor/tests/test_enrollment.py b/lms/djangoapps/instructor/tests/test_enrollment.py index 548491256438..e1201629f103 100644 --- a/lms/djangoapps/instructor/tests/test_enrollment.py +++ b/lms/djangoapps/instructor/tests/test_enrollment.py @@ -11,7 +11,7 @@ from django.test.utils import override_settings from student.tests.factories import UserFactory 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 instructor.enrollment import ( @@ -286,7 +286,7 @@ def test_unenroll_norecord(self): 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): """ Test student module manipulations. """ def setUp(self): @@ -431,7 +431,7 @@ def test_bad_action(self): 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): """ Test what URLs the function get_email_params returns under different diff --git a/lms/djangoapps/instructor/tests/test_hint_manager.py b/lms/djangoapps/instructor/tests/test_hint_manager.py index fb35f75ab9bd..cca276813326 100644 --- a/lms/djangoapps/instructor/tests/test_hint_manager.py +++ b/lms/djangoapps/instructor/tests/test_hint_manager.py @@ -6,7 +6,7 @@ from courseware.models import XModuleUserStateSummaryField 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 from student.tests.factories import UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase @@ -15,7 +15,7 @@ # pylint: disable=missing-docstring -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class HintManagerTest(ModuleStoreTestCase): def setUp(self): diff --git a/lms/djangoapps/instructor/tests/test_legacy_anon_csv.py b/lms/djangoapps/instructor/tests/test_legacy_anon_csv.py index 68ad6a64f0a4..2f298f76dd05 100644 --- a/lms/djangoapps/instructor/tests/test_legacy_anon_csv.py +++ b/lms/djangoapps/instructor/tests/test_legacy_anon_csv.py @@ -16,7 +16,7 @@ from django.core.urlresolvers import reverse 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 from student.roles import CourseStaffRole from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase @@ -25,7 +25,7 @@ from mock import Mock, patch -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestInstructorDashboardAnonCSV(ModuleStoreTestCase, LoginEnrollmentTestCase): ''' Check for download of csv diff --git a/lms/djangoapps/instructor/tests/test_legacy_download_csv.py b/lms/djangoapps/instructor/tests/test_legacy_download_csv.py index 55704e3a3993..94f1648e7610 100644 --- a/lms/djangoapps/instructor/tests/test_legacy_download_csv.py +++ b/lms/djangoapps/instructor/tests/test_legacy_download_csv.py @@ -16,13 +16,13 @@ from django.core.urlresolvers import reverse 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 xmodule.modulestore.tests.django_utils import ModuleStoreTestCase 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): ''' Check for download of csv diff --git a/lms/djangoapps/instructor/tests/test_legacy_email.py b/lms/djangoapps/instructor/tests/test_legacy_email.py index 2d7942b4c1ed..a740a2ef1553 100644 --- a/lms/djangoapps/instructor/tests/test_legacy_email.py +++ b/lms/djangoapps/instructor/tests/test_legacy_email.py @@ -7,8 +7,9 @@ from django.test.utils import override_settings from django.conf import settings 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 xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory @@ -16,10 +17,8 @@ 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): """ Check for email view displayed with flag diff --git a/lms/djangoapps/instructor/tests/test_legacy_enrollment.py b/lms/djangoapps/instructor/tests/test_legacy_enrollment.py index bb7eb1774841..a36374b3eed2 100644 --- a/lms/djangoapps/instructor/tests/test_legacy_enrollment.py +++ b/lms/djangoapps/instructor/tests/test_legacy_enrollment.py @@ -10,7 +10,7 @@ from django.contrib.auth.models import User from django.core.urlresolvers import reverse 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 student.tests.factories import UserFactory, CourseEnrollmentFactory, AdminFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase @@ -22,7 +22,7 @@ @ddt.ddt -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestInstructorEnrollsStudent(ModuleStoreTestCase, LoginEnrollmentTestCase): """ Check Enrollment/Unenrollment with/without auto-enrollment on activation and with/without email notification diff --git a/lms/djangoapps/instructor/tests/test_legacy_forum_admin.py b/lms/djangoapps/instructor/tests/test_legacy_forum_admin.py index a51f9db51800..be323c9eac5a 100644 --- a/lms/djangoapps/instructor/tests/test_legacy_forum_admin.py +++ b/lms/djangoapps/instructor/tests/test_legacy_forum_admin.py @@ -14,7 +14,7 @@ from django_comment_client.utils import has_forum_access 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 xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory @@ -32,7 +32,7 @@ def action_name(operation, 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): ''' Check for change in forum admin role memberships diff --git a/lms/djangoapps/instructor/tests/test_legacy_reset.py b/lms/djangoapps/instructor/tests/test_legacy_reset.py index ecdd4ed5dff5..de2d51851a61 100644 --- a/lms/djangoapps/instructor/tests/test_legacy_reset.py +++ b/lms/djangoapps/instructor/tests/test_legacy_reset.py @@ -8,7 +8,7 @@ from courseware.tests.helpers import LoginEnrollmentTestCase 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 student.tests.factories import UserFactory, AdminFactory, CourseEnrollmentFactory @@ -18,7 +18,7 @@ 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): """ Reset student state from the legacy instructor dash. diff --git a/lms/djangoapps/instructor/tests/test_legacy_xss.py b/lms/djangoapps/instructor/tests/test_legacy_xss.py index 58bbf9076531..fb5302edf6db 100644 --- a/lms/djangoapps/instructor/tests/test_legacy_xss.py +++ b/lms/djangoapps/instructor/tests/test_legacy_xss.py @@ -7,7 +7,7 @@ from django.test.utils import override_settings 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 edxmako.tests import mako_middleware_process_request from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase @@ -18,7 +18,7 @@ # pylint: disable=missing-docstring -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestXss(ModuleStoreTestCase): def setUp(self): self._request_factory = RequestFactory() diff --git a/lms/djangoapps/instructor/tests/test_spoc_gradebook.py b/lms/djangoapps/instructor/tests/test_spoc_gradebook.py index d6a46d90047f..38fd1e8a427e 100644 --- a/lms/djangoapps/instructor/tests/test_spoc_gradebook.py +++ b/lms/djangoapps/instructor/tests/test_spoc_gradebook.py @@ -7,7 +7,7 @@ from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from student.tests.factories import UserFactory, CourseEnrollmentFactory, AdminFactory 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 courseware.tests.factories import StudentModuleFactory from xmodule.modulestore.django import modulestore @@ -16,7 +16,7 @@ USER_COUNT = 11 -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestGradebook(ModuleStoreTestCase): """ Test functionality of the spoc gradebook. Sets up a course with assignments and diff --git a/lms/djangoapps/instructor/tests/test_tools.py b/lms/djangoapps/instructor/tests/test_tools.py index b8cdc0b7bd14..6c6c96e88b7c 100644 --- a/lms/djangoapps/instructor/tests/test_tools.py +++ b/lms/djangoapps/instructor/tests/test_tools.py @@ -12,7 +12,7 @@ from django.utils.timezone import utc 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 xmodule.fields import Date from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase @@ -97,7 +97,7 @@ def test_parse_error(self): tools.parse_datetime('foo') -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestFindUnit(ModuleStoreTestCase): """ Test the find_unit function. @@ -130,7 +130,7 @@ def test_find_unit_notfound(self): tools.find_unit(self.course, url) -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestGetUnitsWithDueDate(ModuleStoreTestCase): """ Test the get_units_with_due_date function. @@ -178,7 +178,7 @@ def test_url(self): 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): """ Test the set_due_date_extensions function. @@ -252,7 +252,7 @@ def test_reset_due_date_extension(self): 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): """ Test data dumps for reporting. diff --git a/lms/djangoapps/instructor_task/tests/test_api.py b/lms/djangoapps/instructor_task/tests/test_api.py index e70d9650be5e..961c3b3dc012 100644 --- a/lms/djangoapps/instructor_task/tests/test_api.py +++ b/lms/djangoapps/instructor_task/tests/test_api.py @@ -1,12 +1,10 @@ """ Test for LMS instructor background task queue management """ - -from xmodule.modulestore.exceptions import ItemNotFoundError - +from bulk_email.models import CourseEmail, SEND_TO_ALL 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 ( get_running_instructor_tasks, get_instructor_task_history, diff --git a/lms/djangoapps/instructor_task/tests/test_base.py b/lms/djangoapps/instructor_task/tests/test_base.py index 78b63a3ff464..1ce6eff9e8a0 100644 --- a/lms/djangoapps/instructor_task/tests/test_base.py +++ b/lms/djangoapps/instructor_task/tests/test_base.py @@ -3,29 +3,27 @@ """ import os -import shutil - import json -from uuid import uuid4 from mock import Mock +import shutil +from uuid import uuid4 from celery.states import SUCCESS, FAILURE - from django.conf import settings from django.test.testcases import TestCase from django.contrib.auth.models import User from django.test.utils import override_settings +from opaque_keys.edx.locations import Location, SlashSeparatedCourseKey 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.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 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.models import PROGRESS, QUEUING @@ -99,7 +97,7 @@ def _create_progress_entry(self, student=None, task_state=PROGRESS): 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): """ Base test class for InstructorTask-related tests that require @@ -184,7 +182,7 @@ def create_task_request(self, requester_username): return request -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class InstructorTaskModuleTestCase(InstructorTaskCourseTestCase): """ Base test class for InstructorTask-related tests that require diff --git a/lms/djangoapps/instructor_task/tests/test_integration.py b/lms/djangoapps/instructor_task/tests/test_integration.py index a4ce56c3b940..5d386ddb92cc 100644 --- a/lms/djangoapps/instructor_task/tests/test_integration.py +++ b/lms/djangoapps/instructor_task/tests/test_integration.py @@ -6,8 +6,8 @@ """ import csv -import logging import json +import logging from mock import patch import textwrap diff --git a/lms/djangoapps/licenses/tests.py b/lms/djangoapps/licenses/tests.py index ef99ff501b06..777d2f074328 100644 --- a/lms/djangoapps/licenses/tests.py +++ b/lms/djangoapps/licenses/tests.py @@ -15,7 +15,7 @@ from django.core.urlresolvers import reverse 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 student.tests.factories import UserFactory @@ -144,7 +144,7 @@ def test_get_license_without_login(self): self.assertEqual(302, response.status_code) -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class CommandTest(ModuleStoreTestCase): '''Test management command for importing serial numbers''' def setUp(self): diff --git a/lms/djangoapps/mobile_api/course_info/tests.py b/lms/djangoapps/mobile_api/course_info/tests.py index e46d8f0ee625..d1a6f7c9ccaf 100644 --- a/lms/djangoapps/mobile_api/course_info/tests.py +++ b/lms/djangoapps/mobile_api/course_info/tests.py @@ -4,13 +4,14 @@ from django.test.utils import override_settings from django.core.urlresolvers import reverse 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.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): """ Tests for /api/mobile/v0.5/course_info/... diff --git a/lms/djangoapps/mobile_api/video_outlines/tests.py b/lms/djangoapps/mobile_api/video_outlines/tests.py index ddbc547c5e4e..ffc0303bc2dc 100644 --- a/lms/djangoapps/mobile_api/video_outlines/tests.py +++ b/lms/djangoapps/mobile_api/video_outlines/tests.py @@ -1,31 +1,31 @@ """ Tests for video outline API """ - +import copy 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.test.utils import override_settings from django.conf import settings -from rest_framework.test import APITestCase -from mobile_api.tests import ROLE_CASES 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['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex @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): """ Tests for /api/mobile/v0.5/video_outlines/ diff --git a/lms/djangoapps/notifier_api/tests.py b/lms/djangoapps/notifier_api/tests.py index 69733ae7ad54..50057813428c 100644 --- a/lms/djangoapps/notifier_api/tests.py +++ b/lms/djangoapps/notifier_api/tests.py @@ -16,7 +16,7 @@ from user_api.models import UserPreference from user_api.tests.factories import UserPreferenceFactory 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 diff --git a/lms/djangoapps/oauth2_handler/tests.py b/lms/djangoapps/oauth2_handler/tests.py index 033c29dbb557..30696810fc4d 100644 --- a/lms/djangoapps/oauth2_handler/tests.py +++ b/lms/djangoapps/oauth2_handler/tests.py @@ -1,23 +1,22 @@ # pylint: disable=missing-docstring from django.core.cache import cache from django.test.utils import override_settings - -from courseware.tests.tests import TEST_DATA_MIXED_MODULESTORE from lang_pref import LANGUAGE_KEY 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 UserProfile from student.roles import CourseStaffRole, CourseInstructorRole from student.tests.factories import UserFactory, UserProfileFactory from user_api.models import UserPreference +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # Will also run default tests for IDTokens and UserInfo 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): profile = None diff --git a/lms/djangoapps/open_ended_grading/tests.py b/lms/djangoapps/open_ended_grading/tests.py index 0f246324dc02..85ae8e425857 100644 --- a/lms/djangoapps/open_ended_grading/tests.py +++ b/lms/djangoapps/open_ended_grading/tests.py @@ -3,7 +3,6 @@ ./manage.py lms --settings test test lms/djangoapps/open_ended_grading """ -from django.test import RequestFactory import json import logging @@ -11,30 +10,36 @@ from django.conf import settings from django.contrib.auth.models import User from django.core.urlresolvers import reverse +from django.test import RequestFactory 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 opaque_keys.edx.locations import SlashSeparatedCourseKey from xblock.field_data import DictFieldData 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.error_module import ErrorDescriptor 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 ( + 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.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 +TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT + + log = logging.getLogger(__name__) @@ -99,7 +104,7 @@ def get_grading_status_list(self, *args, **kwargs): } -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MIXED_TOY_MODULESTORE) class TestStaffGradingService(ModuleStoreTestCase, LoginEnrollmentTestCase): ''' Check that staff grading service proxy works. Basically just checking the @@ -252,7 +257,7 @@ def test_save_grade_with_long_feedback(self): ) -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestPeerGradingService(ModuleStoreTestCase, LoginEnrollmentTestCase): ''' Check that staff grading service proxy works. Basically just checking the @@ -439,17 +444,17 @@ def test_save_grade_with_long_feedback(self): ) -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestPanel(ModuleStoreTestCase): """ Run tests on the open ended panel """ - 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() + 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): """ @@ -483,15 +488,17 @@ def test_problem_list(self): 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): """ Test to see if peer grading modules can be found properly. """ - def setUp(self): - self.course_key = SlashSeparatedCourseKey('edX', 'open_ended_nopath', '2012_Fall') - self.course = modulestore().get_course(self.course_key) + self.user = factories.UserFactory() + 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): """ @@ -503,17 +510,19 @@ def test_peer_grading_nopath(self): self.assertEqual(found, False) -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestStudentProblemList(ModuleStoreTestCase): """ Test if the student problem list correctly fetches and parses problems. """ - def setUp(self): # 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() + 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. make_instructor(self.course, self.user.email) diff --git a/lms/djangoapps/shoppingcart/tests/test_context_processor.py b/lms/djangoapps/shoppingcart/tests/test_context_processor.py index c7be12d86e51..503d7964ebf5 100644 --- a/lms/djangoapps/shoppingcart/tests/test_context_processor.py +++ b/lms/djangoapps/shoppingcart/tests/test_context_processor.py @@ -1,21 +1,22 @@ """ Unit tests for shoppingcart context_processor """ -from mock import patch, Mock from django.conf import settings from django.contrib.auth.models import AnonymousUser 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.factories import CourseFactory -from student.tests.factories import UserFactory -from course_modes.tests.factories import CourseModeFactory + from shoppingcart.models import Order, PaidCourseRegistration 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): """ Unit test for shoppingcart context_processor diff --git a/lms/djangoapps/shoppingcart/tests/test_reports.py b/lms/djangoapps/shoppingcart/tests/test_reports.py index 80402d33004f..8a83d34e2b25 100644 --- a/lms/djangoapps/shoppingcart/tests/test_reports.py +++ b/lms/djangoapps/shoppingcart/tests/test_reports.py @@ -3,16 +3,16 @@ """ Tests for the Shopping Cart Models """ +import datetime +import pytz import StringIO from textwrap import dedent -import pytz -import datetime from django.conf import settings from django.test.utils import override_settings 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, CourseRegCodeItemAnnotation) from shoppingcart.views import initialize_report @@ -22,7 +22,7 @@ from xmodule.modulestore.tests.factories import CourseFactory -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class ReportTypeTests(ModuleStoreTestCase): """ Tests for the models used to generate certificate status reports @@ -179,7 +179,7 @@ def test_basic_uni_revenue_share_csv(self): 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): """ Tests for the models used to generate itemized purchase reports diff --git a/lms/djangoapps/staticbook/tests.py b/lms/djangoapps/staticbook/tests.py index a611f37874a6..59ee4a6e02e1 100644 --- a/lms/djangoapps/staticbook/tests.py +++ b/lms/djangoapps/staticbook/tests.py @@ -10,7 +10,7 @@ from django.test.utils import override_settings 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 xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase @@ -46,7 +46,7 @@ } -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class StaticBookTest(ModuleStoreTestCase): """ Helpers for the static book tests. diff --git a/lms/djangoapps/verify_student/tests/test_models.py b/lms/djangoapps/verify_student/tests/test_models.py index 77175081268e..03fff8d3eff2 100644 --- a/lms/djangoapps/verify_student/tests/test_models.py +++ b/lms/djangoapps/verify_student/tests/test_models.py @@ -1,23 +1,25 @@ # -*- coding: utf-8 -*- from datetime import timedelta, datetime import json -from xmodule.modulestore.tests.factories import CourseFactory -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 requests.exceptions import pytz + +from django.conf import settings from django.test import TestCase -from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from django.test.utils import override_settings -from django.conf import settings -import requests.exceptions +from mock import patch +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 xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory + from verify_student.models import ( SoftwareSecurePhotoVerification, VerificationException, ) -from reverification.tests.factories import MidcourseReverificationWindowFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase FAKE_SETTINGS = { "SOFTWARE_SECURE": { @@ -418,7 +420,7 @@ def test_parse_error_msg_failure(self): 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('verify_student.models.S3Connection', new=MockS3Connection) @patch('verify_student.models.Key', new=MockKey) diff --git a/lms/djangoapps/verify_student/tests/test_ssencrypt.py b/lms/djangoapps/verify_student/tests/test_ssencrypt.py index c2a6c3646fee..1bfef319c01d 100644 --- a/lms/djangoapps/verify_student/tests/test_ssencrypt.py +++ b/lms/djangoapps/verify_student/tests/test_ssencrypt.py @@ -1,5 +1,4 @@ import base64 - from nose.tools import assert_equals from verify_student.ssencrypt import ( @@ -7,7 +6,6 @@ rsa_decrypt, rsa_encrypt, random_aes_key ) - def test_aes(): key_str = "32fe72aaf2abb44de9e161131b5435c8d37cbdb6f5df242ae860b283115f2dae" key = key_str.decode("hex") @@ -29,7 +27,6 @@ def assert_roundtrip(text): assert_roundtrip("") assert_roundtrip("\xe9\xe1a\x13\x1bT5\xc8") # Random, non-ASCII text - def test_rsa(): # Make up some garbage keys for testing purposes. pub_key_str = """-----BEGIN PUBLIC KEY----- From 121b31309d69c0a7b77589af754f819b154f8c15 Mon Sep 17 00:00:00 2001 From: Jesse Zoldak Date: Mon, 1 Dec 2014 14:29:22 -0500 Subject: [PATCH 2/2] Small fixes to modulestore test refactoring --- common/djangoapps/external_auth/tests/test_ssl.py | 2 +- .../lib/xmodule/xmodule/modulestore/tests/django_utils.py | 7 ++++--- lms/djangoapps/courseware/tests/test_masquerade.py | 2 +- lms/djangoapps/courseware/tests/test_module_render.py | 3 --- lms/djangoapps/courseware/tests/test_navigation.py | 2 -- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/common/djangoapps/external_auth/tests/test_ssl.py b/common/djangoapps/external_auth/tests/test_ssl.py index 1bcecdded01a..18cee1e35be6 100644 --- a/common/djangoapps/external_auth/tests/test_ssl.py +++ b/common/djangoapps/external_auth/tests/test_ssl.py @@ -17,11 +17,11 @@ 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.roles import CourseStaffRole from student.tests.factories import UserFactory 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 FEATURES_WITH_SSL_AUTH = settings.FEATURES.copy() diff --git a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py index 422c43220efc..5c0eafc31906 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py @@ -43,9 +43,10 @@ def mixed_store_config(data_dir, mappings, include_xml=False, xml_course_dirs=No xml_course_dirs (list): The directories containing XML courses to load from disk. 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 + * include_xml should be True + * xml_course_dirs should be the list of directories (relative to data_dir) + containing the courses you want to load + * mappings should be configured, pointing the xml courses to the xml modulestore """ stores = [ diff --git a/lms/djangoapps/courseware/tests/test_masquerade.py b/lms/djangoapps/courseware/tests/test_masquerade.py index 0703659ad9e3..8262dc6c6b33 100644 --- a/lms/djangoapps/courseware/tests/test_masquerade.py +++ b/lms/djangoapps/courseware/tests/test_masquerade.py @@ -21,7 +21,7 @@ from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_GRADED_MODULESTORE -# TODO: the abtest in the sample course "graded" is currently preventing +# TODO: the "abtest" node 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. diff --git a/lms/djangoapps/courseware/tests/test_module_render.py b/lms/djangoapps/courseware/tests/test_module_render.py index caed8a430155..f3fee3113d03 100644 --- a/lms/djangoapps/courseware/tests/test_module_render.py +++ b/lms/djangoapps/courseware/tests/test_module_render.py @@ -3,7 +3,6 @@ """ from functools import partial import json -from unittest import skip import ddt from django.http import Http404, HttpResponse @@ -373,7 +372,6 @@ def setup_modulestore(self, default_ms, num_finds, num_sends): # - it loads the active version at the start of the bulk operation # - it loads the course definition for inheritance, because it's outside # 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.unpack def test_toc_toy_from_chapter(self, default_ms, setup_finds, setup_sends, toc_finds): @@ -412,7 +410,6 @@ def test_toc_toy_from_chapter(self, default_ms, setup_finds, setup_sends, toc_fi # - it loads the active version at the start of the bulk operation # - it loads the course definition for inheritance, because it's outside # 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.unpack def test_toc_toy_from_section(self, default_ms, setup_finds, setup_sends, toc_finds): diff --git a/lms/djangoapps/courseware/tests/test_navigation.py b/lms/djangoapps/courseware/tests/test_navigation.py index 212658eaa6e5..ba894af5155b 100644 --- a/lms/djangoapps/courseware/tests/test_navigation.py +++ b/lms/djangoapps/courseware/tests/test_navigation.py @@ -2,7 +2,6 @@ This test file will run through some LMS test scenarios regarding access and navigation of the LMS """ import time -import unittest from django.conf import settings from django.core.urlresolvers import reverse @@ -121,7 +120,6 @@ def test_chrome_settings(self): self.assertTabActive('progress', response) self.assertTabInactive('courseware', response) - @unittest.skip @override_settings(SESSION_INACTIVITY_TIMEOUT_IN_SECONDS=1) def test_inactive_session_timeout(self): """