From cb1bb7fa6459e7941bee0dcb49191fd8e2822a3e Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 1 Feb 2022 14:01:26 -0500 Subject: [PATCH] test: switch default test store to the split store It's long past time that the default test modulestore was Split, instead of Old Mongo. This commit switches the default store and fixes some tests that now fail: - Tests that didn't expect MFE to be enabled (because we don't enable MFE for Old Mongo) - opt out of MFE for those - Tests that hardcoded old key string formats - Lots of other random little differences In many places, I didn't spend much time trying to figure out how to properly fix the test, and instead just set the modulestore to Old Mongo. For those tests that I didn't spend time investigating, I've set the modulestore to TEST_DATA_MONGO_AMNESTY_MODULESTORE - search for that string to find further work. --- cms/djangoapps/contentstore/api/tests/base.py | 5 +- .../contentstore/api/tests/test_import.py | 6 +- .../contentstore/api/tests/test_validation.py | 6 +- .../commands/tests/test_delete_course.py | 11 +-- .../tests/test_courseware_index.py | 12 +-- .../contentstore/tests/test_crud.py | 4 +- .../contentstore/tests/test_i18n.py | 7 +- .../contentstore/tests/test_libraries.py | 11 ++- .../contentstore/tests/test_proctoring.py | 7 +- .../tests/test_users_default_role.py | 4 +- cms/djangoapps/contentstore/tests/utils.py | 18 ++-- .../contentstore/views/tests/test_gating.py | 4 +- .../contentstore/views/tests/test_item.py | 33 +++---- .../contentstore/views/tests/test_preview.py | 5 +- .../views/tests/test_transcripts.py | 14 +-- .../export_course_metadata/test_signals.py | 3 +- cms/lib/xblock/test/test_authoring_mixin.py | 13 +-- .../course_modes/tests/test_views.py | 3 +- .../student/tests/test_bulk_email_settings.py | 2 +- .../student/tests/test_certificates.py | 9 +- .../student/tests/test_enrollment.py | 5 +- common/djangoapps/student/tests/test_views.py | 27 ++---- .../xmodule/modulestore/tests/django_utils.py | 9 +- .../modulestore/tests/test_semantics.py | 7 +- .../backends/tests/test_badgr_backend.py | 2 +- .../events/tests/test_course_complete.py | 6 +- lms/djangoapps/bulk_email/tests/test_email.py | 5 +- .../ccx/tests/test_ccx_modulestore.py | 6 +- .../tests/test_field_override_performance.py | 11 +-- lms/djangoapps/ccx/tests/test_models.py | 7 +- lms/djangoapps/ccx/tests/test_overrides.py | 6 +- lms/djangoapps/ccx/tests/test_tasks.py | 8 +- lms/djangoapps/ccx/tests/test_utils.py | 10 +- lms/djangoapps/ccx/tests/test_views.py | 31 +++--- lms/djangoapps/ccx/tests/utils.py | 8 +- .../certificates/tests/test_signals.py | 8 +- .../certificates/tests/test_support_views.py | 8 +- .../certificates/tests/test_webview_views.py | 24 ++--- lms/djangoapps/commerce/tests/test_signals.py | 4 +- .../course_api/blocks/tests/pacts/views.py | 5 +- lms/djangoapps/course_api/tests/test_api.py | 4 +- .../course_api/tests/test_serializers.py | 9 +- lms/djangoapps/course_api/tests/test_views.py | 19 ++-- .../transformers/tests/helpers.py | 13 ++- .../tests/test_load_override_data.py | 7 +- .../course_goals/tests/test_user_activity.py | 7 +- lms/djangoapps/course_home_api/tests/utils.py | 9 +- .../course_wiki/tests/test_access.py | 6 +- .../course_wiki/tests/test_middleware.py | 5 +- .../courseware/tests/pacts/views.py | 5 +- lms/djangoapps/courseware/tests/test_about.py | 11 ++- .../courseware/tests/test_access.py | 4 - .../courseware/tests/test_course_info.py | 6 +- .../courseware/tests/test_course_survey.py | 5 +- .../courseware/tests/test_courses.py | 30 +++--- .../courseware/tests/test_date_summary.py | 8 +- .../tests/test_discussion_xblock.py | 10 +- .../tests/test_draft_modulestore.py | 10 +- .../courseware/tests/test_entrance_exam.py | 9 +- .../courseware/tests/test_group_access.py | 9 +- .../courseware/tests/test_masquerade.py | 2 + .../courseware/tests/test_module_render.py | 18 ++-- .../courseware/tests/test_navigation.py | 14 +-- .../courseware/tests/test_split_module.py | 7 +- .../tests/test_submitting_problems.py | 10 +- .../tests/test_view_authentication.py | 9 +- lms/djangoapps/courseware/tests/test_views.py | 96 +++++++++---------- .../django_comment_client/base/tests.py | 5 +- .../django_comment_client/tests/test_utils.py | 8 +- .../discussion/rest_api/tests/test_api.py | 17 +++- .../rest_api/tests/test_serializers.py | 6 +- .../discussion/rest_api/tests/test_views.py | 19 +++- lms/djangoapps/discussion/tests/test_views.py | 3 + .../experiments/tests/test_utils.py | 49 +++++----- lms/djangoapps/gating/tests/test_api.py | 2 +- .../gating/tests/test_integration.py | 7 +- .../grades/rest_api/v1/tests/mixins.py | 6 +- .../rest_api/v1/tests/test_gradebook_views.py | 5 +- .../v1/tests/test_grading_policy_view.py | 8 +- lms/djangoapps/grades/tests/base.py | 6 +- .../grades/tests/integration/test_problems.py | 18 ++-- lms/djangoapps/grades/tests/test_api.py | 2 +- .../grades/tests/test_course_grade.py | 5 +- lms/djangoapps/grades/tests/test_services.py | 4 +- lms/djangoapps/grades/tests/test_tasks.py | 10 +- lms/djangoapps/instructor/tests/test_api.py | 15 ++- .../instructor/tests/test_enrollment.py | 11 +-- lms/djangoapps/instructor/tests/test_tools.py | 15 ++- .../tests/views/test_instructor_dashboard.py | 10 +- .../instructor_task/tests/test_base.py | 9 +- .../tests/test_tasks_helper.py | 9 +- .../commands/tests/test_resend_lti_scores.py | 7 +- .../lti_provider/tests/test_outcomes.py | 5 +- lms/djangoapps/mobile_api/testutils.py | 12 ++- lms/djangoapps/mobile_api/users/tests.py | 2 +- .../api/tests/test_linking.py | 3 +- .../rest_api/v1/tests/test_views.py | 9 +- lms/djangoapps/staticbook/tests.py | 2 +- lms/djangoapps/support/tests/test_views.py | 13 ++- lms/djangoapps/teams/tests/test_api.py | 4 +- .../teams/tests/test_serializers.py | 6 +- lms/djangoapps/teams/tests/test_views.py | 30 +++--- .../verify_student/tests/test_services.py | 2 +- .../verify_student/tests/test_views.py | 4 +- .../djangoapps/bookmarks/tests/test_models.py | 9 +- .../djangoapps/bookmarks/tests/test_tasks.py | 2 + .../djangoapps/bookmarks/tests/test_views.py | 4 +- .../core/djangoapps/ccxcon/tests/test_api.py | 8 +- .../block_structure/tests/test_signals.py | 4 +- .../course_overviews/tests/test_signals.py | 3 +- .../contentserver/test/test_contentserver.py | 6 +- .../djangoapps/course_date_signals/tests.py | 12 ++- .../commands/tests/test_dump_to_neo4j.py | 2 +- .../courseware_api/tests/pacts/views.py | 3 +- .../courseware_api/tests/test_views.py | 4 +- .../demographics/tests/test_status.py | 8 +- .../discussions/tests/test_tasks.py | 7 +- .../discussions/tests/test_transformer.py | 3 +- .../embargo/tests/test_middleware.py | 7 +- .../enrollments/tests/test_views.py | 11 ++- .../models/tests/test_course_details.py | 9 +- .../djangoapps/programs/tests/test_utils.py | 11 +-- .../tests/test_content_highlights.py | 8 +- .../schedules/tests/test_resolvers.py | 2 + .../schedules/tests/test_signals.py | 10 +- .../user_api/accounts/tests/test_utils.py | 3 +- openedx/core/lib/gating/tests/test_api.py | 9 +- openedx/core/lib/tests/test_xblock_utils.py | 9 +- .../content_type_gating/tests/test_access.py | 15 ++- .../tests/test_course_expiration.py | 5 +- .../tests/views/test_course_home.py | 4 +- .../tests/views/test_course_outline.py | 27 ++++-- .../tests/views/test_course_sock.py | 2 + .../tests/views/test_masquerade.py | 4 + .../enterprise_support/tests/test_utils.py | 2 + .../completion_integration/test_services.py | 10 +- .../completion_integration/test_views.py | 1 + .../test_crowdsource_hinter.py | 5 +- .../xblock_integration/test_recommender.py | 5 +- .../xblock_integration/xblock_testcase.py | 5 +- 140 files changed, 707 insertions(+), 596 deletions(-) diff --git a/cms/djangoapps/contentstore/api/tests/base.py b/cms/djangoapps/contentstore/api/tests/base.py index da46cc3b19..2da577e975 100644 --- a/cms/djangoapps/contentstore/api/tests/base.py +++ b/cms/djangoapps/contentstore/api/tests/base.py @@ -5,11 +5,11 @@ Base test case for the course API views. from django.urls import reverse from rest_framework.test import APITestCase +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from common.djangoapps.student.tests.factories import StaffFactory from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order # pylint: disable=unused-variable @@ -17,7 +17,6 @@ class BaseCourseViewTest(SharedModuleStoreTestCase, APITestCase): """ Base test class for course data views. """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE view_name = None # The name of the view to use in reverse() call in self.get_url() @classmethod diff --git a/cms/djangoapps/contentstore/api/tests/test_import.py b/cms/djangoapps/contentstore/api/tests/test_import.py index a6d25f5f44..0f989a8151 100644 --- a/cms/djangoapps/contentstore/api/tests/test_import.py +++ b/cms/djangoapps/contentstore/api/tests/test_import.py @@ -12,19 +12,17 @@ from path import Path as path from rest_framework import status from rest_framework.test import APITestCase from user_tasks.models import UserTaskStatus +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.student.tests.factories import StaffFactory from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order class CourseImportViewTest(SharedModuleStoreTestCase, APITestCase): """ Test importing courses via a RESTful API (POST method only) """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - @classmethod def setUpClass(cls): super().setUpClass() diff --git a/cms/djangoapps/contentstore/api/tests/test_validation.py b/cms/djangoapps/contentstore/api/tests/test_validation.py index 9601930dcd..5c0424d706 100644 --- a/cms/djangoapps/contentstore/api/tests/test_validation.py +++ b/cms/djangoapps/contentstore/api/tests/test_validation.py @@ -9,11 +9,11 @@ from django.test.utils import override_settings from django.urls import reverse from rest_framework import status from rest_framework.test import APITestCase +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from common.djangoapps.student.tests.factories import StaffFactory from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order @override_settings(PROCTORING_BACKENDS={'DEFAULT': 'proctortrack', 'proctortrack': {}}) @@ -21,8 +21,6 @@ class CourseValidationViewTest(SharedModuleStoreTestCase, APITestCase): """ Test course validation view via a RESTful API """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - @classmethod def setUpClass(cls): super().setUpClass() diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_delete_course.py b/cms/djangoapps/contentstore/management/commands/tests/test_delete_course.py index 320ebf171f..ccdcde9901 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_delete_course.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_delete_course.py @@ -6,21 +6,20 @@ Delete course tests. from unittest import mock from django.core.management import CommandError, call_command +from xmodule.contentstore.content import StaticContent +from xmodule.contentstore.django import contentstore +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.student.roles import CourseInstructorRole from common.djangoapps.student.tests.factories import UserFactory -from xmodule.contentstore.content import StaticContent # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.contentstore.django import contentstore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order class DeleteCourseTests(ModuleStoreTestCase): """ Test for course deleting functionality of the 'delete_course' command """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE YESNO_PATCH_LOCATION = 'cms.djangoapps.contentstore.management.commands.delete_course.query_yes_no' def test_invalid_course_key(self): diff --git a/cms/djangoapps/contentstore/tests/test_courseware_index.py b/cms/djangoapps/contentstore/tests/test_courseware_index.py index ac534d7604..9dbbfffdd0 100644 --- a/cms/djangoapps/contentstore/tests/test_courseware_index.py +++ b/cms/djangoapps/contentstore/tests/test_courseware_index.py @@ -33,7 +33,6 @@ from xmodule.modulestore.django import SignalHandler, modulestore # lint-amnest from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order ModuleStoreTestCase, TEST_DATA_MONGO_MODULESTORE, - TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase, ) from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, LibraryFactory # lint-amnesty, pylint: disable=wrong-import-order @@ -863,12 +862,11 @@ class TestLibrarySearchIndexer(MixedWithOptionsTestCase): self._perform_test_using_store(store_type, self._test_exception) -class GroupConfigurationSearchMongo(CourseTestCase, MixedWithOptionsTestCase): +class GroupConfigurationSearchSplit(CourseTestCase, MixedWithOptionsTestCase): """ - Tests indexing of content groups on course modules using mongo modulestore. + Tests indexing of content groups on course modules using split modulestore. """ CREATE_USER = True - MODULESTORE = TEST_DATA_MONGO_MODULESTORE INDEX_NAME = CoursewareSearchIndexer.INDEX_NAME def setUp(self): @@ -1362,8 +1360,8 @@ class GroupConfigurationSearchMongo(CourseTestCase, MixedWithOptionsTestCase): mock_index.reset_mock() -class GroupConfigurationSearchSplit(GroupConfigurationSearchMongo): # lint-amnesty, pylint: disable=test-inherits-tests +class GroupConfigurationSearchMongo(GroupConfigurationSearchSplit): # pylint: disable=test-inherits-tests """ - Tests indexing of content groups on course modules using split modulestore. + Tests indexing of content groups on course modules using mongo modulestore. """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE + MODULESTORE = TEST_DATA_MONGO_MODULESTORE diff --git a/cms/djangoapps/contentstore/tests/test_crud.py b/cms/djangoapps/contentstore/tests/test_crud.py index 867e5e5300..2507dbb61b 100644 --- a/cms/djangoapps/contentstore/tests/test_crud.py +++ b/cms/djangoapps/contentstore/tests/test_crud.py @@ -7,7 +7,7 @@ from xmodule.course_module import CourseBlock from xmodule.html_module import HtmlBlock from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.exceptions import DuplicateCourseError -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from xmodule.seq_module import SequenceBlock @@ -16,8 +16,6 @@ class TemplateTests(ModuleStoreTestCase): """ Test finding and using the templates (boilerplates) for xblocks. """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - def test_get_templates(self): found = templates.all_templates() self.assertIsNotNone(found.get('course')) diff --git a/cms/djangoapps/contentstore/tests/test_i18n.py b/cms/djangoapps/contentstore/tests/test_i18n.py index 9ec3c8548d..30e031a43d 100644 --- a/cms/djangoapps/contentstore/tests/test_i18n.py +++ b/cms/djangoapps/contentstore/tests/test_i18n.py @@ -8,14 +8,14 @@ from unittest import mock, skip from django.utils import translation from django.utils.translation import get_language +from xmodule.modulestore.django import ModuleI18nService +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from cms.djangoapps.contentstore.tests.utils import AjaxEnabledTestClient from cms.djangoapps.contentstore.views.preview import _preview_module_system from common.djangoapps.student.tests.factories import UserFactory from openedx.core.lib.edx_six import get_gettext -from xmodule.modulestore.django import ModuleI18nService # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order class FakeTranslations(ModuleI18nService): @@ -57,6 +57,7 @@ class FakeTranslations(ModuleI18nService): class TestModuleI18nService(ModuleStoreTestCase): """ Test ModuleI18nService """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE def setUp(self): """ Setting up tests """ diff --git a/cms/djangoapps/contentstore/tests/test_libraries.py b/cms/djangoapps/contentstore/tests/test_libraries.py index 3f602055ae..91dc14983b 100644 --- a/cms/djangoapps/contentstore/tests/test_libraries.py +++ b/cms/djangoapps/contentstore/tests/test_libraries.py @@ -8,6 +8,11 @@ from unittest.mock import Mock, patch import ddt from django.test.utils import override_settings from opaque_keys.edx.locator import CourseKey, LibraryLocator +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory +from xmodule.x_module import STUDIO_VIEW from cms.djangoapps.contentstore.tests.utils import AjaxEnabledTestClient, parse_json from cms.djangoapps.contentstore.utils import reverse_library_url, reverse_url, reverse_usage_url @@ -27,17 +32,13 @@ from common.djangoapps.student.roles import ( ) from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.xblock_django.user_service import DjangoXBlockUserService -from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.x_module import STUDIO_VIEW # lint-amnesty, pylint: disable=wrong-import-order class LibraryTestCase(ModuleStoreTestCase): """ Common functionality for content libraries tests """ + MODULESTORE = TEST_DATA_MONGO_MODULESTORE def setUp(self): super().setUp() diff --git a/cms/djangoapps/contentstore/tests/test_proctoring.py b/cms/djangoapps/contentstore/tests/test_proctoring.py index fc0de385a3..d398bc896a 100644 --- a/cms/djangoapps/contentstore/tests/test_proctoring.py +++ b/cms/djangoapps/contentstore/tests/test_proctoring.py @@ -10,12 +10,12 @@ import ddt from django.conf import settings from edx_proctoring.api import get_all_exams_for_course, get_review_policy_by_exam_id from pytz import UTC +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from cms.djangoapps.contentstore.signals.handlers import listen_for_course_publish from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order @ddt.ddt @@ -24,6 +24,7 @@ class TestProctoredExams(ModuleStoreTestCase): """ Tests for the publishing of proctored exams """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE def setUp(self): """ diff --git a/cms/djangoapps/contentstore/tests/test_users_default_role.py b/cms/djangoapps/contentstore/tests/test_users_default_role.py index 67967134df..82bd4e960b 100644 --- a/cms/djangoapps/contentstore/tests/test_users_default_role.py +++ b/cms/djangoapps/contentstore/tests/test_users_default_role.py @@ -3,18 +3,20 @@ Unit tests for checking default forum role "Student" of a user when he creates a after deleting it creates same course again """ +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase from cms.djangoapps.contentstore.tests.utils import AjaxEnabledTestClient from cms.djangoapps.contentstore.utils import delete_course, reverse_url from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order class TestUsersDefaultRole(ModuleStoreTestCase): """ Unit tests for checking enrollment and default forum role "Student" of a logged in user """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + def setUp(self): """ Add a user and a course diff --git a/cms/djangoapps/contentstore/tests/utils.py b/cms/djangoapps/contentstore/tests/utils.py index 2fa8d0cdad..fabfb2c75f 100644 --- a/cms/djangoapps/contentstore/tests/utils.py +++ b/cms/djangoapps/contentstore/tests/utils.py @@ -11,17 +11,17 @@ from django.conf import settings from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.test.client import Client from opaque_keys.edx.keys import AssetKey, CourseKey +from xmodule.contentstore.django import contentstore +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.inheritance import own_metadata +from xmodule.modulestore.split_mongo.split import SplitMongoModuleStore +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory +from xmodule.modulestore.tests.utils import ProceduralCourseTestMixin +from xmodule.modulestore.xml_importer import import_course_from_xml from cms.djangoapps.contentstore.utils import reverse_url from common.djangoapps.student.models import Registration -from xmodule.contentstore.django import contentstore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.inheritance import own_metadata # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.split_mongo.split import SplitMongoModuleStore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.utils import ProceduralCourseTestMixin # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.xml_importer import import_course_from_xml # lint-amnesty, pylint: disable=wrong-import-order TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT @@ -74,6 +74,8 @@ class CourseTestCase(ProceduralCourseTestMixin, 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. """ + MODULESTORE = TEST_DATA_MONGO_MODULESTORE + def setUp(self): """ These tests need a user in the DB so that the django Test Client can log them in. diff --git a/cms/djangoapps/contentstore/views/tests/test_gating.py b/cms/djangoapps/contentstore/views/tests/test_gating.py index 589793bd59..566c61bcaa 100644 --- a/cms/djangoapps/contentstore/views/tests/test_gating.py +++ b/cms/djangoapps/contentstore/views/tests/test_gating.py @@ -7,12 +7,12 @@ import json from unittest.mock import patch import ddt +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE +from xmodule.modulestore.tests.factories import ItemFactory from cms.djangoapps.contentstore.tests.utils import CourseTestCase from cms.djangoapps.contentstore.utils import reverse_usage_url from openedx.core.lib.gating.api import GATING_NAMESPACE_QUALIFIER -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import ItemFactory # lint-amnesty, pylint: disable=wrong-import-order from ..item import VisibilityState diff --git a/cms/djangoapps/contentstore/views/tests/test_item.py b/cms/djangoapps/contentstore/views/tests/test_item.py index b7ae9964f1..8ce3da5e46 100644 --- a/cms/djangoapps/contentstore/views/tests/test_item.py +++ b/cms/djangoapps/contentstore/views/tests/test_item.py @@ -27,6 +27,21 @@ from xblock.fields import Scope, ScopeIds, String from xblock.runtime import DictKeyValueStore, KvsFieldData from xblock.test.tools import TestRuntime from xblock.validation import ValidationMessage +from xmodule.capa_module import ProblemBlock +from xmodule.course_module import DEFAULT_START_DATE +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.exceptions import ItemNotFoundError +from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, LibraryFactory, check_mongo_calls +from xmodule.partitions.partitions import ( + ENROLLMENT_TRACK_PARTITION_ID, + MINIMUM_STATIC_PARTITION_ID, + Group, + UserPartition +) +from xmodule.partitions.tests.test_partitions import MockPartitionService +from xmodule.x_module import STUDENT_VIEW, STUDIO_VIEW from cms.djangoapps.contentstore.tests.utils import CourseTestCase from cms.djangoapps.contentstore.utils import reverse_course_url, reverse_usage_url @@ -40,21 +55,6 @@ from common.djangoapps.xblock_django.models import ( from common.djangoapps.xblock_django.user_service import DjangoXBlockUserService from lms.djangoapps.lms_xblock.mixin import NONSENSICAL_ACCESS_RESTRICTION from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration -from xmodule.capa_module import ProblemBlock # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.course_module import DEFAULT_START_DATE # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.exceptions import ItemNotFoundError # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, LibraryFactory, check_mongo_calls # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.partitions.partitions import ( # lint-amnesty, pylint: disable=wrong-import-order - ENROLLMENT_TRACK_PARTITION_ID, - MINIMUM_STATIC_PARTITION_ID, - Group, - UserPartition -) -from xmodule.partitions.tests.test_partitions import MockPartitionService # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.x_module import STUDENT_VIEW, STUDIO_VIEW # lint-amnesty, pylint: disable=wrong-import-order from ..component import component_handler, get_component_templates from ..item import ( @@ -1334,7 +1334,6 @@ class TestDuplicateItemWithAsides(ItemTest, DuplicateHelper): """ Test the duplicate method for blocks with asides. """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE def setUp(self): @@ -1899,8 +1898,6 @@ class TestEditItemSplitMongo(TestEditItemSetup): """ Tests for EditItem running on top of the SplitMongoModuleStore. """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - def test_editing_view_wrappers(self): """ Verify that the editing view only generates a single wrapper, no matter how many times it's loaded diff --git a/cms/djangoapps/contentstore/views/tests/test_preview.py b/cms/djangoapps/contentstore/views/tests/test_preview.py index 9dcc20d03e..d986211920 100644 --- a/cms/djangoapps/contentstore/views/tests/test_preview.py +++ b/cms/djangoapps/contentstore/views/tests/test_preview.py @@ -15,7 +15,9 @@ from xblock.core import XBlock, XBlockAside from xmodule.contentstore.django import contentstore from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, upload_file_to_course +from xmodule.modulestore.tests.django_utils import ( + TEST_DATA_MONGO_MODULESTORE, ModuleStoreTestCase, upload_file_to_course, +) from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from xmodule.modulestore.tests.test_asides import AsideTestType from cms.djangoapps.contentstore.utils import reverse_usage_url @@ -222,6 +224,7 @@ class CmsModuleSystemShimTest(ModuleStoreTestCase): """ Tests that the deprecated attributes in the Module System (XBlock Runtime) return the expected values. """ + MODULESTORE = TEST_DATA_MONGO_MODULESTORE COURSE_ID = 'edX/CmsModuleShimTest/2021_Fall' PYTHON_LIB_FILENAME = 'test_python_lib.zip' PYTHON_LIB_SOURCE_FILE = './common/test/data/uploads/python_lib.zip' diff --git a/cms/djangoapps/contentstore/views/tests/test_transcripts.py b/cms/djangoapps/contentstore/views/tests/test_transcripts.py index c0fa61d4f6..b39535856a 100644 --- a/cms/djangoapps/contentstore/views/tests/test_transcripts.py +++ b/cms/djangoapps/contentstore/views/tests/test_transcripts.py @@ -127,13 +127,13 @@ class BaseTranscripts(CourseTestCase): """ data = { 'parent_locator': str(self.course.location), - 'category': 'non_video', - 'type': 'non_video' + 'category': 'problem', + 'type': 'problem' } response = self.client.ajax_post('/xblock/', data) usage_key = self._get_usage_key(response) item = modulestore().get_item(usage_key) - self.set_fields_from_xml(self.item, '') + self.set_fields_from_xml(self.item, '') modulestore().update_item(item, self.user.id) return usage_key @@ -1037,19 +1037,19 @@ class TestCheckTranscripts(BaseTranscripts): # Not video module: setup data = { 'parent_locator': str(self.course.location), - 'category': 'not_video', - 'type': 'not_video' + 'category': 'problem', + 'type': 'problem' } resp = self.client.ajax_post('/xblock/', data) usage_key = self._get_usage_key(resp) subs_id = str(uuid4()) item = modulestore().get_item(usage_key) self.set_fields_from_xml(self.item, (""" - + - + """.format(subs_id))) modulestore().update_item(item, self.user.id) diff --git a/cms/djangoapps/export_course_metadata/test_signals.py b/cms/djangoapps/export_course_metadata/test_signals.py index 67949f6898..2228f21091 100644 --- a/cms/djangoapps/export_course_metadata/test_signals.py +++ b/cms/djangoapps/export_course_metadata/test_signals.py @@ -6,7 +6,7 @@ from unittest.mock import patch from edx_toggles.toggles.testutils import override_waffle_flag from xmodule.modulestore.django import SignalHandler -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from .signals import export_course_metadata @@ -18,7 +18,6 @@ class TestExportCourseMetadata(SharedModuleStoreTestCase): """ Tests for the export_course_metadata function """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE ENABLED_SIGNALS = ['course_published'] def setUp(self): diff --git a/cms/lib/xblock/test/test_authoring_mixin.py b/cms/lib/xblock/test/test_authoring_mixin.py index ac49bf902e..9d848b06ba 100644 --- a/cms/lib/xblock/test/test_authoring_mixin.py +++ b/cms/lib/xblock/test/test_authoring_mixin.py @@ -6,23 +6,24 @@ Tests for the Studio authoring XBlock mixin. from django.conf import settings from django.test.utils import override_settings from xblock.core import XBlock - -from common.djangoapps.course_modes.tests.factories import CourseModeFactory -from common.lib.xmodule.xmodule.tests.test_export import PureXBlock -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.partitions.partitions import ( # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory +from xmodule.partitions.partitions import ( ENROLLMENT_TRACK_PARTITION_ID, MINIMUM_STATIC_PARTITION_ID, Group, UserPartition ) +from common.djangoapps.course_modes.tests.factories import CourseModeFactory +from common.lib.xmodule.xmodule.tests.test_export import PureXBlock + class AuthoringMixinTestCase(ModuleStoreTestCase): """ Tests the studio authoring XBlock mixin. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE GROUP_NO_LONGER_EXISTS = "This group no longer exists" NO_CONTENT_OR_ENROLLMENT_GROUPS = "Access to this component is not restricted" NO_CONTENT_ENROLLMENT_TRACK_ENABLED = "You can restrict access to this component to learners in specific enrollment tracks or content groups" # lint-amnesty, pylint: disable=line-too-long diff --git a/common/djangoapps/course_modes/tests/test_views.py b/common/djangoapps/course_modes/tests/test_views.py index 4bc739bfc3..5d035f506e 100644 --- a/common/djangoapps/course_modes/tests/test_views.py +++ b/common/djangoapps/course_modes/tests/test_views.py @@ -105,7 +105,8 @@ class CourseModeViewTest(CatalogIntegrationMixin, UrlResetMixin, ModuleStoreTest if redirect: if has_started: self.assertRedirects( - response, reverse('openedx.course_experience.course_home', kwargs={'course_id': course.id}) + response, reverse('openedx.course_experience.course_home', kwargs={'course_id': course.id}), + target_status_code=302, # for follow-on redirection to MFE (ideally we'd just be sent there first) ) else: self.assertRedirects(response, reverse('dashboard')) diff --git a/common/djangoapps/student/tests/test_bulk_email_settings.py b/common/djangoapps/student/tests/test_bulk_email_settings.py index 10d8c0629d..f8bd07d4d2 100644 --- a/common/djangoapps/student/tests/test_bulk_email_settings.py +++ b/common/djangoapps/student/tests/test_bulk_email_settings.py @@ -42,7 +42,7 @@ class TestStudentDashboardEmailView(SharedModuleStoreTestCase): # URL for email settings modal self.email_modal_link = ( 'Email Settings' ).format( org=self.course.org, diff --git a/common/djangoapps/student/tests/test_certificates.py b/common/djangoapps/student/tests/test_certificates.py index f997d0e8a4..a9f6335661 100644 --- a/common/djangoapps/student/tests/test_certificates.py +++ b/common/djangoapps/student/tests/test_certificates.py @@ -10,6 +10,10 @@ from django.conf import settings from django.test.utils import override_settings from django.urls import reverse from pytz import UTC +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory +from xmodule.data import CertificatesDisplayBehaviors from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory @@ -19,10 +23,6 @@ from lms.djangoapps.certificates.tests.factories import ( GeneratedCertificateFactory, LinkedInAddToProfileConfigurationFactory ) -from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.data import CertificatesDisplayBehaviors # lint-amnesty, pylint: disable=wrong-import-order # pylint: disable=no-member @@ -33,6 +33,7 @@ FUTURE_DATE = datetime.datetime.now(UTC) + datetime.timedelta(days=2) class CertificateDisplayTestBase(SharedModuleStoreTestCase): """Tests display of certificates on the student dashboard. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE USERNAME = "test_user" PASSWORD = "password" DOWNLOAD_URL = "http://www.example.com/certificate.pdf" diff --git a/common/djangoapps/student/tests/test_enrollment.py b/common/djangoapps/student/tests/test_enrollment.py index a0cd511b4b..2073c099ea 100644 --- a/common/djangoapps/student/tests/test_enrollment.py +++ b/common/djangoapps/student/tests/test_enrollment.py @@ -11,6 +11,8 @@ import pytest from django.conf import settings from django.urls import reverse from openedx_events.tests.utils import OpenEdxEventsTestMixin +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory @@ -24,8 +26,6 @@ from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRol from common.djangoapps.student.tests.factories import CourseEnrollmentAllowedFactory, UserFactory from common.djangoapps.util.testing import UrlResetMixin from openedx.core.djangoapps.embargo.test_utils import restrict_course -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order @ddt.ddt @@ -36,6 +36,7 @@ class EnrollmentTest(UrlResetMixin, SharedModuleStoreTestCase, OpenEdxEventsTest Test student enrollment, especially with different course modes. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE ENABLED_OPENEDX_EVENTS = [] USERNAME = "Bob" diff --git a/common/djangoapps/student/tests/test_views.py b/common/djangoapps/student/tests/test_views.py index 9ed794c122..a874a39fb7 100644 --- a/common/djangoapps/student/tests/test_views.py +++ b/common/djangoapps/student/tests/test_views.py @@ -5,7 +5,6 @@ Test the student dashboard view. import itertools import json -import re import unittest from datetime import datetime, timedelta # lint-amnesty, pylint: disable=unused-import from unittest.mock import patch @@ -642,16 +641,13 @@ class StudentDashboardTests(SharedModuleStoreTestCase, MilestonesTestCaseMixin, return ''.join(response.content.decode('utf-8').split()) @staticmethod - def _pull_course_run_from_course_key(course_key_string): # lint-amnesty, pylint: disable=missing-function-docstring - search_results = re.search(r'Run_[0-9]+$', course_key_string) - assert search_results - course_run_string = search_results.group(0).replace('_', ' ') - return course_run_string + def _pull_course_run_from_course_key(course_key: CourseKey): # lint-amnesty, pylint: disable=missing-function-docstring + return course_key.run.replace('_', ' ') @staticmethod def _get_html_for_view_course_button(course_key_string, course_run_string): return ''' - View Course @@ -679,7 +675,7 @@ class StudentDashboardTests(SharedModuleStoreTestCase, MilestonesTestCaseMixin, ) @staticmethod - def _get_html_for_entitlement_button(course_key_string): + def _get_html_for_entitlement_button(course_key: CourseKey): return'''
{org} - @@ -689,8 +685,8 @@ class StudentDashboardTests(SharedModuleStoreTestCase, MilestonesTestCaseMixin,
'''.format( - org=course_key_string.split('/')[0], - course=course_key_string.split('/')[1] + org=course_key.org, + course=course_key.course, ) def test_view_course_appears_on_dashboard(self): @@ -711,7 +707,7 @@ class StudentDashboardTests(SharedModuleStoreTestCase, MilestonesTestCaseMixin, course_key_string = str(course.id) # No completion data means there's no block from which to resume. resume_block_key_string = '' - course_run_string = self._pull_course_run_from_course_key(course_key_string) + course_run_string = self._pull_course_run_from_course_key(course.id) view_button_html = self._get_html_for_view_course_button( course_key_string, @@ -759,7 +755,7 @@ class StudentDashboardTests(SharedModuleStoreTestCase, MilestonesTestCaseMixin, course_key_string = str(course_key) resume_block_key_string = str(block_keys[-1]) - course_run_string = self._pull_course_run_from_course_key(course_key_string) + course_run_string = self._pull_course_run_from_course_key(course_key) view_button_html = self._get_html_for_view_course_button( course_key_string, @@ -840,8 +836,7 @@ class StudentDashboardTests(SharedModuleStoreTestCase, MilestonesTestCaseMixin, else: last_completed_block_string = '' - course_run_string = self._pull_course_run_from_course_key( - course_key_string) + course_run_string = self._pull_course_run_from_course_key(course_key) # Submit completed course blocks in even-numbered courses. if isEven(i): @@ -871,9 +866,7 @@ class StudentDashboardTests(SharedModuleStoreTestCase, MilestonesTestCaseMixin, ) ) html_for_entitlement.append( - self._get_html_for_entitlement_button( - course_key_string - ) + self._get_html_for_entitlement_button(course_key) ) response = self.client.get(reverse('dashboard')) diff --git a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py index ba724baa78..d60efbc944 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py @@ -16,13 +16,13 @@ from django.contrib.auth.models import AnonymousUser from django.db import connections, transaction from django.test import TestCase from django.test.utils import override_settings - from xmodule.contentstore.content import StaticContent from xmodule.contentstore.django import _CONTENTSTORE from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import SignalHandler, clear_existing_modulestores, modulestore from xmodule.modulestore.tests.factories import XMODULE_FACTORY_LOCK from xmodule.modulestore.tests.mongo_connection import MONGO_HOST, MONGO_PORT_NUM + from lms.djangoapps.courseware.field_overrides import OverrideFieldData from openedx.core.djangolib.testing.utils import CacheIsolationMixin, CacheIsolationTestCase, FilteredQueryCountMixin from openedx.core.lib.tempdir import mkdtemp_clean @@ -197,6 +197,11 @@ TEST_DATA_MIXED_MODULESTORE = functools.partial( # Use this modulestore if you specifically want to test mongo and not a mocked modulestore. TEST_DATA_MONGO_MODULESTORE = functools.partial(mixed_store_config, mkdtemp_clean(), {}) +# When switching away from MONGO-by-default to SPLIT-by-default, we broke a lot of tests. +# Some we fixed, but others we did not fully investigate. This value was used for those. +# These tests may actually need MONGO, or they may be able to be fixed to work in SPLIT. Investigation needed. +TEST_DATA_MONGO_AMNESTY_MODULESTORE = TEST_DATA_MONGO_MODULESTORE + # All store requests now go through mixed # Use this modulestore if you specifically want to test split-mongo and not a mocked modulestore. TEST_DATA_SPLIT_MODULESTORE = functools.partial( @@ -277,7 +282,7 @@ class ModuleStoreIsolationMixin(CacheIsolationMixin, SignalIsolationMixin): ... """ - MODULESTORE = functools.partial(mixed_store_config, mkdtemp_clean(), {}) + MODULESTORE = TEST_DATA_SPLIT_MODULESTORE CONTENTSTORE = functools.partial(contentstore_config) ENABLED_CACHES = ['default', 'mongo_metadata_inheritance', 'loc_cache', 'course_index_cache'] diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_semantics.py b/common/lib/xmodule/xmodule/modulestore/tests/test_semantics.py index d74d9f4cc4..98ca2aa75a 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_semantics.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_semantics.py @@ -19,11 +19,7 @@ from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.draft_and_published import DIRECT_ONLY_CATEGORIES from xmodule.modulestore.exceptions import ItemNotFoundError from xmodule.modulestore.tests.factories import CourseFactory -from xmodule.modulestore.tests.django_utils import ( - ModuleStoreTestCase, - TEST_DATA_MONGO_MODULESTORE, - TEST_DATA_SPLIT_MODULESTORE, -) +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, TEST_DATA_MONGO_MODULESTORE DETACHED_BLOCK_TYPES = dict(XBlock.load_tagged_classes('detached')) @@ -421,7 +417,6 @@ class TestSplitDirectOnlyCategorySemantics(DirectOnlyCategorySemantics): """ Verify DIRECT_ONLY_CATEGORY semantics against the SplitMongoModulestore. """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE __test__ = True @ddt.data(*TESTABLE_BLOCK_TYPES) diff --git a/lms/djangoapps/badges/backends/tests/test_badgr_backend.py b/lms/djangoapps/badges/backends/tests/test_badgr_backend.py index 9f018adefe..7e9f2d367a 100644 --- a/lms/djangoapps/badges/backends/tests/test_badgr_backend.py +++ b/lms/djangoapps/badges/backends/tests/test_badgr_backend.py @@ -30,7 +30,7 @@ BADGR_SETTINGS = { } # Should be the hashed result of test_slug as the slug, and test_component as the component -EXAMPLE_SLUG = '15bb687e0c59ef2f0a49f6838f511bf4ca6c566dd45da6293cabbd9369390e1a' +EXAMPLE_SLUG = '9e915d55bb304a73d20c453531d3c27f81574218413c23903823d20d11b587ae' BADGR_SERVER_SLUG = 'test_badgr_server_slug' diff --git a/lms/djangoapps/badges/events/tests/test_course_complete.py b/lms/djangoapps/badges/events/tests/test_course_complete.py index c6cbf5cd72..582415d9c1 100644 --- a/lms/djangoapps/badges/events/tests/test_course_complete.py +++ b/lms/djangoapps/badges/events/tests/test_course_complete.py @@ -31,8 +31,10 @@ class CourseCompleteTestCase(ModuleStoreTestCase): Verify slug generation is working as expected. If this test fails, the algorithm has changed, and it will cause the handler to lose track of all badges it made in the past. """ - assert course_complete.course_slug(self.course_key, 'honor') == 'edxcourse_testtest_run_honor_fc5519b' - assert course_complete.course_slug(self.course_key, 'verified') == 'edxcourse_testtest_run_verified_a199ec0' + assert course_complete.course_slug(self.course_key, 'honor') ==\ + 'course-v1edxcourse_testtest_run_honor_2055051' + assert course_complete.course_slug(self.course_key, 'verified') ==\ + 'course-v1edxcourse_testtest_run_verified_d550ad7' def test_dated_description(self): """ diff --git a/lms/djangoapps/bulk_email/tests/test_email.py b/lms/djangoapps/bulk_email/tests/test_email.py index a67c0e8df7..576e068807 100644 --- a/lms/djangoapps/bulk_email/tests/test_email.py +++ b/lms/djangoapps/bulk_email/tests/test_email.py @@ -675,12 +675,13 @@ class TestCourseEmailContext(SharedModuleStoreTestCase): """ This test tests that the bulk email context uses http or https urls as appropriate. """ + course_id_fragment = f'{self.course_org}+{self.course_number}+{self.course_run}' assert email_context['platform_name'] == settings.PLATFORM_NAME assert email_context['course_title'] == self.course_title assert email_context['course_url'] == \ - f'{scheme}://edx.org/courses/{self.course_org}/{self.course_number}/{self.course_run}/' + f'{scheme}://edx.org/courses/course-v1:{course_id_fragment}/' assert email_context['course_image_url'] == \ - f'{scheme}://edx.org/c4x/{self.course_org}/{self.course_number}/asset/images_course_image.jpg' + f'{scheme}://edx.org/asset-v1:{course_id_fragment}+type@asset+block@images_course_image.jpg' assert email_context['email_settings_url'] == f'{scheme}://edx.org/dashboard' assert email_context['account_settings_url'] == f'{scheme}://edx.org/account/settings' diff --git a/lms/djangoapps/ccx/tests/test_ccx_modulestore.py b/lms/djangoapps/ccx/tests/test_ccx_modulestore.py index 6257fca829..2245e8b24b 100644 --- a/lms/djangoapps/ccx/tests/test_ccx_modulestore.py +++ b/lms/djangoapps/ccx/tests/test_ccx_modulestore.py @@ -10,18 +10,16 @@ from itertools import chain import pytz from ccx_keys.locator import CCXLocator from six.moves import zip_longest +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from common.djangoapps.student.tests.factories import AdminFactory, UserFactory from lms.djangoapps.ccx.models import CustomCourseForEdX -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order class TestCCXModulestoreWrapper(SharedModuleStoreTestCase): """tests for a modulestore wrapped by CCXModulestoreWrapper """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - @classmethod def setUpClass(cls): super().setUpClass() diff --git a/lms/djangoapps/ccx/tests/test_field_override_performance.py b/lms/djangoapps/ccx/tests/test_field_override_performance.py index c1a4eaa598..99f14c44ab 100644 --- a/lms/djangoapps/ccx/tests/test_field_override_performance.py +++ b/lms/djangoapps/ccx/tests/test_field_override_performance.py @@ -20,6 +20,9 @@ from edx_django_utils.cache import RequestCache from opaque_keys.edx.keys import CourseKey from pytz import UTC from xblock.core import XBlock +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls, check_sum_of_calls +from xmodule.modulestore.tests.utils import ProceduralCourseTestMixin from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory @@ -30,13 +33,6 @@ from lms.djangoapps.courseware.views.views import progress from openedx.core.djangoapps.content.block_structure.api import get_course_in_cache from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES from openedx.features.content_type_gating.models import ContentTypeGatingConfig -from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order - TEST_DATA_MONGO_MODULESTORE, - TEST_DATA_SPLIT_MODULESTORE, - ModuleStoreTestCase -) -from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls, check_sum_of_calls # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.utils import ProceduralCourseTestMixin # lint-amnesty, pylint: disable=wrong-import-order QUERY_COUNT_TABLE_BLACKLIST = WAFFLE_TABLES @@ -267,7 +263,6 @@ class TestFieldOverrideSplitPerformance(FieldOverridePerformanceTestCase): """ Test cases for instrumenting field overrides against the Split modulestore. """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE __test__ = True # TODO: decrease query count as part of REVO-28 diff --git a/lms/djangoapps/ccx/tests/test_models.py b/lms/djangoapps/ccx/tests/test_models.py index 3d9054896e..34475a31d8 100644 --- a/lms/djangoapps/ccx/tests/test_models.py +++ b/lms/djangoapps/ccx/tests/test_models.py @@ -8,11 +8,11 @@ from datetime import datetime, timedelta import ddt from pytz import utc +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls from common.djangoapps.student.roles import CourseCcxCoachRole from common.djangoapps.student.tests.factories import AdminFactory -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls # lint-amnesty, pylint: disable=wrong-import-order from ..overrides import override_field_for_ccx from .factories import CcxFactory @@ -22,9 +22,6 @@ from .factories import CcxFactory class TestCCX(ModuleStoreTestCase): """Unit tests for the CustomCourseForEdX model """ - - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - def setUp(self): """common setup for all tests""" super().setUp() diff --git a/lms/djangoapps/ccx/tests/test_overrides.py b/lms/djangoapps/ccx/tests/test_overrides.py index b5aedad1da..4ec68aecf0 100644 --- a/lms/djangoapps/ccx/tests/test_overrides.py +++ b/lms/djangoapps/ccx/tests/test_overrides.py @@ -10,6 +10,8 @@ import pytz from ccx_keys.locator import CCXLocator from django.test.utils import override_settings from edx_django_utils.cache import RequestCache +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from common.djangoapps.student.tests.factories import AdminFactory from lms.djangoapps.ccx.models import CustomCourseForEdX @@ -19,8 +21,6 @@ from lms.djangoapps.courseware.field_overrides import OverrideFieldData from lms.djangoapps.courseware.tests.test_field_overrides import inject_field_overrides from lms.djangoapps.courseware.testutils import FieldOverrideTestMixin from openedx.core.lib.courses import get_course_by_id -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order @override_settings( @@ -31,8 +31,6 @@ class TestFieldOverrides(FieldOverrideTestMixin, SharedModuleStoreTestCase): """ Make sure field overrides behave in the expected manner. """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - @classmethod def setUpClass(cls): """ diff --git a/lms/djangoapps/ccx/tests/test_tasks.py b/lms/djangoapps/ccx/tests/test_tasks.py index 1448355390..12ece91a3c 100644 --- a/lms/djangoapps/ccx/tests/test_tasks.py +++ b/lms/djangoapps/ccx/tests/test_tasks.py @@ -7,15 +7,15 @@ import contextlib from unittest import mock from ccx_keys.locator import CCXLocator +from xmodule.modulestore.django import SignalHandler +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.student.roles import CourseCcxCoachRole from common.djangoapps.student.tests.factories import AdminFactory from lms.djangoapps.ccx.tasks import send_ccx_course_published from lms.djangoapps.ccx.tests.factories import CcxFactory from openedx.core.djangoapps.content.course_overviews.models import CourseOverview -from xmodule.modulestore.django import SignalHandler # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order @contextlib.contextmanager @@ -30,8 +30,6 @@ class TestSendCCXCoursePublished(ModuleStoreTestCase): """ Unit tests for the send ccx course published task """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - ENABLED_SIGNALS = ['course_published'] def setUp(self): diff --git a/lms/djangoapps/ccx/tests/test_utils.py b/lms/djangoapps/ccx/tests/test_utils.py index 3b55bcbabf..c9e65ddd31 100644 --- a/lms/djangoapps/ccx/tests/test_utils.py +++ b/lms/djangoapps/ccx/tests/test_utils.py @@ -8,6 +8,9 @@ from smtplib import SMTPException from unittest import mock from ccx_keys.locator import CCXLocator +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.student.models import CourseEnrollment, CourseEnrollmentException from common.djangoapps.student.roles import CourseCcxCoachRole, CourseInstructorRole, CourseStaffRole @@ -16,15 +19,10 @@ from lms.djangoapps.ccx.tests.factories import CcxFactory from lms.djangoapps.ccx.tests.utils import CcxTestCase from lms.djangoapps.ccx.utils import add_master_course_staff_to_ccx, ccx_course, remove_master_course_staff_from_ccx from lms.djangoapps.instructor.access import list_with_level -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order class TestGetCCXFromCCXLocator(ModuleStoreTestCase): """Verify that get_ccx_from_ccx_locator functions properly""" - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - def setUp(self): """Set up a course, coach, ccx and user""" super().setUp() @@ -57,8 +55,6 @@ class TestStaffOnCCX(CcxTestCase): """ Tests for staff on ccx courses. """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - def setUp(self): super().setUp() diff --git a/lms/djangoapps/ccx/tests/test_views.py b/lms/djangoapps/ccx/tests/test_views.py index e14b5b8a13..8d717bcc17 100644 --- a/lms/djangoapps/ccx/tests/test_views.py +++ b/lms/djangoapps/ccx/tests/test_views.py @@ -17,8 +17,14 @@ from django.test.utils import override_settings from django.urls import resolve, reverse from django.utils.translation import gettext as _ from edx_django_utils.cache import RequestCache +from edx_toggles.toggles.testutils import override_waffle_flag from opaque_keys.edx.keys import CourseKey from pytz import UTC +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, SampleCourseFactory +from xmodule.x_module import XModuleMixin from capa.tests.response_xml_factory import StringResponseXMLFactory from common.djangoapps.edxmako.shortcuts import render_to_response @@ -35,6 +41,7 @@ from lms.djangoapps.courseware.tabs import get_course_tab_list from lms.djangoapps.courseware.tests.factories import StudentModuleFactory from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase from lms.djangoapps.courseware.testutils import FieldOverrideTestMixin +from lms.djangoapps.courseware.toggles import COURSEWARE_USE_LEGACY_FRONTEND from lms.djangoapps.discussion.django_comment_client.utils import has_forum_access from lms.djangoapps.grades.api import task_compute_all_grades_for_course from lms.djangoapps.instructor.access import allow_access, list_with_level @@ -42,15 +49,6 @@ from openedx.core.djangoapps.content.course_overviews.models import CourseOvervi from openedx.core.djangoapps.django_comment_common.models import FORUM_ROLE_ADMINISTRATOR from openedx.core.djangoapps.django_comment_common.utils import are_permissions_roles_seeded from openedx.core.lib.courses import get_course_by_id -from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order - TEST_DATA_SPLIT_MODULESTORE, - ModuleStoreTestCase, - SharedModuleStoreTestCase -) -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, SampleCourseFactory # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.x_module import XModuleMixin # lint-amnesty, pylint: disable=wrong-import-order def intercept_renderer(path, context): @@ -128,8 +126,6 @@ class TestAdminAccessCoachDashboard(CcxTestCase, LoginEnrollmentTestCase): """ Tests for Custom Courses views. """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - def setUp(self): super().setUp() self.make_coach() @@ -948,8 +944,6 @@ class TestCCXGrades(FieldOverrideTestMixin, SharedModuleStoreTestCase, LoginEnro """ Tests for Custom Courses views. """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - @classmethod def setUpClass(cls): super().setUpClass() @@ -1201,12 +1195,10 @@ class TestStudentViewsWithCCX(ModuleStoreTestCase): """ super().setUp() - # Create a Draft Mongo and a Split Mongo course and enroll a student user in them. + # Create a Split Mongo course and enroll a student user in it. self.student_password = "foobar" self.student = UserFactory.create(username="test", password=self.student_password, is_staff=False) - self.draft_course = SampleCourseFactory.create(default_store=ModuleStoreEnum.Type.mongo) self.split_course = SampleCourseFactory.create(default_store=ModuleStoreEnum.Type.split) - CourseEnrollment.enroll(self.student, self.draft_course.id) CourseEnrollment.enroll(self.student, self.split_course.id) # Create a CCX coach. @@ -1227,7 +1219,12 @@ class TestStudentViewsWithCCX(ModuleStoreTestCase): assert response.status_code == 200 assert re.search('Test CCX', response.content.decode('utf-8')) + @override_waffle_flag(COURSEWARE_USE_LEGACY_FRONTEND, active=True) def test_load_courseware(self): self.client.login(username=self.student.username, password=self.student_password) - response = self.client.get(reverse('courseware', kwargs={'course_id': str(self.ccx_course_key)})) + response = self.client.get(reverse('courseware_section', kwargs={ + 'course_id': str(self.ccx_course_key), + 'chapter': 'chapter_x', + 'section': 'sequential_x1', + })) assert response.status_code == 200 diff --git a/lms/djangoapps/ccx/tests/utils.py b/lms/djangoapps/ccx/tests/utils.py index 8245041753..3d2c5de0bb 100644 --- a/lms/djangoapps/ccx/tests/utils.py +++ b/lms/djangoapps/ccx/tests/utils.py @@ -7,15 +7,15 @@ import datetime import pytz from django.conf import settings +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from common.djangoapps.student.roles import CourseCcxCoachRole, CourseInstructorRole, CourseStaffRole from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.ccx.overrides import override_field_for_ccx from lms.djangoapps.ccx.tests.factories import CcxFactory from openedx.core.djangoapps.ace_common.tests.mixins import EmailTemplateTagMixin -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order class CcxTestCase(EmailTemplateTagMixin, SharedModuleStoreTestCase): @@ -24,8 +24,6 @@ class CcxTestCase(EmailTemplateTagMixin, SharedModuleStoreTestCase): It creates a course that can be used as master course for CCXs. """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - @classmethod def setUpClass(cls): super().setUpClass() diff --git a/lms/djangoapps/certificates/tests/test_signals.py b/lms/djangoapps/certificates/tests/test_signals.py index 59a8f76d27..abc10411ec 100644 --- a/lms/djangoapps/certificates/tests/test_signals.py +++ b/lms/djangoapps/certificates/tests/test_signals.py @@ -8,6 +8,8 @@ from unittest import mock import ddt from edx_toggles.toggles.testutils import override_waffle_flag, override_waffle_switch +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from lms.djangoapps.certificates.api import has_self_generated_certificates_enabled @@ -21,8 +23,6 @@ from lms.djangoapps.certificates.tests.factories import CertificateAllowlistFact from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from lms.djangoapps.grades.tests.utils import mock_passing_grade from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order class SelfGeneratedCertsSignalTest(ModuleStoreTestCase): @@ -44,11 +44,11 @@ class SelfGeneratedCertsSignalTest(ModuleStoreTestCase): assert not has_self_generated_certificates_enabled(course.id) course.self_paced = True - self.store.update_item(course, self.user.id) + self.update_course(course, self.user.id) assert has_self_generated_certificates_enabled(course.id) course.self_paced = False - self.store.update_item(course, self.user.id) + self.update_course(course, self.user.id) assert not has_self_generated_certificates_enabled(course.id) diff --git a/lms/djangoapps/certificates/tests/test_support_views.py b/lms/djangoapps/certificates/tests/test_support_views.py index 1e4715d06b..89ec8ac7ee 100644 --- a/lms/djangoapps/certificates/tests/test_support_views.py +++ b/lms/djangoapps/certificates/tests/test_support_views.py @@ -40,10 +40,10 @@ class CertificateSupportTestCase(ModuleStoreTestCase): STUDENT_EMAIL = "student@example.com" STUDENT_PASSWORD = "student" - CERT_COURSE_KEY = CourseKey.from_string("edX/DemoX/Demo_Course") - COURSE_NOT_EXIST_KEY = CourseKey.from_string("test/TestX/Test_Course_Not_Exist") - EXISTED_COURSE_KEY_1 = CourseKey.from_string("test1/Test1X/Test_Course_Exist_1") - EXISTED_COURSE_KEY_2 = CourseKey.from_string("test2/Test2X/Test_Course_Exist_2") + CERT_COURSE_KEY = CourseKey.from_string("course-v1:edX+DemoX+Demo_Course") + COURSE_NOT_EXIST_KEY = CourseKey.from_string("course-v1:test+TestX+Test_Course_Not_Exist") + EXISTED_COURSE_KEY_1 = CourseKey.from_string("course-v1:test1+Test1X+Test_Course_Exist_1") + EXISTED_COURSE_KEY_2 = CourseKey.from_string("course-v1:test2+Test2X+Test_Course_Exist_2") CERT_GRADE = 0.89 CERT_STATUS = CertificateStatuses.downloadable CERT_MODE = "verified" diff --git a/lms/djangoapps/certificates/tests/test_webview_views.py b/lms/djangoapps/certificates/tests/test_webview_views.py index a1dff65b99..33530d1b7f 100644 --- a/lms/djangoapps/certificates/tests/test_webview_views.py +++ b/lms/djangoapps/certificates/tests/test_webview_views.py @@ -148,7 +148,7 @@ class CommonCertificatesTestCase(ModuleStoreTestCase): self.course.certificates = {'certificates': certificates} self.course.cert_html_view_enabled = True self.course.save() - self.store.update_item(self.course, self.user.id) + self.update_course(self.course, self.user.id) def _create_custom_template(self, org_id=None, mode=None, course_key=None, language=None): """ @@ -531,7 +531,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase, CacheIsolationTestCase) } self.course.save() - self.store.update_item(self.course, self.user.id) + self.update_course(self.course, self.user.id) test_url = get_certificate_url( user_id=self.user.id, @@ -715,7 +715,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase, CacheIsolationTestCase) self.course.cert_html_view_enabled = True self.course.certificate_available_date = datetime.datetime.today() + datetime.timedelta(days=1) self.course.save() - self.store.update_item(self.course, self.user.id) + self.update_course(self.course, self.user.id) test_url = get_certificate_url( user_id=self.user.id, @@ -759,7 +759,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase, CacheIsolationTestCase) self.course.certificates = {'certificates': test_certificates} self.course.cert_html_view_enabled = True self.course.save() - self.store.update_item(self.course, self.user.id) + self.update_course(self.course, self.user.id) test_url = get_certificate_url( user_id=self.user.id, course_id=str(self.course.id), @@ -787,7 +787,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase, CacheIsolationTestCase) self.course.display_coursenumber = "overridden_number" self.course.display_organization = "overridden_org" - self.store.update_item(self.course, self.user.id) + self.update_course(self.course, self.user.id) response = self.client.get(test_url) self.assertContains(response, 'overridden_number') @@ -807,7 +807,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase, CacheIsolationTestCase) self.course.certificates = {'certificates': test_certificates} self.course.cert_html_view_enabled = True self.course.save() - self.store.update_item(self.course, self.user.id) + self.update_course(self.course, self.user.id) test_url = get_certificate_url( user_id=self.user.id, @@ -848,7 +848,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase, CacheIsolationTestCase) self.course.certificates = {'certificates': test_certificates} self.course.cert_html_view_enabled = True self.course.save() - self.store.update_item(self.course, self.user.id) + self.update_course(self.course, self.user.id) test_url = get_certificate_url( user_id=self.user.id, @@ -975,7 +975,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase, CacheIsolationTestCase) self.course.self_paced = self_paced today = datetime.datetime.utcnow() self.course.certificate_available_date = today + datetime.timedelta(cert_avail_delta) - self.store.update_item(self.course, self.user.id) + self.update_course(self.course, self.user.id) self._add_course_certificates(count=1, signatory_count=1, is_active=True) test_url = get_certificate_url( user_id=self.user.id, @@ -1018,7 +1018,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase, CacheIsolationTestCase) self._add_certificate_date_override() today = datetime.datetime.utcnow() self.course.certificate_available_date = today + datetime.timedelta(-2) - self.store.update_item(self.course, self.user.id) + self.update_course(self.course, self.user.id) self._add_course_certificates(count=1, signatory_count=1, is_active=True) test_url = get_certificate_url( user_id=self.user.id, @@ -1048,7 +1048,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase, CacheIsolationTestCase) def test_render_html_view_invalid_certificate_configuration(self): self.course.cert_html_view_enabled = True self.course.save() - self.store.update_item(self.course, self.user.id) + self.update_course(self.course, self.user.id) test_url = get_certificate_url( user_id=self.user.id, @@ -1744,12 +1744,12 @@ class CertificateEventTests(CommonCertificatesTestCase, EventTrackingTestCase): { 'name': 'edx.badge.assertion.evidence_visited', 'data': { - 'course_id': 'testorg/run1/refundable_course', + 'course_id': 'course-v1:testorg+run1+refundable_course', 'assertion_id': assertion.id, 'badge_generator': 'DummyBackend', 'badge_name': 'refundable course', 'issuing_component': '', - 'badge_slug': 'testorgrun1refundable_course_honor_432f164', + 'badge_slug': 'course-v1testorgrun1refundable_course_honor_927f3ad', 'assertion_json_url': 'https://www.example.com/assertion.json', 'assertion_image_url': 'https://www.example.com/image.png', 'user_id': self.user.id, diff --git a/lms/djangoapps/commerce/tests/test_signals.py b/lms/djangoapps/commerce/tests/test_signals.py index e93917114c..7534a4d821 100644 --- a/lms/djangoapps/commerce/tests/test_signals.py +++ b/lms/djangoapps/commerce/tests/test_signals.py @@ -13,10 +13,10 @@ import ddt import httpretty from django.conf import settings from django.contrib.auth.models import AnonymousUser -from django.test import TestCase from django.test.utils import override_settings from opaque_keys.edx.keys import CourseKey from requests import Timeout +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.signals import REFUND_ORDER @@ -34,7 +34,7 @@ ZENDESK_API_KEY = 'abc123' @ddt.ddt @override_settings(ZENDESK_URL=ZENDESK_URL, ZENDESK_USER=ZENDESK_USER, ZENDESK_API_KEY=ZENDESK_API_KEY) -class TestRefundSignal(TestCase): +class TestRefundSignal(ModuleStoreTestCase): """ Exercises logic triggered by the REFUND_ORDER signal. """ diff --git a/lms/djangoapps/course_api/blocks/tests/pacts/views.py b/lms/djangoapps/course_api/blocks/tests/pacts/views.py index f351c83ff8..85b5ac7a1a 100644 --- a/lms/djangoapps/course_api/blocks/tests/pacts/views.py +++ b/lms/djangoapps/course_api/blocks/tests/pacts/views.py @@ -7,7 +7,7 @@ from django.http import JsonResponse from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST from opaque_keys.edx.keys import CourseKey -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreIsolationMixin +from xmodule.modulestore.tests.django_utils import ModuleStoreIsolationMixin from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.student.models import CourseEnrollment @@ -16,9 +16,6 @@ from common.djangoapps.student.tests.factories import CourseEnrollmentFactory class ProviderState(ModuleStoreIsolationMixin): """ Provider State Setup """ - - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - def clean_db(self, user, course_key): """ Delete objects from SQL DB and clean mongodb instance """ diff --git a/lms/djangoapps/course_api/tests/test_api.py b/lms/djangoapps/course_api/tests/test_api.py index 690042f661..8de1b78755 100644 --- a/lms/djangoapps/course_api/tests/test_api.py +++ b/lms/djangoapps/course_api/tests/test_api.py @@ -36,7 +36,7 @@ class CourseApiTestMixin(CourseApiFactoryMixin): cls.request_factory = APIRequestFactory() CourseOverview.get_all_courses() # seed the CourseOverview table - def verify_course(self, course, course_id='edX/toy/2012_Fall'): + def verify_course(self, course, course_id='course-v1:edX+toy+2012_Fall'): """ Ensure that the returned course is the course we just created """ @@ -88,7 +88,7 @@ class TestGetCourseDetail(CourseDetailTestMixin, SharedModuleStoreTestCase): def test_hidden_course_for_staff(self): course = self._make_api_call(self.staff_user, self.staff_user, self.hidden_course.id) - self.verify_course(course, course_id='edX/hidden/2012_Fall') + self.verify_course(course, course_id='course-v1:edX+hidden+2012_Fall') def test_hidden_course_for_staff_as_honor(self): with pytest.raises(Http404): diff --git a/lms/djangoapps/course_api/tests/test_serializers.py b/lms/djangoapps/course_api/tests/test_serializers.py index 61892b37c3..b80cc63799 100644 --- a/lms/djangoapps/course_api/tests/test_serializers.py +++ b/lms/djangoapps/course_api/tests/test_serializers.py @@ -11,12 +11,12 @@ from opaque_keys.edx.locator import CourseLocator from rest_framework.request import Request from rest_framework.test import APIRequestFactory from xblock.core import XBlock +from xmodule.course_module import DEFAULT_START_DATE +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import check_mongo_calls from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.models.course_details import CourseDetails -from xmodule.course_module import DEFAULT_START_DATE # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import check_mongo_calls # lint-amnesty, pylint: disable=wrong-import-order from ..serializers import CourseDetailSerializer, CourseKeySerializer, CourseSerializer from .mixins import CourseApiFactoryMixin @@ -31,6 +31,7 @@ class TestCourseSerializer(CourseApiFactoryMixin, ModuleStoreTestCase): maxDiff = 5000 # long enough to show mismatched dicts, in case of error serializer_class = CourseSerializer + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE ENABLED_SIGNALS = ['course_published'] def setUp(self): @@ -65,7 +66,7 @@ class TestCourseSerializer(CourseApiFactoryMixin, ModuleStoreTestCase): 'raw': image_url, 'small': image_url, 'large': image_url, - } + }, }, 'start': '2015-07-17T12:00:00Z', 'start_type': 'timestamp', diff --git a/lms/djangoapps/course_api/tests/test_views.py b/lms/djangoapps/course_api/tests/test_views.py index 5fed5d5fe6..e2633d085c 100644 --- a/lms/djangoapps/course_api/tests/test_views.py +++ b/lms/djangoapps/course_api/tests/test_views.py @@ -17,6 +17,12 @@ from search.tests.test_course_discovery import DemoCourse from search.tests.tests import TEST_INDEX_NAME from search.tests.utils import SearcherMixin from waffle.testutils import override_switch +from xmodule.modulestore.tests.django_utils import ( + TEST_DATA_MONGO_MODULESTORE, + ModuleStoreTestCase, + SharedModuleStoreTestCase, +) +from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory @@ -26,8 +32,6 @@ from common.djangoapps.student.tests.factories import AdminFactory from openedx.core.lib.api.view_utils import LazySequence from openedx.features.content_type_gating.models import ContentTypeGatingConfig from openedx.features.course_duration_limits.models import CourseDurationLimitConfig -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ..views import CourseDetailView, CourseListUserThrottle, LazyPageNumberPagination from .mixins import TEST_PASSWORD, CourseApiFactoryMixin @@ -313,6 +317,7 @@ class CourseListSearchViewTest(CourseApiTestViewMixin, ModuleStoreTestCase, Sear Similar to search.tests.test_course_discovery_views but with the course API integration. """ + MODULESTORE = TEST_DATA_MONGO_MODULESTORE ENABLED_SIGNALS = ['course_published'] ENABLED_CACHES = ModuleStoreTestCase.ENABLED_CACHES + ['configuration'] @@ -495,7 +500,7 @@ class CourseIdListViewTestCase(CourseApiTestViewMixin, ModuleStoreTestCase): 'role': 'staff' }) assert len(filtered_response.data['results']) == 1 - assert filtered_response.data['results'][0].startswith(self.course.org) + assert filtered_response.data['results'][0].startswith(f'course-v1:{self.course.org}+') # The course staff user does *not* have the course instructor role on any courses. filtered_response = self.verify_response(params={ @@ -510,7 +515,7 @@ class CourseIdListViewTestCase(CourseApiTestViewMixin, ModuleStoreTestCase): 'role': 'instructor' }) assert len(filtered_response.data['results']) == 1 - assert filtered_response.data['results'][0].startswith(alternate_course1.org) + assert filtered_response.data['results'][0].startswith(f'course-v1:{alternate_course1.org}+') # The course instructor user has the inferred course staff role on one course. self.setup_user(course_instructor_user) @@ -519,7 +524,7 @@ class CourseIdListViewTestCase(CourseApiTestViewMixin, ModuleStoreTestCase): 'role': 'staff' }) assert len(filtered_response.data['results']) == 1 - assert filtered_response.data['results'][0].startswith(alternate_course1.org) + assert filtered_response.data['results'][0].startswith(f'course-v1:{alternate_course1.org}+') # The user with both instructor AND staff on a course has the inferred course staff role on that one course. self.setup_user(course_instructor_staff_user) @@ -528,7 +533,7 @@ class CourseIdListViewTestCase(CourseApiTestViewMixin, ModuleStoreTestCase): 'role': 'staff' }) assert len(filtered_response.data['results']) == 1 - assert filtered_response.data['results'][0].startswith(alternate_course2.org) + assert filtered_response.data['results'][0].startswith(f'course-v1:{alternate_course2.org}+') def test_no_libraries(self): """ @@ -550,7 +555,7 @@ class CourseIdListViewTestCase(CourseApiTestViewMixin, ModuleStoreTestCase): 'role': 'staff' }) assert len(filtered_response.data['results']) == 1 - assert filtered_response.data['results'][0].startswith(self.course.org) + assert filtered_response.data['results'][0].startswith(f'course-v1:{self.course.org}+') class LazyPageNumberPaginationTestCase(TestCase): # lint-amnesty, pylint: disable=missing-class-docstring diff --git a/lms/djangoapps/course_blocks/transformers/tests/helpers.py b/lms/djangoapps/course_blocks/transformers/tests/helpers.py index 356030c6ed..c83924ad54 100644 --- a/lms/djangoapps/course_blocks/transformers/tests/helpers.py +++ b/lms/djangoapps/course_blocks/transformers/tests/helpers.py @@ -5,15 +5,16 @@ Test helpers for testing course block transformers. from unittest.mock import patch +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory + from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from lms.djangoapps.courseware.access import has_access from openedx.core.djangoapps.content.block_structure.tests.helpers import clear_registered_transformers_cache from openedx.core.djangoapps.content.block_structure.transformers import BlockStructureTransformers -from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order from ...api import get_course_blocks @@ -42,6 +43,8 @@ class CourseStructureTestCase(TransformerRegistryTestMixin, ModuleStoreTestCase) """ Helper for test cases that need to build course structures. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + def setUp(self): """ Create users. @@ -206,6 +209,8 @@ class BlockParentsMapTestCase(TransformerRegistryTestMixin, ModuleStoreTestCase) a graph of vertical blocks based on a parents_map. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + # Tree formed by parent_map: # 0 # / \ diff --git a/lms/djangoapps/course_blocks/transformers/tests/test_load_override_data.py b/lms/djangoapps/course_blocks/transformers/tests/test_load_override_data.py index 1cf18c29be..e522bc5b65 100644 --- a/lms/djangoapps/course_blocks/transformers/tests/test_load_override_data.py +++ b/lms/djangoapps/course_blocks/transformers/tests/test_load_override_data.py @@ -7,14 +7,14 @@ import datetime import ddt import pytz +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import ToyCourseFactory from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from lms.djangoapps.course_blocks.transformers.load_override_data import REQUESTED_FIELDS, OverrideDataTransformer from lms.djangoapps.courseware.student_field_overrides import get_override_for_user, override_field_for_user from openedx.core.djangoapps.content.block_structure.factory import BlockStructureFactory -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import ToyCourseFactory # lint-amnesty, pylint: disable=wrong-import-order expected_overrides = { 'start': datetime.datetime( @@ -32,6 +32,7 @@ class TestOverrideDataTransformer(ModuleStoreTestCase): """ Test proper behavior for OverrideDataTransformer """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE @classmethod def setUpClass(cls): diff --git a/lms/djangoapps/course_goals/tests/test_user_activity.py b/lms/djangoapps/course_goals/tests/test_user_activity.py index 6e6733b928..cc6df26085 100644 --- a/lms/djangoapps/course_goals/tests/test_user_activity.py +++ b/lms/djangoapps/course_goals/tests/test_user_activity.py @@ -13,6 +13,8 @@ from edx_django_utils.cache import TieredCache from edx_toggles.toggles.testutils import override_waffle_flag from freezegun import freeze_time from mock import patch +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from common.djangoapps.edxmako.shortcuts import render_to_response from common.djangoapps.student.models import CourseEnrollment @@ -21,8 +23,6 @@ from common.djangoapps.util.testing import UrlResetMixin from lms.djangoapps.course_goals.models import UserActivity from openedx.core.djangoapps.django_comment_common.models import ForumsConfig from openedx.features.course_experience import ENABLE_COURSE_GOALS -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, TEST_DATA_SPLIT_MODULESTORE # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order User = get_user_model() @@ -33,9 +33,6 @@ class UserActivityTests(UrlResetMixin, ModuleStoreTestCase): """ Testing Course Goals User Activity """ - - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - @patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) def setUp(self): super().setUp() diff --git a/lms/djangoapps/course_home_api/tests/utils.py b/lms/djangoapps/course_home_api/tests/utils.py index 977cef53e7..f1d2731bb0 100644 --- a/lms/djangoapps/course_home_api/tests/utils.py +++ b/lms/djangoapps/course_home_api/tests/utils.py @@ -6,17 +6,14 @@ import unittest from datetime import datetime from django.conf import settings +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory from lms.djangoapps.courseware.tests.helpers import MasqueradeMixin from lms.djangoapps.verify_student.models import VerificationDeadline from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory -from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=unused-import # lint-amnesty, pylint: disable=wrong-import-order - TEST_DATA_SPLIT_MODULESTORE, - ModuleStoreTestCase -) -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') @@ -26,8 +23,6 @@ class BaseCourseHomeTests(ModuleStoreTestCase, MasqueradeMixin): Creates a course to """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - def setUp(self): super().setUp() diff --git a/lms/djangoapps/course_wiki/tests/test_access.py b/lms/djangoapps/course_wiki/tests/test_access.py index 9352dfd1c7..86c6e54b8a 100644 --- a/lms/djangoapps/course_wiki/tests/test_access.py +++ b/lms/djangoapps/course_wiki/tests/test_access.py @@ -5,6 +5,8 @@ Tests for wiki permissions from django.contrib.auth.models import Group from wiki.models import URLPath +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.student.tests.factories import InstructorFactory from common.djangoapps.student.tests.factories import StaffFactory @@ -12,12 +14,12 @@ from lms.djangoapps.course_wiki import settings from lms.djangoapps.course_wiki.utils import course_wiki_slug, user_is_article_course_staff from lms.djangoapps.course_wiki.views import get_or_create_root from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order class TestWikiAccessBase(ModuleStoreTestCase): """Base class for testing wiki access.""" + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + def setUp(self): super().setUp() diff --git a/lms/djangoapps/course_wiki/tests/test_middleware.py b/lms/djangoapps/course_wiki/tests/test_middleware.py index b3804b892a..16937cc772 100644 --- a/lms/djangoapps/course_wiki/tests/test_middleware.py +++ b/lms/djangoapps/course_wiki/tests/test_middleware.py @@ -5,15 +5,16 @@ Tests for wiki middleware. from django.test.client import Client from wiki.models import URLPath +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.student.tests.factories import InstructorFactory from lms.djangoapps.course_wiki.views import get_or_create_root -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order class TestWikiAccessMiddleware(ModuleStoreTestCase): """Tests for WikiAccessMiddleware.""" + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE def setUp(self): """Test setup.""" diff --git a/lms/djangoapps/courseware/tests/pacts/views.py b/lms/djangoapps/courseware/tests/pacts/views.py index 5cd8416521..9c3844121f 100644 --- a/lms/djangoapps/courseware/tests/pacts/views.py +++ b/lms/djangoapps/courseware/tests/pacts/views.py @@ -7,15 +7,12 @@ from django.http import JsonResponse from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST from opaque_keys.edx.keys import CourseKey -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreIsolationMixin +from xmodule.modulestore.tests.django_utils import ModuleStoreIsolationMixin from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory class ProviderState(ModuleStoreIsolationMixin): """ Provider State Setup """ - - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - def clean_db(self, user, course_key): # pylint: disable=unused-argument """ clean mongodb instance """ diff --git a/lms/djangoapps/courseware/tests/test_about.py b/lms/djangoapps/courseware/tests/test_about.py index 976c2ae59f..ce6cbce18a 100644 --- a/lms/djangoapps/courseware/tests/test_about.py +++ b/lms/djangoapps/courseware/tests/test_about.py @@ -35,7 +35,7 @@ from xmodule.course_module import ( # lint-amnesty, pylint: disable=wrong-impor ) from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order TEST_DATA_MIXED_MODULESTORE, - TEST_DATA_SPLIT_MODULESTORE, + TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase, SharedModuleStoreTestCase ) @@ -55,6 +55,7 @@ class AboutTestCase(LoginEnrollmentTestCase, SharedModuleStoreTestCase, EventTra """ Tests about xblock. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE @classmethod def setUpClass(cls): @@ -291,6 +292,8 @@ class AboutWithCappedEnrollmentsTestCase(LoginEnrollmentTestCase, SharedModuleSt """ This test case will check the About page when a course has a capped enrollment """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + @classmethod def setUpClass(cls): super().setUpClass() @@ -336,6 +339,8 @@ class AboutWithInvitationOnly(SharedModuleStoreTestCase): """ This test case will check the About page when a course is invitation only. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + @classmethod def setUpClass(cls): super().setUpClass() @@ -380,6 +385,8 @@ class AboutWithClosedEnrollment(ModuleStoreTestCase): This test case will check the About page for a course that has enrollment start/end set but it is currently outside of that period. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + def setUp(self): super().setUp() @@ -462,8 +469,6 @@ class CourseAboutTestCaseCCX(SharedModuleStoreTestCase, LoginEnrollmentTestCase) Test for unenrolled student tries to access ccx. Note: Only CCX coach can enroll a student in CCX. In sum self-registration not allowed. """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - @classmethod def setUpClass(cls): super().setUpClass() diff --git a/lms/djangoapps/courseware/tests/test_access.py b/lms/djangoapps/courseware/tests/test_access.py index 1ba063fa30..06ef06425c 100644 --- a/lms/djangoapps/courseware/tests/test_access.py +++ b/lms/djangoapps/courseware/tests/test_access.py @@ -49,7 +49,6 @@ from xmodule.course_module import ( # lint-amnesty, pylint: disable=wrong-impor from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order - TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase, SharedModuleStoreTestCase ) @@ -65,8 +64,6 @@ class CoachAccessTestCaseCCX(SharedModuleStoreTestCase, LoginEnrollmentTestCase) """ Test if user is coach on ccx. """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - @classmethod def setUpClass(cls): """ @@ -164,7 +161,6 @@ class AccessTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase, MilestonesTes """ TOMORROW = 'tomorrow' YESTERDAY = 'yesterday' - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE DATES = { TOMORROW: datetime.datetime.now(pytz.utc) + datetime.timedelta(days=1), YESTERDAY: datetime.datetime.now(pytz.utc) - datetime.timedelta(days=1), diff --git a/lms/djangoapps/courseware/tests/test_course_info.py b/lms/djangoapps/courseware/tests/test_course_info.py index 5f2f6536a9..90df8c68ca 100644 --- a/lms/djangoapps/courseware/tests/test_course_info.py +++ b/lms/djangoapps/courseware/tests/test_course_info.py @@ -27,7 +27,6 @@ from common.djangoapps.student.tests.factories import AdminFactory from common.djangoapps.util.date_utils import strftime_localized from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order TEST_DATA_MIXED_MODULESTORE, - TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase, SharedModuleStoreTestCase ) @@ -192,7 +191,7 @@ class CourseInfoLastAccessedTestCase(LoginEnrollmentTestCase, ModuleStoreTestCas category="chapter", parent_location=self.course.location ) section = ItemFactory.create( - category='section', parent_location=chapter.location + category='sequential', parent_location=chapter.location ) section_url = reverse( 'courseware_section', @@ -309,9 +308,6 @@ class CourseInfoTestCaseCCX(SharedModuleStoreTestCase, LoginEnrollmentTestCase): Test for unenrolled student tries to access ccx. Note: Only CCX coach can enroll a student in CCX. In sum self-registration not allowed. """ - - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - @classmethod def setUpClass(cls): super().setUpClass() diff --git a/lms/djangoapps/courseware/tests/test_course_survey.py b/lms/djangoapps/courseware/tests/test_course_survey.py index df28503d58..77240e44ba 100644 --- a/lms/djangoapps/courseware/tests/test_course_survey.py +++ b/lms/djangoapps/courseware/tests/test_course_survey.py @@ -8,18 +8,19 @@ from copy import deepcopy from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.urls import reverse +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory from common.test.utils import XssTestMixin from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase from lms.djangoapps.survey.models import SurveyAnswer, SurveyForm -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order class SurveyViewsTests(LoginEnrollmentTestCase, SharedModuleStoreTestCase, XssTestMixin): """ All tests for the views.py file """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE STUDENT_INFO = [('view@test.com', 'foo')] @classmethod diff --git a/lms/djangoapps/courseware/tests/test_courses.py b/lms/djangoapps/courseware/tests/test_courses.py index 05d46b0b86..77293624d4 100644 --- a/lms/djangoapps/courseware/tests/test_courses.py +++ b/lms/djangoapps/courseware/tests/test_courses.py @@ -18,6 +18,13 @@ from django.test.client import RequestFactory from django.test.utils import override_settings from django.urls import reverse from opaque_keys.edx.keys import CourseKey +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import _get_modulestore_branch_setting, modulestore +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls +from xmodule.modulestore.xml_importer import import_course_from_xml +from xmodule.tests.xml import XModuleXmlImportTest +from xmodule.tests.xml import factories as xml from lms.djangoapps.courseware.courses import ( course_open_for_self_enrollment, @@ -39,13 +46,6 @@ from openedx.core.djangolib.testing.utils import get_mock_request from openedx.core.lib.courses import course_image_url from openedx.core.lib.courses import get_course_by_id from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.django import _get_modulestore_branch_setting, modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.xml_importer import import_course_from_xml # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.tests.xml import XModuleXmlImportTest # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.tests.xml import factories as xml # lint-amnesty, pylint: disable=wrong-import-order CMS_BASE_TEST = 'testcms' TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT @@ -54,6 +54,7 @@ TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT @ddt.ddt class CoursesTest(ModuleStoreTestCase): """Test methods related to fetching courses.""" + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE ENABLED_SIGNALS = ['course_published'] GET_COURSE_WITH_ACCESS = 'get_course_with_access' GET_COURSE_OVERVIEW_WITH_ACCESS = 'get_course_overview_with_access' @@ -212,18 +213,24 @@ class MongoCourseImageTestCase(ModuleStoreTestCase): def test_get_image_url(self): """Test image URL formatting.""" - course = CourseFactory.create(org='edX', course='999') - assert course_image_url(course) == f'/c4x/edX/999/asset/{course.course_image}' + course = CourseFactory.create() + key = course.location + assert course_image_url(course) ==\ + f'/asset-v1:{key.org}+{key.course}+{key.run}+type@asset+block@{course.course_image}' def test_non_ascii_image_name(self): # Verify that non-ascii image names are cleaned course = CourseFactory.create(course_image='before_\N{SNOWMAN}_after.jpg') - assert course_image_url(course) == f'/c4x/{course.location.org}/{course.location.course}/asset/before___after.jpg' # pylint: disable=line-too-long + key = course.location + assert course_image_url(course) ==\ + f'/asset-v1:{key.org}+{key.course}+{key.run}+type@asset+block@before___after.jpg' def test_spaces_in_image_name(self): # Verify that image names with spaces in them are cleaned course = CourseFactory.create(course_image='before after.jpg') - assert course_image_url(course) == f'/c4x/{course.location.org}/{course.location.course}/asset/before_after.jpg' # pylint: disable=line-too-long + key = course.location + assert course_image_url(course) ==\ + f'/asset-v1:{key.org}+{key.course}+{key.run}+type@asset+block@before_after.jpg' def test_static_asset_path_course_image_default(self): """ @@ -262,6 +269,7 @@ class XmlCourseImageTestCase(XModuleXmlImportTest): class CoursesRenderTest(ModuleStoreTestCase): """Test methods related to rendering courses content.""" + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE # 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. diff --git a/lms/djangoapps/courseware/tests/test_date_summary.py b/lms/djangoapps/courseware/tests/test_date_summary.py index 6c14245181..e3188824a0 100644 --- a/lms/djangoapps/courseware/tests/test_date_summary.py +++ b/lms/djangoapps/courseware/tests/test_date_summary.py @@ -13,6 +13,9 @@ from django.urls import reverse from edx_toggles.toggles.testutils import override_waffle_flag from freezegun import freeze_time from pytz import utc +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory @@ -50,16 +53,11 @@ from openedx.features.course_experience import ( CourseHomeMessages ) from common.djangoapps.student.tests.factories import TEST_PASSWORD, CourseEnrollmentFactory, UserFactory -from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order @ddt.ddt class CourseDateSummaryTest(SharedModuleStoreTestCase): """Tests for course date summary blocks.""" - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - def setUp(self): super().setUp() SelfPacedConfiguration.objects.create(enable_course_home_improvements=True) diff --git a/lms/djangoapps/courseware/tests/test_discussion_xblock.py b/lms/djangoapps/courseware/tests/test_discussion_xblock.py index da1ee79f22..fb45ebba57 100644 --- a/lms/djangoapps/courseware/tests/test_discussion_xblock.py +++ b/lms/djangoapps/courseware/tests/test_discussion_xblock.py @@ -18,6 +18,10 @@ from edx_toggles.toggles.testutils import override_waffle_flag from opaque_keys.edx.keys import CourseKey from web_fragments.fragment import Fragment from xblock.field_data import DictFieldData +from xblock_discussion import DiscussionXBlock, loader +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import ItemFactory, ToyCourseFactory from lms.djangoapps.course_api.blocks.tests.helpers import deserialize_usage_key from lms.djangoapps.courseware.module_render import get_module_for_descriptor_internal @@ -25,11 +29,6 @@ from lms.djangoapps.courseware.tests.helpers import XModuleRenderingTestBase from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory -from xblock_discussion import DiscussionXBlock, loader # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import ItemFactory, ToyCourseFactory # lint-amnesty, pylint: disable=wrong-import-order - @ddt.ddt class TestDiscussionXBlock(XModuleRenderingTestBase): @@ -261,6 +260,7 @@ class TestXBlockInCourse(SharedModuleStoreTestCase): """ Test the discussion xblock as rendered in the course and course API. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE @classmethod def setUpClass(cls): diff --git a/lms/djangoapps/courseware/tests/test_draft_modulestore.py b/lms/djangoapps/courseware/tests/test_draft_modulestore.py index 5f1e6b3c2f..223a866b53 100644 --- a/lms/djangoapps/courseware/tests/test_draft_modulestore.py +++ b/lms/djangoapps/courseware/tests/test_draft_modulestore.py @@ -3,22 +3,20 @@ Test the draft modulestore """ -from django.test import TestCase from opaque_keys.edx.keys import CourseKey -from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_MODULESTORE, ModuleStoreTestCase -class TestDraftModuleStore(TestCase): +class TestDraftModuleStore(ModuleStoreTestCase): """ Test the draft modulestore """ + MODULESTORE = TEST_DATA_MONGO_MODULESTORE def test_get_items_with_course_items(self): - store = modulestore() - # fix was to allow get_items() to take the course_id parameter - store.get_items(CourseKey.from_string('a/b/c'), qualifiers={'category': 'vertical'}) + self.store.get_items(CourseKey.from_string('a/b/c'), qualifiers={'category': 'vertical'}) # test success is just getting through the above statement. # The bug was that 'course_id' argument was diff --git a/lms/djangoapps/courseware/tests/test_entrance_exam.py b/lms/djangoapps/courseware/tests/test_entrance_exam.py index 742565ef5a..dbea9ce190 100644 --- a/lms/djangoapps/courseware/tests/test_entrance_exam.py +++ b/lms/djangoapps/courseware/tests/test_entrance_exam.py @@ -6,10 +6,13 @@ Tests use cases related to LMS Entrance Exam behavior, such as gated content acc from unittest.mock import Mock, patch from crum import set_current_request from django.urls import reverse +from edx_toggles.toggles.testutils import override_waffle_flag from milestones.tests.utils import MilestonesTestCaseMixin +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory -from edx_toggles.toggles.testutils import override_waffle_flag # lint-amnesty, pylint: disable=wrong-import-order from lms.djangoapps.courseware.entrance_exams import ( course_has_entrance_exam, get_entrance_exam_content, @@ -35,9 +38,6 @@ from common.djangoapps.util.milestones_helpers import ( get_milestone_relationship_types, get_namespace_choices ) -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order @patch.dict('django.conf.settings.FEATURES', {'ENTRANCE_EXAMS': True}) @@ -48,6 +48,7 @@ class EntranceExamTestCases(LoginEnrollmentTestCase, ModuleStoreTestCase, Milest Creates a test course from scratch. The tests below are designed to execute workflows regardless of the feature flag settings. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE @patch.dict('django.conf.settings.FEATURES', {'ENTRANCE_EXAMS': True}) def setUp(self): diff --git a/lms/djangoapps/courseware/tests/test_group_access.py b/lms/djangoapps/courseware/tests/test_group_access.py index 4467b2954f..6d42caf090 100644 --- a/lms/djangoapps/courseware/tests/test_group_access.py +++ b/lms/djangoapps/courseware/tests/test_group_access.py @@ -6,14 +6,14 @@ access control rules. import ddt from stevedore.extension import Extension, ExtensionManager +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory +from xmodule.partitions.partitions import USER_PARTITION_SCHEME_NAMESPACE, Group, UserPartition from common.djangoapps.student.tests.factories import StaffFactory from common.djangoapps.student.tests.factories import UserFactory import lms.djangoapps.courseware.access as access -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.partitions.partitions import USER_PARTITION_SCHEME_NAMESPACE, Group, UserPartition # lint-amnesty, pylint: disable=wrong-import-order class MemoryUserPartitionScheme: @@ -57,6 +57,7 @@ class GroupAccessTestCase(ModuleStoreTestCase): Tests to ensure that has_access() correctly enforces the visibility restrictions specified in the `group_access` field of XBlocks. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE def set_user_group(self, user, partition, group): """ diff --git a/lms/djangoapps/courseware/tests/test_masquerade.py b/lms/djangoapps/courseware/tests/test_masquerade.py index 5fe93f41c0..2e34ebed79 100644 --- a/lms/djangoapps/courseware/tests/test_masquerade.py +++ b/lms/djangoapps/courseware/tests/test_masquerade.py @@ -28,6 +28,7 @@ from lms.djangoapps.courseware.masquerade import ( from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase, MasqueradeMixin, masquerade_as_group_member from lms.djangoapps.courseware.tests.test_submitting_problems import ProblemSubmissionTestMixin +from lms.djangoapps.courseware.toggles import COURSEWARE_USE_LEGACY_FRONTEND from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration from openedx.core.djangoapps.user_api.preferences.api import get_user_preference, set_user_preference @@ -41,6 +42,7 @@ from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # li from xmodule.partitions.partitions import Group, UserPartition # lint-amnesty, pylint: disable=wrong-import-order +@override_waffle_flag(COURSEWARE_USE_LEGACY_FRONTEND, active=True) class MasqueradeTestCase(SharedModuleStoreTestCase, LoginEnrollmentTestCase, MasqueradeMixin): """ Base class for masquerade tests that sets up a test course and enrolls a user in the course. diff --git a/lms/djangoapps/courseware/tests/test_module_render.py b/lms/djangoapps/courseware/tests/test_module_render.py index b007a3358a..07d5d7fa80 100644 --- a/lms/djangoapps/courseware/tests/test_module_render.py +++ b/lms/djangoapps/courseware/tests/test_module_render.py @@ -49,6 +49,7 @@ from xmodule.lti_module import LTIBlock from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import ( + TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase, SharedModuleStoreTestCase, upload_file_to_course, @@ -1095,6 +1096,8 @@ class TestTOC(ModuleStoreTestCase): @patch.dict('django.conf.settings.FEATURES', {'ENABLE_SPECIAL_EXAMS': True}) class TestProctoringRendering(SharedModuleStoreTestCase): """Check the Table of Contents for a course""" + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + @classmethod def setUpClass(cls): super().setUpClass() @@ -1416,6 +1419,7 @@ class TestGatedSubsectionRendering(SharedModuleStoreTestCase, MilestonesTestCase """ Test the toc for a course is rendered correctly when there is gated content """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE @classmethod def setUpClass(cls): @@ -1555,9 +1559,8 @@ class TestHtmlModifiers(ModuleStoreTestCase): self.field_data_cache, ) result_fragment = module.render(STUDENT_VIEW) - - assert f'/c4x/{self.course.location.org}/{self.course.location.course}/asset/foo_content' \ - in result_fragment.content + key = self.course.location + assert f'/asset-v1:{key.org}+{key.course}+{key.run}+type@asset+block/foo_content' in result_fragment.content def test_static_badlink_rewrite(self): module = render.get_module( @@ -1568,8 +1571,8 @@ class TestHtmlModifiers(ModuleStoreTestCase): ) result_fragment = module.render(STUDENT_VIEW) - assert f'/c4x/{self.course.location.org}/{self.course.location.course}/asset/file.jpg'\ - in result_fragment.content + key = self.course.location + assert f'/asset-v1:{key.org}+{key.course}+{key.run}+type@asset+block/file.jpg' in result_fragment.content def test_static_asset_path_use(self): ''' @@ -1589,7 +1592,7 @@ class TestHtmlModifiers(ModuleStoreTestCase): def test_course_image(self): url = course_image_url(self.course) - assert url.startswith('/c4x/') + assert url.startswith('/asset-v1:') self.course.static_asset_path = "toy_course_dir" url = course_image_url(self.course) @@ -1693,6 +1696,7 @@ class DetachedXBlock(XBlock): @patch('lms.djangoapps.courseware.module_render.has_access', Mock(return_value=True, autospec=True)) class TestStaffDebugInfo(SharedModuleStoreTestCase): """Tests to verify that Staff Debug Info panel and histograms are displayed to staff.""" + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE @classmethod def setUpClass(cls): @@ -2313,6 +2317,7 @@ class LMSXBlockServiceBindingTest(SharedModuleStoreTestCase): service = runtime.service(descriptor, expected_service) assert service is not None + @XBlock.register_temp_plugin(PureXBlock, identifier='pure') def test_beta_tester_fields_added(self): """ Tests that the beta tester fields are set on LMS runtime. @@ -2566,6 +2571,7 @@ class LmsModuleSystemShimTest(SharedModuleStoreTestCase): """ Tests that the deprecated attributes in the LMS Module System (XBlock Runtime) return the expected values. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE COURSE_ID = 'edX/LmsModuleShimTest/2021_Fall' PYTHON_LIB_FILENAME = 'test_python_lib.zip' PYTHON_LIB_SOURCE_FILE = './common/test/data/uploads/python_lib.zip' diff --git a/lms/djangoapps/courseware/tests/test_navigation.py b/lms/djangoapps/courseware/tests/test_navigation.py index 016a8bff98..b7ea203fb9 100644 --- a/lms/djangoapps/courseware/tests/test_navigation.py +++ b/lms/djangoapps/courseware/tests/test_navigation.py @@ -9,17 +9,19 @@ from unittest.mock import patch from django.conf import settings from django.test.utils import override_settings from django.urls import reverse - from edx_toggles.toggles.testutils import override_waffle_flag +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory + from common.djangoapps.student.tests.factories import GlobalStaffFactory from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase +from lms.djangoapps.courseware.toggles import COURSEWARE_USE_LEGACY_FRONTEND from openedx.features.course_experience import DISABLE_COURSE_OUTLINE_PAGE_FLAG from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order +@override_waffle_flag(COURSEWARE_USE_LEGACY_FRONTEND, active=True) class TestNavigation(SharedModuleStoreTestCase, LoginEnrollmentTestCase): """ Check that navigation state is saved properly. @@ -124,7 +126,7 @@ class TestNavigation(SharedModuleStoreTestCase, LoginEnrollmentTestCase): assert ('course-navigation' in response.content.decode('utf-8')) == accordion self.assertTabInactive('progress', response) - self.assertTabActive('courseware', response) + self.assertTabActive('home', response) response = self.client.get(reverse('courseware_section', kwargs={ 'course_id': str(self.course.id), @@ -133,7 +135,7 @@ class TestNavigation(SharedModuleStoreTestCase, LoginEnrollmentTestCase): })) self.assertTabActive('progress', response) - self.assertTabInactive('courseware', response) + self.assertTabInactive('home', response) @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 6e4ba2c4ab..0aecb0fbb0 100644 --- a/lms/djangoapps/courseware/tests/test_split_module.py +++ b/lms/djangoapps/courseware/tests/test_split_module.py @@ -5,14 +5,14 @@ Test for split test XModule from unittest.mock import MagicMock from django.urls import reverse +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory +from xmodule.partitions.partitions import Group, UserPartition from lms.djangoapps.courseware.model_data import FieldDataCache from lms.djangoapps.courseware.module_render import get_module_for_descriptor from openedx.core.djangoapps.user_api.tests.factories import UserCourseTagFactory from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.partitions.partitions import Group, UserPartition # lint-amnesty, pylint: disable=wrong-import-order class SplitTestBase(SharedModuleStoreTestCase): @@ -21,6 +21,7 @@ class SplitTestBase(SharedModuleStoreTestCase): Also provides tests of rendered HTML for two user_tag conditions, 0 and 1. """ __test__ = False + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE COURSE_NUMBER = 'split-test-base' ICON_CLASSES = None TOOLTIPS = None diff --git a/lms/djangoapps/courseware/tests/test_submitting_problems.py b/lms/djangoapps/courseware/tests/test_submitting_problems.py index 2757bd77db..959458afce 100644 --- a/lms/djangoapps/courseware/tests/test_submitting_problems.py +++ b/lms/djangoapps/courseware/tests/test_submitting_problems.py @@ -7,10 +7,12 @@ Integration tests for submitting problem responses and getting grades. import json import os +from datetime import datetime from textwrap import dedent - from unittest.mock import patch + import ddt +import pytz from django.conf import settings from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.db import connections @@ -208,7 +210,11 @@ class TestSubmittingProblems(ModuleStoreTestCase, LoginEnrollmentTestCase, Probl parent_location=self.chapter.location, display_name=name, category='sequential', - metadata={'graded': True, 'format': section_format, 'due': '2013-05-20T23:30'} + metadata={ + 'graded': True, + 'format': section_format, + 'due': datetime(2013, 5, 20, 23, 30, tzinfo=pytz.utc), + }, ) elif reset: section = ItemFactory.create( diff --git a/lms/djangoapps/courseware/tests/test_view_authentication.py b/lms/djangoapps/courseware/tests/test_view_authentication.py index 3175488985..c758b051a5 100644 --- a/lms/djangoapps/courseware/tests/test_view_authentication.py +++ b/lms/djangoapps/courseware/tests/test_view_authentication.py @@ -8,6 +8,9 @@ import datetime from unittest.mock import patch import pytz from django.urls import reverse +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from common.djangoapps.student.tests.factories import BetaTesterFactory from common.djangoapps.student.tests.factories import GlobalStaffFactory @@ -19,9 +22,6 @@ from lms.djangoapps.courseware.access import has_access from lms.djangoapps.courseware.tests.helpers import CourseAccessTestMixin, LoginEnrollmentTestCase from openedx.features.enterprise_support.tests.mixins.enterprise import EnterpriseTestConsentRequired from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order class TestViewAuth(EnterpriseTestConsentRequired, ModuleStoreTestCase, LoginEnrollmentTestCase): @@ -201,7 +201,8 @@ class TestViewAuth(EnterpriseTestConsentRequired, ModuleStoreTestCase, LoginEnro kwargs={'course_id': str(self.course.id), 'chapter': self.overview_chapter.url_name, 'section': self.welcome_section.url_name} - ) + ), + fetch_redirect_response=False, # just sends us on to MFE ) def test_redirection_missing_enterprise_consent(self): diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index 46accda240..d79b77a33f 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -9,7 +9,7 @@ import json import re from datetime import datetime, timedelta from unittest.mock import MagicMock, PropertyMock, call, create_autospec, patch -from urllib.parse import quote, urlencode +from urllib.parse import urlencode from uuid import uuid4 import ddt @@ -44,7 +44,7 @@ from xmodule.graders import ShowCorrectness from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import ( - TEST_DATA_SPLIT_MODULESTORE, + TEST_DATA_MONGO_AMNESTY_MODULESTORE, CourseUserType, ModuleStoreTestCase, SharedModuleStoreTestCase @@ -164,8 +164,6 @@ class TestJumpTo(ModuleStoreTestCase): """ Check the jumpto link for a course. """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - @ddt.data( (False, None, False), # not provided -> Active experience (False, "blarfingar", False), # nonsense -> Active experience @@ -541,15 +539,15 @@ class ViewsTestCase(BaseViewsTestCase): def test_index_success(self): response = self._verify_index_response() - self.assertContains(response, self.problem2.location) + self.assertContains(response, self.problem2.location.replace(branch=None, version_guid=None)) # re-access to the main course page redirects to last accessed view. url = reverse('courseware', kwargs={'course_id': str(self.course_key)}) response = self.client.get(url) assert response.status_code == 302 response = self.client.get(response.url) - self.assertNotContains(response, self.problem.location) - self.assertContains(response, self.problem2.location) + self.assertNotContains(response, self.problem.location.replace(branch=None, version_guid=None)) + self.assertContains(response, self.problem2.location.replace(branch=None, version_guid=None)) def test_index_nonexistent_chapter(self): self._verify_index_response(expected_response_code=404, chapter_name='non-existent') @@ -1099,9 +1097,8 @@ class ViewsTestCase(BaseViewsTestCase): returning a render_to_string, so we will render via the courseware URL in order to include the needed context """ - course_id = quote(str(self.course.id).encode("utf-8")) response = self.client.get( - reverse('courseware', args=[str(course_id)]), + reverse('courseware', args=[str(self.course.id)]), follow=True ) test_responses = [ @@ -1155,6 +1152,7 @@ class TestProgramMarketingView(SharedModuleStoreTestCase): # setting TIME_ZONE_DISPLAYED_FOR_DEADLINES explicitly @override_settings(TIME_ZONE_DISPLAYED_FOR_DEADLINES="UTC") +@_set_mfe_flag(activate_mfe=False) class BaseDueDateTests(ModuleStoreTestCase): """ Base class that verifies that due dates are rendered correctly on a page @@ -1339,18 +1337,17 @@ class ProgressPageBaseTests(ModuleStoreTestCase): def create_course(self, **options): """Create the test course.""" - self.course = CourseFactory.create( # lint-amnesty, pylint: disable=attribute-defined-outside-init + self.course = CourseFactory.create( # pylint: disable=attribute-defined-outside-init start=datetime(2013, 9, 16, 7, 17, 28), - grade_cutoffs={'çü†øƒƒ': 0.75, 'Pass': 0.5}, end=datetime.now(), certificate_available_date=datetime.now(UTC), certificates_display_behavior=CertificatesDisplayBehaviors.END_WITH_DATE, - **options + **options, ) def setup_course(self, **course_options): """Create the test course and content, and enroll the user.""" - self.create_course(**course_options) + self.create_course(**course_options, grading_policy={'GRADE_CUTOFFS': {'çü†øƒƒ': 0.75, 'Pass': 0.5}}) with self.store.bulk_operations(self.course.id): self.chapter = ItemFactory.create(category='chapter', parent_location=self.course.location) self.section = ItemFactory.create(category='sequential', parent_location=self.chapter.location) @@ -1546,7 +1543,7 @@ class ProgressPageTests(ProgressPageBaseTests): self.course.certificates = {'certificates': certificates} self.course.cert_html_view_enabled = True self.course.save() - self.store.update_item(self.course, self.user.id) + self.update_course(self.course, self.user.id) with patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.read') as mock_create: course_grade = mock_create.return_value @@ -1563,7 +1560,7 @@ class ProgressPageTests(ProgressPageBaseTests): # when course certificate is not active certificates[0]['is_active'] = False - self.store.update_item(self.course, self.user.id) + self.update_course(self.course, self.user.id) resp = self._get_progress_page() self.assertNotContains(resp, "View my Certificate") @@ -1609,7 +1606,7 @@ class ProgressPageTests(ProgressPageBaseTests): # TODO: decrease query count as part of REVO-28 ContentTypeGatingConfig.objects.create(enabled=True, enabled_as_of=datetime(2018, 1, 1)) self.setup_course(self_paced=self_paced) - with self.assertNumQueries(query_count, table_blacklist=QUERY_COUNT_TABLE_BLACKLIST), check_mongo_calls(1): + with self.assertNumQueries(query_count, table_blacklist=QUERY_COUNT_TABLE_BLACKLIST), check_mongo_calls(3): self._get_progress_page() @patch.dict(settings.FEATURES, {'ASSUME_ZERO_GRADE_IF_ABSENT_FOR_ALL_TESTS': False}) @@ -1624,14 +1621,14 @@ class ProgressPageTests(ProgressPageBaseTests): with override_waffle_switch(grades_waffle_switch(ASSUME_ZERO_GRADE_IF_ABSENT), active=enable_waffle): with self.assertNumQueries( initial, table_blacklist=QUERY_COUNT_TABLE_BLACKLIST - ), check_mongo_calls(1): + ), check_mongo_calls(3): self._get_progress_page() # subsequent accesses to the progress page require fewer queries. for _ in range(2): with self.assertNumQueries( subsequent, table_blacklist=QUERY_COUNT_TABLE_BLACKLIST - ), check_mongo_calls(1): + ), check_mongo_calls(3): self._get_progress_page() @ddt.data( @@ -1696,7 +1693,7 @@ class ProgressPageTests(ProgressPageBaseTests): self.course.certificates = {'certificates': certificates} self.course.cert_html_view_enabled = True self.course.save() - self.store.update_item(self.course, self.user.id) + self.update_course(self.course, self.user.id) with patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.read') as mock_create: course_grade = mock_create.return_value @@ -1733,7 +1730,7 @@ class ProgressPageTests(ProgressPageBaseTests): self.course.certificates = {'certificates': certificates} self.course.cert_html_view_enabled = True self.course.save() - self.store.update_item(self.course, self.user.id) + self.update_course(self.course, self.user.id) CertificateAllowlistFactory.create( user=self.user, course_id=self.course.id @@ -2344,8 +2341,8 @@ class GenerateUserCertTests(ModuleStoreTestCase): number='verified', end=datetime.now(), display_name='Verified Course', - grade_cutoffs={'cutoff': 0.75, 'Pass': 0.5}, - self_paced=True + grading_policy={'GRADE_CUTOFFS': {'cutoff': 0.75, 'Pass': 0.5}}, + self_paced=True, ) self.enrollment = CourseEnrollment.enroll(self.student, self.course.id, mode='honor') assert self.client.login(username=self.student, password=TEST_PASSWORD) @@ -2540,6 +2537,7 @@ class TestIndexView(ModuleStoreTestCase): """ Tests of the courseware.views.index view. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE @XBlock.register_temp_plugin(ViewCheckerBlock, 'view_checker') @ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split) @@ -2551,10 +2549,13 @@ class TestIndexView(ModuleStoreTestCase): with modulestore().default_store(default_store): course = CourseFactory.create() - chapter = ItemFactory.create(parent=course, category='chapter') - section = ItemFactory.create(parent=chapter, category='view_checker', display_name="Sequence Checker") - vertical = ItemFactory.create(parent=section, category='view_checker', display_name="Vertical Checker") - block = ItemFactory.create(parent=vertical, category='view_checker', display_name="Block Checker") + chapter = ItemFactory.create(parent_location=course.location, category='chapter') + section = ItemFactory.create(parent_location=chapter.location, category='view_checker', + display_name="Sequence Checker") + vertical = ItemFactory.create(parent_location=section.location, category='view_checker', + display_name="Vertical Checker") + block = ItemFactory.create(parent_location=vertical.location, category='view_checker', + display_name="Block Checker") for item in (section, vertical, block): StudentModuleFactory.create( @@ -2906,6 +2907,7 @@ class TestIndexViewCompleteOnView(ModuleStoreTestCase, CompletionWaffleTestMixin @ddt.ddt +@_set_mfe_flag(activate_mfe=False) class TestIndexViewWithVerticalPositions(ModuleStoreTestCase): """ Test the index view to handle vertical positions. Confirms that first position is loaded @@ -2923,11 +2925,12 @@ class TestIndexViewWithVerticalPositions(ModuleStoreTestCase): # create course with 3 positions self.course = CourseFactory.create() with self.store.bulk_operations(self.course.id): - self.chapter = ItemFactory.create(parent=self.course, category='chapter') - self.section = ItemFactory.create(parent=self.chapter, category='sequential', display_name="Sequence") - ItemFactory.create(parent=self.section, category='vertical', display_name="Vertical1") - ItemFactory.create(parent=self.section, category='vertical', display_name="Vertical2") - ItemFactory.create(parent=self.section, category='vertical', display_name="Vertical3") + self.chapter = ItemFactory.create(parent_location=self.course.location, category='chapter') + self.section = ItemFactory.create(parent_location=self.chapter.location, category='sequential', + display_name="Sequence") + ItemFactory.create(parent_location=self.section.location, category='vertical', display_name="Vertical1") + ItemFactory.create(parent_location=self.section.location, category='vertical', display_name="Vertical2") + ItemFactory.create(parent_location=self.section.location, category='vertical', display_name="Vertical3") CourseOverview.load_from_module_store(self.course.id) @@ -2987,16 +2990,18 @@ class TestIndexViewWithGating(ModuleStoreTestCase, MilestonesTestCaseMixin): with self.store.bulk_operations(self.course.id): self.course.enable_subsection_gating = True self.course.save() - self.store.update_item(self.course, 0) - self.chapter = ItemFactory.create(parent=self.course, category="chapter", display_name="Chapter") + self.course = self.update_course(self.course, 0) + self.chapter = ItemFactory.create( + parent_location=self.course.location, category="chapter", display_name="Chapter", + ) self.open_seq = ItemFactory.create( - parent=self.chapter, category='sequential', display_name="Open Sequential" + parent_location=self.chapter.location, category='sequential', display_name="Open Sequential" ) - ItemFactory.create(parent=self.open_seq, category='problem', display_name="Problem 1") + ItemFactory.create(parent_location=self.open_seq.location, category='problem', display_name="Problem 1") self.gated_seq = ItemFactory.create( - parent=self.chapter, category='sequential', display_name="Gated Sequential" + parent_location=self.chapter.location, category='sequential', display_name="Gated Sequential" ) - ItemFactory.create(parent=self.gated_seq, category='problem', display_name="Problem 2") + ItemFactory.create(parent_location=self.gated_seq.location, category='problem', display_name="Problem 2") gating_api.add_prerequisite(self.course.id, self.open_seq.location) gating_api.set_required_content(self.course.id, self.gated_seq.location, self.open_seq.location, 100) @@ -3037,9 +3042,9 @@ class TestIndexViewWithCourseDurationLimits(ModuleStoreTestCase): self.user = UserFactory() self.course = CourseFactory.create(start=datetime.now() - timedelta(weeks=1)) with self.store.bulk_operations(self.course.id): - self.chapter = ItemFactory.create(parent=self.course, category="chapter") - self.sequential = ItemFactory.create(parent=self.chapter, category='sequential') - self.vertical = ItemFactory.create(parent=self.sequential, category="vertical") + self.chapter = ItemFactory.create(parent_location=self.course.location, category="chapter") + self.sequential = ItemFactory.create(parent_location=self.chapter.location, category='sequential') + self.vertical = ItemFactory.create(parent_location=self.sequential.location, category="vertical") CourseEnrollmentFactory(user=self.user, course_id=self.course.id) @@ -3309,6 +3314,7 @@ class TestRenderXBlockSelfPaced(TestRenderXBlock): # lint-amnesty, pylint: disa return options +@_set_mfe_flag(activate_mfe=False) class TestIndexViewCrawlerStudentStateWrites(SharedModuleStoreTestCase): """ Ensure that courseware index requests do not trigger student state writes. @@ -3441,8 +3447,6 @@ class DatesTabTestCase(ModuleStoreTestCase): """ Ensure that the dates page renders with the correct data for both a verified and audit learner """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - def setUp(self): super().setUp() @@ -3693,8 +3697,6 @@ class TestShowCoursewareMFE(TestCase): @ddt.ddt class MFERedirectTests(BaseViewsTestCase): # lint-amnesty, pylint: disable=missing-class-docstring - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - def test_learner_redirect(self): # learners will be redirected when the waffle flag is set lms_url, mfe_url, __ = self._get_urls() @@ -3740,8 +3742,6 @@ class PreviewRedirectTests(BaseViewsTestCase): * user is global staff member * user is member of the course team """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - def test_staff_no_redirect(self): __, __, preview_url = self._get_urls() with patch.object(access_utils, 'get_current_request_hostname', @@ -3899,8 +3899,8 @@ class TestCourseWideResources(ModuleStoreTestCase): css = ['https://testcdn.com/css/lib.min.css', '//testcdn.com/css/lib2.css', '/test.css'] course = CourseFactory.create(course_wide_js=js, course_wide_css=css) - chapter = ItemFactory.create(parent=course, category='chapter') - sequence = ItemFactory.create(parent=chapter, category='sequential', display_name='Sequence') + chapter = ItemFactory.create(parent_location=course.location, category='chapter') + sequence = ItemFactory.create(parent_location=chapter.location, category='sequential', display_name='Sequence') CourseOverview.load_from_module_store(course.id) CourseEnrollmentFactory(user=user, course_id=course.id) diff --git a/lms/djangoapps/discussion/django_comment_client/base/tests.py b/lms/djangoapps/discussion/django_comment_client/base/tests.py index 3b65c46365..1c313342d2 100644 --- a/lms/djangoapps/discussion/django_comment_client/base/tests.py +++ b/lms/djangoapps/discussion/django_comment_client/base/tests.py @@ -52,7 +52,9 @@ from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES from openedx.core.lib.teams_config import TeamsConfig from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase +from xmodule.modulestore.tests.django_utils import ( + TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase, SharedModuleStoreTestCase, +) from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls from .event_transformers import ForumThreadViewedEventTransformer @@ -2031,6 +2033,7 @@ class ForumThreadViewedEventTransformerTestCase(ForumsEnableMixin, UrlResetMixin sources (e.g., a mobile app), we carefully test a myriad of cases, including those with incomplete and malformed events. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE CATEGORY_ID = 'i4x-edx-discussion-id' CATEGORY_NAME = 'Discussion 1' diff --git a/lms/djangoapps/discussion/django_comment_client/tests/test_utils.py b/lms/djangoapps/discussion/django_comment_client/tests/test_utils.py index 58ef1a33e6..63bf1e7be1 100644 --- a/lms/djangoapps/discussion/django_comment_client/tests/test_utils.py +++ b/lms/djangoapps/discussion/django_comment_client/tests/test_utils.py @@ -1075,7 +1075,7 @@ class ContentGroupCategoryMapTestCase(CategoryMapTestMixin, ContentGroupTestCase 'General': { 'sort_key': 'General', 'is_divided': False, - 'id': 'i4x-org-number-course-run' + 'id': 'course' } } }, @@ -1115,7 +1115,7 @@ class ContentGroupCategoryMapTestCase(CategoryMapTestMixin, ContentGroupTestCase 'General': { 'sort_key': 'General', 'is_divided': False, - 'id': 'i4x-org-number-course-run' + 'id': 'course' } } }, @@ -1152,7 +1152,7 @@ class ContentGroupCategoryMapTestCase(CategoryMapTestMixin, ContentGroupTestCase 'General': { 'sort_key': 'General', 'is_divided': False, - 'id': 'i4x-org-number-course-run' + 'id': 'course' } } }, @@ -1186,7 +1186,7 @@ class ContentGroupCategoryMapTestCase(CategoryMapTestMixin, ContentGroupTestCase 'General': { 'sort_key': 'General', 'is_divided': False, - 'id': 'i4x-org-number-course-run' + 'id': 'course' } } }, diff --git a/lms/djangoapps/discussion/rest_api/tests/test_api.py b/lms/djangoapps/discussion/rest_api/tests/test_api.py index 92d3baef35..1ed30aa2d0 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_api.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_api.py @@ -22,9 +22,7 @@ from rest_framework.exceptions import PermissionDenied from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import ( - TEST_DATA_SPLIT_MODULESTORE, - ModuleStoreTestCase, - SharedModuleStoreTestCase + TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase, SharedModuleStoreTestCase, ) from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from xmodule.partitions.partitions import Group, UserPartition @@ -157,6 +155,7 @@ def _set_course_discussion_blackout(course, user_id): @ddt.ddt class GetCourseTest(ForumsEnableMixin, UrlResetMixin, SharedModuleStoreTestCase): """Test for get_course""" + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE @classmethod def setUpClass(cls): @@ -220,6 +219,7 @@ class GetCourseTestBlackouts(ForumsEnableMixin, UrlResetMixin, ModuleStoreTestCa """ Tests of get_course for courses that have blackout dates. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE @mock.patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) def setUp(self): @@ -258,6 +258,8 @@ class GetCourseTestBlackouts(ForumsEnableMixin, UrlResetMixin, ModuleStoreTestCa @mock.patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) class GetCourseTopicsTest(CommentsServiceMockMixin, ForumsEnableMixin, UrlResetMixin, ModuleStoreTestCase): """Test for get_course_topics""" + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + @mock.patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) def setUp(self): httpretty.reset() @@ -648,6 +650,7 @@ class GetCourseTopicsTest(CommentsServiceMockMixin, ForumsEnableMixin, UrlResetM @mock.patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) class GetThreadListTest(ForumsEnableMixin, CommentsServiceMockMixin, UrlResetMixin, SharedModuleStoreTestCase): """Test for get_thread_list""" + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE @classmethod def setUpClass(cls): @@ -1727,6 +1730,7 @@ class CreateThreadTest( MockSignalHandlerMixin ): """Tests for create_thread""" + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE LONG_TITLE = ( 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. ' 'Aenean commodo ligula eget dolor. Aenean massa. Cum sociis ' @@ -2085,6 +2089,8 @@ class CreateCommentTest( MockSignalHandlerMixin ): """Tests for create_comment""" + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + @classmethod def setUpClass(cls): super().setUpClass() @@ -2445,6 +2451,8 @@ class UpdateThreadTest( MockSignalHandlerMixin ): """Tests for update_thread""" + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + @classmethod def setUpClass(cls): super().setUpClass() @@ -2798,6 +2806,7 @@ class UpdateCommentTest( MockSignalHandlerMixin ): """Tests for update_comment""" + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE @classmethod def setUpClass(cls): @@ -3582,8 +3591,6 @@ class CourseTopicsV2Test(ModuleStoreTestCase): """ Tests for discussions topic API v2 code. """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - def setUp(self) -> None: super().setUp() self.course = CourseFactory.create( diff --git a/lms/djangoapps/discussion/rest_api/tests/test_serializers.py b/lms/djangoapps/discussion/rest_api/tests/test_serializers.py index 2e462177ab..2f5afadb34 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_serializers.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_serializers.py @@ -11,7 +11,7 @@ import httpretty from django.test.client import RequestFactory from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.student.tests.factories import UserFactory @@ -414,6 +414,8 @@ class ThreadSerializerDeserializationTest( SharedModuleStoreTestCase ): """Tests for ThreadSerializer deserialization.""" + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + @classmethod @mock.patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) def setUpClass(cls): @@ -646,6 +648,8 @@ class ThreadSerializerDeserializationTest( @ddt.ddt class CommentSerializerDeserializationTest(ForumsEnableMixin, CommentsServiceMockMixin, SharedModuleStoreTestCase): """Tests for ThreadSerializer deserialization.""" + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + @classmethod def setUpClass(cls): super().setUpClass() diff --git a/lms/djangoapps/discussion/rest_api/tests/test_views.py b/lms/djangoapps/discussion/rest_api/tests/test_views.py index f47b5e1d6b..36ba3a0c1c 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_views.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_views.py @@ -20,7 +20,7 @@ from rest_framework.test import APIClient, APITestCase from rest_framework import status 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 TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls from common.djangoapps.course_modes.models import CourseMode @@ -484,6 +484,8 @@ class CommentViewSetListByUserTest( @mock.patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) class CourseViewTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): """Tests for CourseView""" + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + def setUp(self): super().setUp() self.url = reverse("discussion_course", kwargs={"course_id": str(self.course.id)}) @@ -693,6 +695,7 @@ class CourseTopicsViewTest(DiscussionAPIViewTestMixin, CommentsServiceMockMixin, """ Tests for CourseTopicsView """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE def setUp(self): httpretty.reset() @@ -863,6 +866,8 @@ class CourseTopicsViewTest(DiscussionAPIViewTestMixin, CommentsServiceMockMixin, @mock.patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase, ProfileImageTestMixin): """Tests for ThreadViewSet list""" + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + def setUp(self): super().setUp() self.author = UserFactory.create() @@ -1204,6 +1209,8 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase, Pro @mock.patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) class ThreadViewSetCreateTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): """Tests for ThreadViewSet create""" + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + def setUp(self): super().setUp() self.url = reverse("thread-list") @@ -1273,6 +1280,8 @@ class ThreadViewSetCreateTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): @mock.patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) class ThreadViewSetPartialUpdateTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase, PatchMediaTypeMixin): """Tests for ThreadViewSet partial_update""" + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + def setUp(self): self.unsupported_media_type = JSONParser.media_type super().setUp() @@ -1865,6 +1874,8 @@ class CommentViewSetDeleteTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): @mock.patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) class CommentViewSetCreateTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): """Tests for CommentViewSet create""" + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + def setUp(self): super().setUp() self.url = reverse("comment-list") @@ -1953,6 +1964,8 @@ class CommentViewSetCreateTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): @mock.patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) class CommentViewSetPartialUpdateTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase, PatchMediaTypeMixin): """Tests for CommentViewSet partial_update""" + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + def setUp(self): self.unsupported_media_type = JSONParser.media_type super().setUp() @@ -2246,6 +2259,8 @@ class CourseDiscussionSettingsAPIViewTest(APITestCase, UrlResetMixin, ModuleStor """ Test the course discussion settings handler API endpoint. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + @mock.patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) def setUp(self): super().setUp() @@ -2489,6 +2504,8 @@ class CourseDiscussionRolesAPIViewTest(APITestCase, UrlResetMixin, ModuleStoreTe """ Test the course discussion roles management endpoint. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + @mock.patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) def setUp(self): super().setUp() diff --git a/lms/djangoapps/discussion/tests/test_views.py b/lms/djangoapps/discussion/tests/test_views.py index 942b944c1b..4b4df1f810 100644 --- a/lms/djangoapps/discussion/tests/test_views.py +++ b/lms/djangoapps/discussion/tests/test_views.py @@ -20,6 +20,7 @@ from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import ( TEST_DATA_MONGO_MODULESTORE, + TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase, SharedModuleStoreTestCase ) @@ -1903,6 +1904,7 @@ class CourseDiscussionTopicsTestCase(DividedDiscussionsTestCase): """ Tests the `divide_discussion_topics` view. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE def test_non_staff(self): """ @@ -1958,6 +1960,7 @@ class CourseDiscussionsHandlerTestCase(DividedDiscussionsTestCase): """ Tests the course_discussion_settings_handler """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE def get_expected_response(self): """ diff --git a/lms/djangoapps/experiments/tests/test_utils.py b/lms/djangoapps/experiments/tests/test_utils.py index 9626446d94..b32bea73c3 100644 --- a/lms/djangoapps/experiments/tests/test_utils.py +++ b/lms/djangoapps/experiments/tests/test_utils.py @@ -8,10 +8,11 @@ from unittest import TestCase from django.utils.timezone import now from opaque_keys.edx.keys import CourseKey +from xmodule.modulestore.tests.factories import CourseFactory +from xmodule.partitions.partitions import Group from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from lms.djangoapps.course_blocks.transformers.tests.helpers import ModuleStoreTestCase -from lms.djangoapps.courseware import courses # lint-amnesty, pylint: disable=unused-import from lms.djangoapps.experiments.utils import ( get_course_entitlement_price_and_sku, get_experiment_user_metadata_context, @@ -19,7 +20,6 @@ from lms.djangoapps.experiments.utils import ( get_unenrolled_courses, is_enrolled_in_course_run ) -from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order class ExperimentUtilsTests(ModuleStoreTestCase, TestCase): @@ -124,36 +124,39 @@ class ExperimentUtilsTests(ModuleStoreTestCase, TestCase): assert self.entitlement_a_sku in skus def test_get_experiment_user_metadata_context(self): - course = CourseFactory.create(start=now() - timedelta(days=30), pacing_type="instructor_paced", course_duration=None, upgrade_price='Free', # lint-amnesty, pylint: disable=line-too-long - upgrade_link=None, enrollment_mode=None, audit_access_deadline=None, program_key_fields=None, schedule_start=None, # lint-amnesty, pylint: disable=line-too-long - enrollment_time=None, dynamic_upgrade_deadline=None, course_upgrade_deadline=None, course_key_fields={'org': 'org.0', 'course': 'course_0', 'run': 'Run_0'}) # lint-amnesty, pylint: disable=line-too-long + course = CourseFactory.create(start=now() - timedelta(days=30)) user = UserFactory() + enrollment = CourseEnrollmentFactory(course_id=course.id, user=user) context = get_experiment_user_metadata_context(course, user) - CourseEnrollmentFactory(course_id=course.id, user=user) user_metadata_expected_result = {'username': user.username, 'user_id': user.id, - 'course_id': course.id, - 'enrollment_mode': course.enrollment_mode, - 'upgrade_link': course.upgrade_link, - 'upgrade_price': course.upgrade_price, - 'audit_access_deadline': course.audit_access_deadline, - 'course_duration': course.course_duration, - 'pacing_type': course.pacing_type, + 'course_id': str(course.id), + 'course_display_name': course.display_name_with_default, + 'enrollment_mode': enrollment.mode, + 'upgrade_link': None, + 'upgrade_price': 'Free', + 'audit_access_deadline': None, + 'course_duration': None, + 'pacing_type': 'instructor_paced', 'has_staff_access': False, - 'forum_roles': [], - 'partition_groups': {}, + 'forum_roles': [('Student',)], + 'partition_groups': {'Enrollment Track Groups': Group(id=1, name='Audit')}, 'has_non_audit_enrollments': False, - 'program_key_fields': course.program_key_fields, + 'program_key_fields': None, 'email': user.email, - 'schedule_start': course.schedule_start, - 'enrollment_time': course.enrollment_time, - 'course_start': course.start, + 'schedule_start': enrollment.schedule.start_date.isoformat(), + 'enrollment_time': enrollment.created.isoformat(), + 'course_start': course.start.isoformat(), 'course_end': course.end, - 'dynamic_upgrade_deadline': course.dynamic_upgrade_deadline, - 'course_upgrade_deadline': course.course_upgrade_deadline, - 'course_key_fields': course.course_key_fields} + 'dynamic_upgrade_deadline': None, + 'course_upgrade_deadline': None, + 'course_key_fields': { + 'org': course.id.org, + 'course': course.id.course, + 'run': course.id.run, + }} user_metadata = context.get('user_metadata') - assert user_metadata, user_metadata_expected_result + assert user_metadata == user_metadata_expected_result diff --git a/lms/djangoapps/gating/tests/test_api.py b/lms/djangoapps/gating/tests/test_api.py index 92799c50cb..6ddd4484c5 100644 --- a/lms/djangoapps/gating/tests/test_api.py +++ b/lms/djangoapps/gating/tests/test_api.py @@ -37,7 +37,7 @@ class GatingTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase): ) self.course.enable_subsection_gating = True self.course.save() - self.store.update_item(self.course, 0) + self.update_course(self.course, 0) # create chapter self.chapter1 = ItemFactory.create( diff --git a/lms/djangoapps/gating/tests/test_integration.py b/lms/djangoapps/gating/tests/test_integration.py index 89503a35a0..b58073f5c2 100644 --- a/lms/djangoapps/gating/tests/test_integration.py +++ b/lms/djangoapps/gating/tests/test_integration.py @@ -10,6 +10,9 @@ from edx_django_utils.cache import RequestCache from edx_toggles.toggles.testutils import override_waffle_switch from milestones import api as milestones_api from milestones.tests.utils import MilestonesTestCaseMixin +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.courseware.access import has_access @@ -17,9 +20,6 @@ from lms.djangoapps.grades.api import CourseGradeFactory from lms.djangoapps.grades.tests.utils import answer_problem from openedx.core.djangolib.testing.utils import get_mock_request from openedx.core.lib.gating import api as gating_api -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order @ddt.ddt @@ -28,6 +28,7 @@ class TestGatedContent(MilestonesTestCaseMixin, SharedModuleStoreTestCase): Base TestCase class for setting up a basic course structure and testing the gating feature """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE @classmethod def setUpClass(cls): diff --git a/lms/djangoapps/grades/rest_api/v1/tests/mixins.py b/lms/djangoapps/grades/rest_api/v1/tests/mixins.py index 2c84d4bf75..54851fecc3 100644 --- a/lms/djangoapps/grades/rest_api/v1/tests/mixins.py +++ b/lms/djangoapps/grades/rest_api/v1/tests/mixins.py @@ -6,13 +6,13 @@ Mixins classes being used by all test classes within this folder from datetime import datetime from pytz import UTC +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from common.djangoapps.student.tests.factories import GlobalStaffFactory from lms.djangoapps.program_enrollments.tests.factories import ProgramCourseEnrollmentFactory, ProgramEnrollmentFactory from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order class GradeViewTestMixin(SharedModuleStoreTestCase): @@ -54,8 +54,6 @@ class GradeViewTestMixin(SharedModuleStoreTestCase): } } """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - @classmethod def setUpClass(cls): super().setUpClass() diff --git a/lms/djangoapps/grades/rest_api/v1/tests/test_gradebook_views.py b/lms/djangoapps/grades/rest_api/v1/tests/test_gradebook_views.py index 1baf1cdcca..7b8e631527 100644 --- a/lms/djangoapps/grades/rest_api/v1/tests/test_gradebook_views.py +++ b/lms/djangoapps/grades/rest_api/v1/tests/test_gradebook_views.py @@ -18,6 +18,8 @@ from opaque_keys.edx.locator import BlockUsageLocator from pytz import UTC from rest_framework import status from rest_framework.test import APITestCase +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.roles import ( @@ -48,8 +50,6 @@ from lms.djangoapps.grades.rest_api.v1.views import CourseEnrollmentPagination from lms.djangoapps.grades.subsection_grade import ReadSubsectionGrade from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order # pylint: disable=unused-variable @@ -58,7 +58,6 @@ class CourseGradingViewTest(SharedModuleStoreTestCase, APITestCase): Test course grading view via a RESTful API """ view_name = 'grades_api:v1:course_gradebook_grading_info' - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE @classmethod def setUpClass(cls): diff --git a/lms/djangoapps/grades/rest_api/v1/tests/test_grading_policy_view.py b/lms/djangoapps/grades/rest_api/v1/tests/test_grading_policy_view.py index 92a8e7a091..440136c757 100644 --- a/lms/djangoapps/grades/rest_api/v1/tests/test_grading_policy_view.py +++ b/lms/djangoapps/grades/rest_api/v1/tests/test_grading_policy_view.py @@ -8,15 +8,15 @@ from datetime import datetime import ddt from django.urls import reverse from pytz import UTC +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory from common.djangoapps.student.tests.factories import GlobalStaffFactory from common.djangoapps.student.tests.factories import StaffFactory from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.oauth_dispatch.tests.factories import AccessTokenFactory, ApplicationFactory -from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order @ddt.ddt @@ -160,6 +160,7 @@ class CourseGradingPolicyTests(GradingPolicyTestMixin, SharedModuleStoreTestCase """ Tests for CourseGradingPolicy view. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE view_name = 'grades_api:v1:course_grading_policy' raw_grader = [ @@ -211,6 +212,7 @@ class CourseGradingPolicyMissingFieldsTests(GradingPolicyTestMixin, SharedModule """ Tests for CourseGradingPolicy view when fields are missing. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE view_name = 'grades_api:v1:course_grading_policy' # Raw grader with missing keys diff --git a/lms/djangoapps/grades/tests/base.py b/lms/djangoapps/grades/tests/base.py index 9ef009990e..5fe1618fba 100644 --- a/lms/djangoapps/grades/tests/base.py +++ b/lms/djangoapps/grades/tests/base.py @@ -4,14 +4,14 @@ Base file for Grades tests from crum import set_current_request +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.course_blocks.api import get_course_blocks from openedx.core.djangolib.testing.utils import get_mock_request -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order from ..course_data import CourseData from ..subsection_grade_factory import SubsectionGradeFactory @@ -21,6 +21,8 @@ class GradeTestBase(SharedModuleStoreTestCase): """ Base class for some Grades tests. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + @classmethod def setUpClass(cls): super().setUpClass() diff --git a/lms/djangoapps/grades/tests/integration/test_problems.py b/lms/djangoapps/grades/tests/integration/test_problems.py index dd547268f2..8fdf2fbf1e 100644 --- a/lms/djangoapps/grades/tests/integration/test_problems.py +++ b/lms/djangoapps/grades/tests/integration/test_problems.py @@ -5,6 +5,14 @@ import itertools import ddt import pytz from crum import set_current_request +from xmodule.graders import ProblemScore +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.tests.django_utils import ( + TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase, SharedModuleStoreTestCase, +) +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory +from xmodule.modulestore.tests.utils import TEST_DATA_DIR +from xmodule.modulestore.xml_importer import import_course_from_xml from capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory from common.djangoapps.student.models import CourseEnrollment @@ -12,12 +20,6 @@ from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.course_blocks.api import get_course_blocks from lms.djangoapps.courseware.tests.test_submitting_problems import ProblemSubmissionTestMixin from openedx.core.djangolib.testing.utils import get_mock_request -from xmodule.graders import ProblemScore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.utils import TEST_DATA_DIR # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.xml_importer import import_course_from_xml # lint-amnesty, pylint: disable=wrong-import-order from ...subsection_grade_factory import SubsectionGradeFactory from ..utils import answer_problem, mock_get_submissions_score @@ -28,6 +30,7 @@ class TestMultipleProblemTypesSubsectionScores(SharedModuleStoreTestCase): """ Test grading of different problem types. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE SCORED_BLOCK_COUNT = 7 ACTUAL_TOTAL_POSSIBLE = 17.0 @@ -102,6 +105,8 @@ class TestVariedMetadata(ProblemSubmissionTestMixin, ModuleStoreTestCase): Test that changing the metadata on a block has the desired effect on the persisted score. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + default_problem_metadata = { 'graded': True, 'weight': 2.5, @@ -210,6 +215,7 @@ class TestWeightedProblems(SharedModuleStoreTestCase): """ Test scores and grades with various problem weight values. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE @classmethod def setUpClass(cls): diff --git a/lms/djangoapps/grades/tests/test_api.py b/lms/djangoapps/grades/tests/test_api.py index e988d43a30..62c92ad5d3 100644 --- a/lms/djangoapps/grades/tests/test_api.py +++ b/lms/djangoapps/grades/tests/test_api.py @@ -41,7 +41,7 @@ class OverrideSubsectionGradeTests(ModuleStoreTestCase): def setUp(self): super().setUp() self.course = CourseFactory.create(org='edX', number='DemoX', display_name='Demo_Course', run='Spring2019') - self.subsection = ItemFactory.create(parent=self.course, category="subsection", display_name="Subsection") + self.subsection = ItemFactory.create(parent=self.course, category="sequential", display_name="Subsection") self.grade = PersistentSubsectionGrade.update_or_create_grade( user_id=self.user.id, course_id=self.course.id, diff --git a/lms/djangoapps/grades/tests/test_course_grade.py b/lms/djangoapps/grades/tests/test_course_grade.py index 81cd69e642..c59f3ac73b 100644 --- a/lms/djangoapps/grades/tests/test_course_grade.py +++ b/lms/djangoapps/grades/tests/test_course_grade.py @@ -5,12 +5,12 @@ import ddt from crum import set_current_request from django.conf import settings from edx_toggles.toggles.testutils import override_waffle_switch +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangolib.testing.utils import get_mock_request -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order from ..config.waffle import ASSUME_ZERO_GRADE_IF_ABSENT, waffle_switch from ..course_data import CourseData @@ -73,6 +73,7 @@ class TestScoreForModule(SharedModuleStoreTestCase): (2/5) (3/5) (0/1) - (1/3) - (3/10) """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE @classmethod def setUpClass(cls): diff --git a/lms/djangoapps/grades/tests/test_services.py b/lms/djangoapps/grades/tests/test_services.py index 26f3013b00..e77af77e28 100644 --- a/lms/djangoapps/grades/tests/test_services.py +++ b/lms/djangoapps/grades/tests/test_services.py @@ -43,10 +43,10 @@ class GradesServiceTests(ModuleStoreTestCase): super().setUp() self.service = GradesService() self.course = CourseFactory.create(org='edX', number='DemoX', display_name='Demo_Course', run='Spring2019') - self.subsection = ItemFactory.create(parent=self.course, category="subsection", display_name="Subsection") + self.subsection = ItemFactory.create(parent=self.course, category="sequential", display_name="Subsection") self.subsection_without_grade = ItemFactory.create( parent=self.course, - category="subsection", + category="sequential", display_name="Subsection without grade" ) self.user = UserFactory() diff --git a/lms/djangoapps/grades/tests/test_tasks.py b/lms/djangoapps/grades/tests/test_tasks.py index 9c40423621..ab58bbe29f 100644 --- a/lms/djangoapps/grades/tests/test_tasks.py +++ b/lms/djangoapps/grades/tests/test_tasks.py @@ -16,6 +16,9 @@ from django.conf import settings from django.db.utils import IntegrityError from django.utils import timezone from edx_toggles.toggles.testutils import override_waffle_flag +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls from common.djangoapps.student.models import CourseEnrollment, anonymous_id_for_user from common.djangoapps.student.tests.factories import UserFactory @@ -36,10 +39,6 @@ from lms.djangoapps.grades.tasks import ( recalculate_subsection_grade_v3 ) from openedx.core.djangoapps.content.block_structure.exceptions import BlockStructureNotFound -from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls # lint-amnesty, pylint: disable=wrong-import-order from .utils import mock_get_score @@ -209,7 +208,8 @@ class RecalculateSubsectionGradeTest(HasCourseWithProblemsMixin, ModuleStoreTest # So in total, 3 sequential parents, with one inaccessible. for sequential in (accessible_seq, inaccessible_seq): sequential.children = [self.problem.location] - modulestore().update_item(sequential, self.user.id) + with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, self.course.id): + self.store.update_item(sequential, self.user.id) # Make sure the signal is sent for only the 2 accessible sequentials. self._apply_recalculate_subsection_grade() diff --git a/lms/djangoapps/instructor/tests/test_api.py b/lms/djangoapps/instructor/tests/test_api.py index 86d7ce8d7b..e4c5110e8c 100644 --- a/lms/djangoapps/instructor/tests/test_api.py +++ b/lms/djangoapps/instructor/tests/test_api.py @@ -27,6 +27,12 @@ from edx_toggles.toggles.testutils import override_waffle_flag from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import UsageKey from pytz import UTC +from xmodule.fields import Date +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.tests.django_utils import ( + TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase, SharedModuleStoreTestCase, +) +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory @@ -88,10 +94,6 @@ from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin from openedx.core.lib.teams_config import TeamsConfig from openedx.core.lib.xblock_utils import grade_histogram from openedx.features.course_experience import RELATIVE_DATES_FLAG -from xmodule.fields import Date # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order from .test_tools import msk_from_problem_urlname @@ -3091,6 +3093,8 @@ class TestEntranceExamInstructorAPIRegradeTask(SharedModuleStoreTestCase, LoginE Test endpoints whereby instructors can rescore student grades, reset student attempts and delete state for entrance exam. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + @classmethod def setUpClass(cls): super().setUpClass() @@ -3871,6 +3875,8 @@ class TestDueDateExtensions(SharedModuleStoreTestCase, LoginEnrollmentTestCase): """ Test data dumps for reporting. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + @classmethod def setUpClass(cls): super().setUpClass() @@ -4045,6 +4051,7 @@ class TestDueDateExtensionsDeletedDate(ModuleStoreTestCase, LoginEnrollmentTestC """ Tests for deleting due date extensions """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE def setUp(self): """ diff --git a/lms/djangoapps/instructor/tests/test_enrollment.py b/lms/djangoapps/instructor/tests/test_enrollment.py index 5fe59c40e8..1a56471dbd 100644 --- a/lms/djangoapps/instructor/tests/test_enrollment.py +++ b/lms/djangoapps/instructor/tests/test_enrollment.py @@ -16,6 +16,8 @@ from django.utils.translation import get_language from django.utils.translation import override as override_language from opaque_keys.edx.locator import CourseLocator from submissions import api as sub_api +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory from common.djangoapps.student.models import CourseEnrollment, CourseEnrollmentAllowed, anonymous_id_for_user @@ -39,8 +41,6 @@ from lms.djangoapps.teams.models import CourseTeamMembership from lms.djangoapps.teams.tests.factories import CourseTeamFactory from openedx.core.djangoapps.ace_common.tests.mixins import EmailTemplateTagMixin from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, get_mock_request -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order class TestSettableEnrollmentState(CacheIsolationTestCase): @@ -368,6 +368,8 @@ class TestInstructorUnenrollDB(TestEnrollmentChangeBase): class TestInstructorEnrollmentStudentModule(SharedModuleStoreTestCase): """ Test student module manipulations. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + @classmethod def setUpClass(cls): super().setUpClass() @@ -869,9 +871,6 @@ class TestGetEmailParamsCCX(SharedModuleStoreTestCase): """ Test what URLs the function get_email_params for CCX student enrollment. """ - - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - @classmethod def setUpClass(cls): super().setUpClass() @@ -961,8 +960,6 @@ class TestRenderMessageToString(EmailTemplateTagMixin, SharedModuleStoreTestCase Test that email templates can be rendered in a language chosen manually. Test CCX enrollmet email. """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - @classmethod def setUpClass(cls): super().setUpClass() diff --git a/lms/djangoapps/instructor/tests/test_tools.py b/lms/djangoapps/instructor/tests/test_tools.py index 183a32588d..cffd7edb47 100644 --- a/lms/djangoapps/instructor/tests/test_tools.py +++ b/lms/djangoapps/instructor/tests/test_tools.py @@ -16,12 +16,14 @@ from edx_when.api import set_dates_for_course from edx_when.field_data import DateLookupFieldData from opaque_keys.edx.keys import CourseKey from pytz import UTC +from xmodule.fields import Date +from xmodule.modulestore.tests.django_utils import ( + TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase, SharedModuleStoreTestCase, +) +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory from openedx.core.djangoapps.course_date_signals import handlers -from xmodule.fields import Date # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order from ..views import tools @@ -99,6 +101,8 @@ class TestFindUnit(SharedModuleStoreTestCase): """ Test the find_unit function. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + @classmethod def setUpClass(cls): super().setUpClass() @@ -128,6 +132,8 @@ class TestGetUnitsWithDueDate(ModuleStoreTestCase): """ Test the get_units_with_due_date function. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + def setUp(self): """ Fixtures. @@ -193,6 +199,8 @@ class TestSetDueDateExtension(ModuleStoreTestCase): """ Test the set_due_date_extensions function. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + def setUp(self): """ Fixtures. @@ -281,6 +289,7 @@ class TestDataDumps(ModuleStoreTestCase): """ Test data dumps for reporting. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE def setUp(self): """ diff --git a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py index 3047653343..4095b70457 100644 --- a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py +++ b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py @@ -14,6 +14,9 @@ from django.urls import reverse from edx_toggles.toggles.testutils import override_waffle_flag from pyquery import PyQuery as pq from pytz import UTC +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.edxmako.shortcuts import render_to_response @@ -36,9 +39,6 @@ from openedx.core.djangoapps.discussions.config.waffle import ( OVERRIDE_DISCUSSION_LEGACY_SETTINGS_FLAG ) from openedx.core.djangoapps.site_configuration.models import SiteConfiguration -from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls # lint-amnesty, pylint: disable=wrong-import-order def intercept_renderer(path, context): @@ -81,7 +81,7 @@ class TestInstructorDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase, XssT org="ACME", number="001", run="2017", - name="How to defeat the Road Runner" + display_name="How to defeat the Road Runner" ) self.course_mode.save() # Create instructor account @@ -604,8 +604,6 @@ class TestInstructorDashboardPerformance(ModuleStoreTestCase, LoginEnrollmentTes """ Tests for the instructor dashboard from the performance point of view. """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - def setUp(self): """ Set up tests diff --git a/lms/djangoapps/instructor_task/tests/test_base.py b/lms/djangoapps/instructor_task/tests/test_base.py index f264ea9419..61e0984cd2 100644 --- a/lms/djangoapps/instructor_task/tests/test_base.py +++ b/lms/djangoapps/instructor_task/tests/test_base.py @@ -18,6 +18,10 @@ from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imp from django.urls import reverse from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locations import Location +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from capa.tests.response_xml_factory import OptionResponseXMLFactory from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory @@ -29,10 +33,6 @@ from lms.djangoapps.instructor_task.tests.factories import InstructorTaskFactory from lms.djangoapps.instructor_task.views import instructor_task_status from openedx.core.djangolib.testing.utils import CacheIsolationTestCase from openedx.core.lib.url_utils import quote_slashes -from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order TEST_COURSE_ORG = 'edx' TEST_COURSE_NAME = 'test_course' @@ -108,6 +108,7 @@ class InstructorTaskCourseTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase) Base test class for InstructorTask-related tests that require the setup of a course. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE course = None current_user = None diff --git a/lms/djangoapps/instructor_task/tests/test_tasks_helper.py b/lms/djangoapps/instructor_task/tests/test_tasks_helper.py index 8cf5b125c3..41c65f7f84 100644 --- a/lms/djangoapps/instructor_task/tests/test_tasks_helper.py +++ b/lms/djangoapps/instructor_task/tests/test_tasks_helper.py @@ -14,7 +14,6 @@ from collections import OrderedDict from contextlib import ExitStack, contextmanager from datetime import datetime, timedelta from unittest.mock import ANY, MagicMock, Mock, patch -from urllib.parse import quote import ddt import unicodecsv @@ -2573,8 +2572,8 @@ class TestInstructorOra2Report(SharedModuleStoreTestCase): return_val = upload_ora2_data(None, None, self.course.id, None, 'generated') timestamp_str = datetime.now(UTC).strftime('%Y-%m-%d-%H%M') - course_id_string = quote(str(self.course.id).replace('/', '_')) - filename = f'{course_id_string}_ORA_data_{timestamp_str}.csv' + key = self.course.id + filename = f'{key.org}_{key.course}_{key.run}_ORA_data_{timestamp_str}.csv' assert return_val == UPDATE_STATUS_SUCCEEDED mock_store_rows.assert_called_once_with(self.course.id, filename, [test_header] + test_rows, '') @@ -2626,8 +2625,8 @@ class TestInstructorOra2AttachmentsExport(SharedModuleStoreTestCase): return_val = upload_ora2_summary(None, None, self.course.id, None, 'generated') timestamp_str = datetime.now(UTC).strftime('%Y-%m-%d-%H%M') - course_id_string = quote(str(self.course.id).replace('/', '_')) - filename = f'{course_id_string}_ORA_summary_{timestamp_str}.csv' + key = self.course.id + filename = f'{key.org}_{key.course}_{key.run}_ORA_summary_{timestamp_str}.csv' self.assertEqual(return_val, UPDATE_STATUS_SUCCEEDED) mock_store_rows.assert_called_once_with(self.course.id, filename, [test_header] + test_rows, '') diff --git a/lms/djangoapps/lti_provider/management/commands/tests/test_resend_lti_scores.py b/lms/djangoapps/lti_provider/management/commands/tests/test_resend_lti_scores.py index a850c6c1b6..bc076d4c9f 100644 --- a/lms/djangoapps/lti_provider/management/commands/tests/test_resend_lti_scores.py +++ b/lms/djangoapps/lti_provider/management/commands/tests/test_resend_lti_scores.py @@ -7,13 +7,13 @@ from unittest.mock import patch from django.test import TestCase from opaque_keys.edx.keys import CourseKey, UsageKey +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.utils import TEST_DATA_DIR +from xmodule.modulestore.xml_importer import import_course_from_xml from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.lti_provider.management.commands import resend_lti_scores from lms.djangoapps.lti_provider.models import GradedAssignment, LtiConsumer, OutcomeService -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.utils import TEST_DATA_DIR # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.xml_importer import import_course_from_xml # lint-amnesty, pylint: disable=wrong-import-order class CommandArgsTestCase(TestCase): @@ -46,6 +46,7 @@ class CommandExecutionTestCase(SharedModuleStoreTestCase): """ Test `manage.py resend_lti_scores` command. """ + MODULESTORE = TEST_DATA_MONGO_MODULESTORE @classmethod def setUpClass(cls): diff --git a/lms/djangoapps/lti_provider/tests/test_outcomes.py b/lms/djangoapps/lti_provider/tests/test_outcomes.py index bae8911e01..4f9cc4779d 100644 --- a/lms/djangoapps/lti_provider/tests/test_outcomes.py +++ b/lms/djangoapps/lti_provider/tests/test_outcomes.py @@ -8,12 +8,12 @@ from unittest.mock import ANY, MagicMock, patch from django.test import TestCase from lxml import etree from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls import lms.djangoapps.lti_provider.outcomes as outcomes from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.lti_provider.models import GradedAssignment, LtiConsumer, OutcomeService -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls # lint-amnesty, pylint: disable=wrong-import-order class StoreOutcomeParametersTest(TestCase): @@ -297,6 +297,7 @@ class TestAssignmentsForProblem(ModuleStoreTestCase): """ Test cases for the assignments_for_problem method in outcomes.py """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE def setUp(self): super().setUp() diff --git a/lms/djangoapps/mobile_api/testutils.py b/lms/djangoapps/mobile_api/testutils.py index c6adaa2301..e81afc24e5 100644 --- a/lms/djangoapps/mobile_api/testutils.py +++ b/lms/djangoapps/mobile_api/testutils.py @@ -22,6 +22,8 @@ from django.urls import reverse from django.utils import timezone from opaque_keys.edx.keys import CourseKey from rest_framework.test import APITestCase +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.student import auth from common.djangoapps.student.models import CourseEnrollment @@ -30,8 +32,6 @@ from lms.djangoapps.courseware.access_response import MobileAvailabilityError, S from lms.djangoapps.mobile_api.models import IgnoreMobileAvailableFlagConfig from lms.djangoapps.mobile_api.tests.test_milestones import MobileAPIMilestonesMixin from lms.djangoapps.mobile_api.utils import API_V1 -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order class MobileAPITestCase(ModuleStoreTestCase, APITestCase): @@ -41,6 +41,8 @@ class MobileAPITestCase(ModuleStoreTestCase, APITestCase): REVERSE_INFO = {'name': , 'params': []} They may also override any of the methods defined in this class to control the behavior of the TestMixins. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + def setUp(self): super().setUp() self.course = CourseFactory.create( @@ -172,7 +174,7 @@ class MobileCourseAccessTestMixin(MobileAPIMilestonesMixin): self.verify_success(response) # allow subclasses to override verification def test_course_not_found(self): - non_existent_course_id = CourseKey.from_string('a/b/c') + non_existent_course_id = CourseKey.from_string('course-v1:a+b+c') self.init_course_access(course_id=non_existent_course_id) response = self.api_response(expected_response_code=None, course_id=non_existent_course_id) @@ -205,7 +207,7 @@ class MobileCourseAccessTestMixin(MobileAPIMilestonesMixin): self.init_course_access() # set mobile_available to False for the test course self.course.mobile_available = False - self.store.update_item(self.course, self.user.id) + self.course = self.update_course(self.course, self.user.id) self._verify_response(should_succeed, MobileAvailabilityError(), role) IgnoreMobileAvailableFlagConfig(enabled=True).save() @@ -226,7 +228,7 @@ class MobileCourseAccessTestMixin(MobileAPIMilestonesMixin): def test_visible_to_staff_only_course(self, role, should_succeed): self.init_course_access() self.course.visible_to_staff_only = True - self.store.update_item(self.course, self.user.id) + self.course = self.update_course(self.course, self.user.id) if self.ALLOW_ACCESS_TO_NON_VISIBLE_COURSE: should_succeed = True self._verify_response(should_succeed, VisibilityError(), role) diff --git a/lms/djangoapps/mobile_api/users/tests.py b/lms/djangoapps/mobile_api/users/tests.py index 89210b17bb..d1b8a38703 100644 --- a/lms/djangoapps/mobile_api/users/tests.py +++ b/lms/djangoapps/mobile_api/users/tests.py @@ -645,7 +645,7 @@ class TestCourseEnrollmentSerializer(MobileAPITestCase, MilestonesTestCaseMixin) def test_with_display_overrides(self, api_version): self.course.display_coursenumber = "overridden_number" self.course.display_organization = "overridden_org" - self.store.update_item(self.course, self.user.id) + self.course = self.update_course(self.course, self.user.id) serialized = self.get_serialized_data(api_version) assert serialized['course']['number'] == self.course.display_coursenumber diff --git a/lms/djangoapps/program_enrollments/api/tests/test_linking.py b/lms/djangoapps/program_enrollments/api/tests/test_linking.py index b60cbad7d1..4939d7122c 100644 --- a/lms/djangoapps/program_enrollments/api/tests/test_linking.py +++ b/lms/djangoapps/program_enrollments/api/tests/test_linking.py @@ -10,6 +10,7 @@ from django.test import TestCase from edx_django_utils.cache import RequestCache from opaque_keys.edx.keys import CourseKey from testfixtures import LogCapture +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from common.djangoapps.student.api import get_course_access_role from common.djangoapps.student.roles import CourseStaffRole @@ -363,7 +364,7 @@ class TestLinkProgramEnrollments(TestLinkProgramEnrollmentsMixin, TestCase): self._assert_user_enrolled_in_program_courses(self.user_2, self.program, self.fruit_course, self.animal_course) -class TestLinkProgramEnrollmentsErrors(TestLinkProgramEnrollmentsMixin, TestCase): +class TestLinkProgramEnrollmentsErrors(TestLinkProgramEnrollmentsMixin, ModuleStoreTestCase): """ Tests for linking error behavior """ def test_program_enrollment_not_found__nonexistant(self): diff --git a/lms/djangoapps/program_enrollments/rest_api/v1/tests/test_views.py b/lms/djangoapps/program_enrollments/rest_api/v1/tests/test_views.py index 74560fe44d..e7131c23f4 100644 --- a/lms/djangoapps/program_enrollments/rest_api/v1/tests/test_views.py +++ b/lms/djangoapps/program_enrollments/rest_api/v1/tests/test_views.py @@ -20,6 +20,9 @@ from organizations.tests.factories import OrganizationFactory as LMSOrganization from rest_framework import status from rest_framework.test import APITestCase from social_django.models import UserSocialAuth +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory as ModulestoreCourseFactory +from xmodule.modulestore.tests.factories import ItemFactory from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.models import CourseEnrollment @@ -52,9 +55,6 @@ from openedx.core.djangoapps.catalog.tests.factories import ( from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangolib.testing.utils import CacheIsolationMixin -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory as ModulestoreCourseFactory # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import ItemFactory # lint-amnesty, pylint: disable=wrong-import-order from .. import views from ..constants import ( @@ -96,6 +96,7 @@ class EnrollmentsDataMixin(ProgramCacheMixin): Mixin to define some shared test data objects for program/course enrollment view tests. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE view_name = 'SET-ME-IN-SUBCLASS' @classmethod @@ -1636,6 +1637,8 @@ class ProgramCourseEnrollmentOverviewGetTests( """ Tests for the ProgramCourseEnrollmentOverview view GET method. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + patch_resume_url = mock.patch( _UTILS_PATCH_FORMAT.format('get_resume_urls_for_enrollments'), autospec=True, diff --git a/lms/djangoapps/staticbook/tests.py b/lms/djangoapps/staticbook/tests.py index b99551e290..81c67523f2 100644 --- a/lms/djangoapps/staticbook/tests.py +++ b/lms/djangoapps/staticbook/tests.py @@ -209,7 +209,7 @@ class StaticPdfBookTest(StaticBookTest): url = self.make_url('pdf_book', book_index=0, chapter=1) response = self.client.get(url) self.assertNotContains(response, 'file={}'.format(PORTABLE_PDF_BOOK['chapters'][0]['url'])) - self.assertContains(response, 'file=/c4x/{0.org}/{0.course}/asset/{1}'.format( + self.assertContains(response, 'file=/asset-v1:{0.org}+{0.course}+{0.run}+type@asset+block/{1}'.format( self.course.location, PORTABLE_PDF_BOOK['chapters'][0]['url'].replace('/static/', ''))) diff --git a/lms/djangoapps/support/tests/test_views.py b/lms/djangoapps/support/tests/test_views.py index deab43c567..a6b8e43947 100644 --- a/lms/djangoapps/support/tests/test_views.py +++ b/lms/djangoapps/support/tests/test_views.py @@ -7,6 +7,7 @@ import json import re from datetime import datetime, timedelta from unittest.mock import patch +from urllib.parse import quote from uuid import UUID, uuid4 import ddt @@ -28,7 +29,9 @@ from organizations.tests.factories import OrganizationFactory from pytz import UTC from rest_framework import status from social_django.models import UserSocialAuth -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase +from xmodule.modulestore.tests.django_utils import ( + TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase, SharedModuleStoreTestCase, +) from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.course_modes.models import CourseMode @@ -214,7 +217,7 @@ class SupportViewAccessTests(SupportViewTestCase): # Expect a redirect to the login page redirect_url = "{login_url}?next={original_url}".format( login_url=reverse("signin_user"), - original_url=url, + original_url=quote(url), ) self.assertRedirects(response, redirect_url) @@ -247,6 +250,7 @@ class SupportViewCertificatesTests(SupportViewTestCase): """ Tests for the certificates support view. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE def setUp(self): """Make the user support staff. """ @@ -266,7 +270,7 @@ class SupportViewCertificatesTests(SupportViewTestCase): def test_certificates_along_with_course_filter(self): # Check that an initial filter is passed to the JavaScript client. - url = reverse("support:certificates") + "?user=student@example.com&course_id=" + str(self.course.id) + url = reverse("support:certificates") + "?user=student@example.com&course_id=" + quote(str(self.course.id)) response = self.client.get(url) self.assertContains(response, "userFilter: 'student@example.com'") self.assertContains(response, "courseFilter: '" + str(self.course.id) + "'") @@ -451,7 +455,7 @@ class SupportViewEnrollmentsTests(SharedModuleStoreTestCase, SupportViewTestCase 'mode': '', 'reason': 'Financial Assistance' }) - test_key_error = b'<script>alert("xss")</script> is not a valid mode for org' + test_key_error = b'<script>alert("xss")</script> is not a valid mode for course-v1:org' assert response.status_code == status.HTTP_400_BAD_REQUEST assert test_key_error in response.content @@ -1797,6 +1801,7 @@ class TestOnboardingView(SupportViewTestCase, ProctoredExamTestCase): """ Tests for OnboardingView """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE def setUp(self): super().setUp() diff --git a/lms/djangoapps/teams/tests/test_api.py b/lms/djangoapps/teams/tests/test_api.py index bc9679a8f6..e9df8cd222 100644 --- a/lms/djangoapps/teams/tests/test_api.py +++ b/lms/djangoapps/teams/tests/test_api.py @@ -19,8 +19,8 @@ from openedx.core.lib.teams_config import TeamsConfig, TeamsetType from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order -COURSE_KEY1 = CourseKey.from_string('edx/history/1') -COURSE_KEY2 = CourseKey.from_string('edx/math/1') +COURSE_KEY1 = CourseKey.from_string('course-v1:edx+history+1') +COURSE_KEY2 = CourseKey.from_string('course-v1:edx+math+1') TOPIC1 = 'topic-1' TOPIC2 = 'topic-2' TOPIC3 = 'topic-3' diff --git a/lms/djangoapps/teams/tests/test_serializers.py b/lms/djangoapps/teams/tests/test_serializers.py index 89721467db..4aec23ccc2 100644 --- a/lms/djangoapps/teams/tests/test_serializers.py +++ b/lms/djangoapps/teams/tests/test_serializers.py @@ -75,7 +75,7 @@ class TopicSerializerTestCase(SerializerTestCase): Verifies that the `TopicSerializer` correctly displays a topic with a team count of 0, and that it takes a known number of SQL queries. """ - with self.assertNumQueries(2): + with self.assertNumQueries(1): serializer = TopicSerializer( self.course.teamsets[0].cleaned_data, context={'course_id': self.course.id}, @@ -91,7 +91,7 @@ class TopicSerializerTestCase(SerializerTestCase): CourseTeamFactory.create( course_id=self.course.id, topic_id=self.course.teamsets[0].teamset_id ) - with self.assertNumQueries(2): + with self.assertNumQueries(1): serializer = TopicSerializer( self.course.teamsets[0].cleaned_data, context={'course_id': self.course.id}, @@ -110,7 +110,7 @@ class TopicSerializerTestCase(SerializerTestCase): ) CourseTeamFactory.create(course_id=self.course.id, topic_id=duplicate_topic['id']) CourseTeamFactory.create(course_id=second_course.id, topic_id=duplicate_topic['id']) - with self.assertNumQueries(2): + with self.assertNumQueries(1): serializer = TopicSerializer( self.course.teamsets[0].cleaned_data, context={'course_id': self.course.id}, diff --git a/lms/djangoapps/teams/tests/test_views.py b/lms/djangoapps/teams/tests/test_views.py index 9db96dd372..ab556ce925 100644 --- a/lms/djangoapps/teams/tests/test_views.py +++ b/lms/djangoapps/teams/tests/test_views.py @@ -6,6 +6,7 @@ import json import unittest from datetime import datetime from unittest.mock import patch +from urllib.parse import quote from uuid import UUID import ddt @@ -75,7 +76,7 @@ class TestDashboard(SharedModuleStoreTestCase): dashboard, and is redirected to the login page.""" anonymous_client = APIClient() response = anonymous_client.get(self.teams_url) - redirect_url = f'{settings.LOGIN_URL}?next={self.teams_url}' + redirect_url = f'{settings.LOGIN_URL}?next={quote(self.teams_url)}' self.assertRedirects(response, redirect_url) def test_not_enrolled_not_staff(self): @@ -173,7 +174,7 @@ class TestDashboard(SharedModuleStoreTestCase): response = self.client.get(bad_team_url) assert 404 == response.status_code - bad_team_url = bad_team_url.replace(bad_org, "invalid/course/id") + bad_team_url = bad_team_url.replace(self.course.id.run, "invalid/course/id") response = self.client.get(bad_team_url) assert 404 == response.status_code @@ -882,7 +883,7 @@ class TestListTeamsAPI(EventTestMixin, TeamAPITestCase): self.verify_names(data, 400, []) self.assert_no_events_were_emitted() - @ddt.data((404, {'course_id': 'no/such/course'}), (400, {'topic_id': 'no_such_topic'})) + @ddt.data((404, {'course_id': 'course-v1:no+such+course'}), (400, {'topic_id': 'no_such_topic'})) @ddt.unpack def test_no_results(self, status, data): self.get_teams_list(status, data) @@ -1161,7 +1162,7 @@ class TestCreateTeamAPI(EventTestMixin, TeamAPITestCase): 'description': "Filler Description" }), (404, { 'name': "Non-existent course ID", - 'course_id': 'no/such/course', + 'course_id': 'course-v1:no+such+course', 'description': "Filler Description" })) @ddt.unpack @@ -2125,10 +2126,10 @@ class TestListMembershipAPI(TeamAPITestCase): assert users == ['student_on_team_1_private_set_1'] @ddt.data( - ('student_enrolled_both_courses_other_team', 'TestX/TS101/Test_Course', 200, 'Nuclear Team'), - ('student_enrolled_both_courses_other_team', 'MIT/6.002x/Circuits', 200, 'Another Team'), - ('student_enrolled', 'TestX/TS101/Test_Course', 200, 'Sólar team'), - ('student_enrolled', 'MIT/6.002x/Circuits', 400, ''), + ('student_enrolled_both_courses_other_team', 'course-v1:TestX+TS101+Test_Course', 200, 'Nuclear Team'), + ('student_enrolled_both_courses_other_team', 'course-v1:MIT+6.002x+Circuits', 200, 'Another Team'), + ('student_enrolled', 'course-v1:TestX+TS101+Test_Course', 200, 'Sólar team'), + ('student_enrolled', 'course-v1:MIT+6.002x+Circuits', 400, ''), ) @ddt.unpack def test_course_filter_with_username(self, user, course_id, status, team_name): @@ -2145,8 +2146,8 @@ class TestListMembershipAPI(TeamAPITestCase): assert membership['results'][0]['team']['team_id'] == self.test_team_name_id_map[team_name].team_id @ddt.data( - ('TestX/TS101/Test_Course', 200), - ('MIT/6.002x/Circuits', 400), + ('course-v1:TestX+TS101+Test_Course', 200), + ('course-v1:MIT+6.002x+Circuits', 400), ) @ddt.unpack def test_course_filter_with_team_id(self, course_id, status): @@ -2210,7 +2211,7 @@ class TestListMembershipAPI(TeamAPITestCase): { 'team_id': self.solar_team.team_id, 'teamset_id': 'topic_0', - 'course_id': 'TestX/TS101/Non_Existent_Course' + 'course_id': 'course-v1:TestX+TS101+Non_Existent_Course' } ) @@ -2228,7 +2229,8 @@ class TestListMembershipAPI(TeamAPITestCase): ) def test_filter_teamset_course_nonexistant(self): - self.get_membership_list(404, {'teamset_id': 'topic_0', 'course_id': 'TestX/TS101/Non_Existent_Course'}) + self.get_membership_list(404, {'teamset_id': 'topic_0', + 'course_id': 'course-v1:TestX+TS101+Non_Existent_Course'}) def test_filter_teamset_teamset_nonexistant(self): self.get_membership_list(404, {'teamset_id': 'nonexistant', 'course_id': str(self.test_course_1.id)}) @@ -2790,8 +2792,8 @@ class TestBulkMembershipManagement(TeamAPITestCase): This test case will be expanded when the view is fully implemented (TODO MST-31). """ - good_course_id = 'TestX/TS101/Test_Course' - fake_course_id = 'TestX/TS101/Non_Existent_Course' + good_course_id = 'course-v1:TestX+TS101+Test_Course' + fake_course_id = 'course-v1:TestX+TS101+Non_Existent_Course' allow_username = 'course_staff' deny_username = 'student_enrolled' diff --git a/lms/djangoapps/verify_student/tests/test_services.py b/lms/djangoapps/verify_student/tests/test_services.py index 4a5cace602..b526357909 100644 --- a/lms/djangoapps/verify_student/tests/test_services.py +++ b/lms/djangoapps/verify_student/tests/test_services.py @@ -130,7 +130,7 @@ class TestIDVerificationService(ModuleStoreTestCase): course = CourseFactory.create(org='Robot', number='999', display_name='Test Course') path = IDVerificationService.get_verify_location(course.id) expected_path = f'{settings.ACCOUNT_MICROFRONTEND_URL}/id-verification' - assert path == (expected_path + '?course_id=Robot/999/Test_Course') + assert path == (expected_path + '?course_id=course-v1%3ARobot%2B999%2BTest_Course') def test_get_verify_location_from_string(self): """ diff --git a/lms/djangoapps/verify_student/tests/test_views.py b/lms/djangoapps/verify_student/tests/test_views.py index db06c717bb..d65881d2e9 100644 --- a/lms/djangoapps/verify_student/tests/test_views.py +++ b/lms/djangoapps/verify_student/tests/test_views.py @@ -589,9 +589,9 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin, Tes original_url = reverse(url_name, kwargs={'course_id': str(course.id)}) login_url = "{login_url}?next={original_url}".format( login_url=reverse('signin_user'), - original_url=original_url + original_url=urllib.parse.quote(original_url), ) - self.assertRedirects(response, login_url) + self.assertRedirects(response, login_url, fetch_redirect_response=False) @ddt.data( "verify_student_start_flow", diff --git a/openedx/core/djangoapps/bookmarks/tests/test_models.py b/openedx/core/djangoapps/bookmarks/tests/test_models.py index 1c618dcea4..8fc067449b 100644 --- a/openedx/core/djangoapps/bookmarks/tests/test_models.py +++ b/openedx/core/djangoapps/bookmarks/tests/test_models.py @@ -12,13 +12,13 @@ import pytz from freezegun import freeze_time from opaque_keys.edx.keys import UsageKey from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls from openedx.core.djangolib.testing.utils import skip_unless_lms from common.djangoapps.student.tests.factories import AdminFactory, UserFactory -from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls # lint-amnesty, pylint: disable=wrong-import-order from .. import DEFAULT_FIELDS, OPTIONAL_FIELDS, PathItem from ..models import Bookmark, XBlockCache, parse_path_data @@ -35,6 +35,7 @@ class BookmarksTestsBase(ModuleStoreTestCase): """ Test the Bookmark model. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE ALL_FIELDS = DEFAULT_FIELDS + OPTIONAL_FIELDS STORE_TYPE = ModuleStoreEnum.Type.mongo TEST_PASSWORD = 'test' diff --git a/openedx/core/djangoapps/bookmarks/tests/test_tasks.py b/openedx/core/djangoapps/bookmarks/tests/test_tasks.py index f033e6bc1e..075a263f01 100644 --- a/openedx/core/djangoapps/bookmarks/tests/test_tasks.py +++ b/openedx/core/djangoapps/bookmarks/tests/test_tasks.py @@ -6,6 +6,7 @@ Tests for tasks. import ddt from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE from xmodule.modulestore.tests.factories import ItemFactory, check_mongo_calls from ..models import XBlockCache @@ -18,6 +19,7 @@ class XBlockCacheTaskTests(BookmarksTestsBase): """ Test the XBlockCache model. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE def setUp(self): super().setUp() diff --git a/openedx/core/djangoapps/bookmarks/tests/test_views.py b/openedx/core/djangoapps/bookmarks/tests/test_views.py index 14bd44f355..82fc24588d 100644 --- a/openedx/core/djangoapps/bookmarks/tests/test_views.py +++ b/openedx/core/djangoapps/bookmarks/tests/test_views.py @@ -11,9 +11,10 @@ import ddt from django.conf import settings from django.urls import reverse from rest_framework.test import APIClient +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE from openedx.core.djangolib.testing.utils import skip_unless_lms -from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from .test_api import BookmarkApiEventTestMixin from .test_models import BookmarksTestsBase @@ -71,6 +72,7 @@ class BookmarksListViewTests(BookmarksViewsTestsBase): GET /api/bookmarks/v1/bookmarks/?course_id={course_id1} POST /api/bookmarks/v1/bookmarks """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE @ddt.data( (1, False), diff --git a/openedx/core/djangoapps/ccxcon/tests/test_api.py b/openedx/core/djangoapps/ccxcon/tests/test_api.py index f55621dc74..e3047af015 100644 --- a/openedx/core/djangoapps/ccxcon/tests/test_api.py +++ b/openedx/core/djangoapps/ccxcon/tests/test_api.py @@ -8,12 +8,12 @@ from urllib import parse import pytest import pytz from opaque_keys.edx.keys import CourseKey +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from openedx.core.djangoapps.ccxcon import api as ccxconapi from common.djangoapps.student.tests.factories import AdminFactory -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order from .factories import CcxConFactory @@ -36,8 +36,6 @@ class APIsTestCase(SharedModuleStoreTestCase): """ Unit tests for the API module functions """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - @classmethod def setUpClass(cls): super().setUpClass() diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_signals.py b/openedx/core/djangoapps/content/block_structure/tests/test_signals.py index c794eb2fa9..920b663cb8 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_signals.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_signals.py @@ -39,7 +39,7 @@ class CourseBlocksSignalTest(ModuleStoreTestCase): assert test_display_name != orig_block_structure.get_xblock_field(self.course_usage_key, 'display_name') self.course.display_name = test_display_name - self.store.update_item(self.course, self.user.id) + self.update_course(self.course, self.user.id) # Cached version of course has been updated updated_block_structure = bs_manager.get_collected() @@ -52,7 +52,7 @@ class CourseBlocksSignalTest(ModuleStoreTestCase): with override_waffle_switch(INVALIDATE_CACHE_ON_PUBLISH, active=invalidate_cache_enabled): self.course.display_name = test_display_name - self.store.update_item(self.course, self.user.id) + self.update_course(self.course, self.user.id) assert mock_bs_manager_clear.called == invalidate_cache_enabled diff --git a/openedx/core/djangoapps/content/course_overviews/tests/test_signals.py b/openedx/core/djangoapps/content/course_overviews/tests/test_signals.py index 66f5d39b8c..4b486f3616 100644 --- a/openedx/core/djangoapps/content/course_overviews/tests/test_signals.py +++ b/openedx/core/djangoapps/content/course_overviews/tests/test_signals.py @@ -9,7 +9,7 @@ import ddt from xmodule.data import CertificatesDisplayBehaviors from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls from ..models import CourseOverview @@ -23,6 +23,7 @@ class CourseOverviewSignalsTestCase(ModuleStoreTestCase): """ Tests for CourseOverview signals. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE ENABLED_SIGNALS = ['course_deleted', 'course_published'] TODAY = datetime.datetime.utcnow() NEXT_WEEK = TODAY + datetime.timedelta(days=7) diff --git a/openedx/core/djangoapps/contentserver/test/test_contentserver.py b/openedx/core/djangoapps/contentserver/test/test_contentserver.py index 2fcbd1cb34..cf5ae5b509 100644 --- a/openedx/core/djangoapps/contentserver/test/test_contentserver.py +++ b/openedx/core/djangoapps/contentserver/test/test_contentserver.py @@ -16,14 +16,13 @@ from django.conf import settings from django.test import RequestFactory from django.test.client import Client from django.test.utils import override_settings - +from opaque_keys import InvalidKeyError from xmodule.contentstore.django import contentstore from xmodule.contentstore.content import StaticContent, VERSIONED_ASSETS_PREFIX from xmodule.modulestore.django import modulestore -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_MODULESTORE, SharedModuleStoreTestCase from xmodule.modulestore.xml_importer import import_course_from_xml from xmodule.assetstore.assetmgr import AssetManager -from opaque_keys import InvalidKeyError # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.exceptions import ItemNotFoundError from common.djangoapps.student.models import CourseEnrollment @@ -74,6 +73,7 @@ class ContentStoreToyCourseTest(SharedModuleStoreTestCase): """ Tests that use the toy course. """ + MODULESTORE = TEST_DATA_MONGO_MODULESTORE @classmethod def setUpClass(cls): diff --git a/openedx/core/djangoapps/course_date_signals/tests.py b/openedx/core/djangoapps/course_date_signals/tests.py index 9eebdd1de5..ce93bc8529 100644 --- a/openedx/core/djangoapps/course_date_signals/tests.py +++ b/openedx/core/djangoapps/course_date_signals/tests.py @@ -2,8 +2,11 @@ from datetime import timedelta from unittest.mock import patch # lint-amnesty, pylint: disable=wrong-import-order +from edx_toggles.toggles.testutils import override_waffle_flag +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory + from cms.djangoapps.contentstore.config.waffle import CUSTOM_RELATIVE_DATES -from edx_toggles.toggles.testutils import override_waffle_flag # lint-amnesty, pylint: disable=wrong-import-order from openedx.core.djangoapps.course_date_signals.handlers import ( _gather_graded_items, _get_custom_pacing_children, @@ -11,12 +14,13 @@ from openedx.core.djangoapps.course_date_signals.handlers import ( extract_dates_from_course ) from openedx.core.djangoapps.course_date_signals.models import SelfPacedRelativeDatesConfig -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order + from . import utils class SelfPacedDueDatesTests(ModuleStoreTestCase): # lint-amnesty, pylint: disable=missing-class-docstring + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + def setUp(self): super().setUp() self.course = CourseFactory.create() @@ -200,6 +204,8 @@ class SelfPacedCustomDueDateTests(ModuleStoreTestCase): """ Tests the custom Personalized Learner Schedule (PLS) dates in self paced courses """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + def setUp(self): super().setUp() SelfPacedRelativeDatesConfig.objects.create(enabled=True) diff --git a/openedx/core/djangoapps/coursegraph/management/commands/tests/test_dump_to_neo4j.py b/openedx/core/djangoapps/coursegraph/management/commands/tests/test_dump_to_neo4j.py index 3e5699a605..61349eda8a 100644 --- a/openedx/core/djangoapps/coursegraph/management/commands/tests/test_dump_to_neo4j.py +++ b/openedx/core/djangoapps/coursegraph/management/commands/tests/test_dump_to_neo4j.py @@ -273,7 +273,7 @@ class TestModuleStoreSerializer(TestDumpToNeo4jCommandBase): 'test_block_type', 'test_block_id' ).for_branch( 'test_branch' - ).for_version('test_version') + ).for_version(b'test_version') assert location.branch is not None assert location.version_guid is not None diff --git a/openedx/core/djangoapps/courseware_api/tests/pacts/views.py b/openedx/core/djangoapps/courseware_api/tests/pacts/views.py index a283c03d72..e3ea735a70 100644 --- a/openedx/core/djangoapps/courseware_api/tests/pacts/views.py +++ b/openedx/core/djangoapps/courseware_api/tests/pacts/views.py @@ -8,7 +8,7 @@ from django.http import JsonResponse from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST from opaque_keys.edx.keys import CourseKey, UsageKey -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreIsolationMixin +from xmodule.modulestore.tests.django_utils import ModuleStoreIsolationMixin from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, ToyCourseFactory from common.djangoapps.course_modes.models import CourseMode @@ -21,7 +21,6 @@ class ProviderState(ModuleStoreIsolationMixin): """ Provider State Setup """ COURSE_KEY = "course-v1:edX+DemoX+Demo_Course" - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE def clean_db(self, user, course_key): """ Utility method to clean db """ diff --git a/openedx/core/djangoapps/courseware_api/tests/test_views.py b/openedx/core/djangoapps/courseware_api/tests/test_views.py index 699b85a2b1..db7ba2e0e3 100644 --- a/openedx/core/djangoapps/courseware_api/tests/test_views.py +++ b/openedx/core/djangoapps/courseware_api/tests/test_views.py @@ -17,7 +17,7 @@ from edx_django_utils.cache import TieredCache from edx_toggles.toggles.testutils import override_waffle_flag from xmodule.data import CertificatesDisplayBehaviors from xmodule.modulestore.django import modulestore -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import ItemFactory, ToyCourseFactory from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID @@ -56,8 +56,6 @@ class BaseCoursewareTests(SharedModuleStoreTestCase): """ Base class for courseware API tests """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - @classmethod def setUpClass(cls): super().setUpClass() diff --git a/openedx/core/djangoapps/demographics/tests/test_status.py b/openedx/core/djangoapps/demographics/tests/test_status.py index 4b8a068eca..525b82e13c 100644 --- a/openedx/core/djangoapps/demographics/tests/test_status.py +++ b/openedx/core/djangoapps/demographics/tests/test_status.py @@ -7,6 +7,9 @@ from unittest import mock from django.conf import settings from opaque_keys.edx.keys import CourseKey from pytest import mark +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory @@ -16,9 +19,6 @@ from openedx.core.djangoapps.catalog.tests.factories import ( ) from openedx.core.djangolib.testing.utils import skip_unless_lms from openedx.features.enterprise_support.tests.factories import EnterpriseCustomerUserFactory -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase, TEST_DATA_SPLIT_MODULESTORE # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order if settings.ROOT_URLCONF == 'lms.urls': from openedx.core.djangoapps.demographics.api.status import show_user_demographics, show_call_to_action_for_user @@ -33,8 +33,6 @@ class TestShowDemographics(SharedModuleStoreTestCase): """ Tests for whether the demographics collection fields should be shown """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - @classmethod def setUpClass(cls): super().setUpClass() diff --git a/openedx/core/djangoapps/discussions/tests/test_tasks.py b/openedx/core/djangoapps/discussions/tests/test_tasks.py index 244eff7bc8..256450bea3 100644 --- a/openedx/core/djangoapps/discussions/tests/test_tasks.py +++ b/openedx/core/djangoapps/discussions/tests/test_tasks.py @@ -4,10 +4,11 @@ Tests for discussions tasks. import ddt import mock +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory + from openedx.core.djangoapps.discussions.data import DiscussionTopicContext from openedx.core.djangoapps.discussions.tasks import update_discussions_settings_from_course -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order @ddt.ddt @@ -16,6 +17,8 @@ class UpdateDiscussionsSettingsFromCourseTestCase(ModuleStoreTestCase): """ Tests for the discussions settings update tasks """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + def setUp(self): super().setUp() self.course = course = CourseFactory.create() diff --git a/openedx/core/djangoapps/discussions/tests/test_transformer.py b/openedx/core/djangoapps/discussions/tests/test_transformer.py index 50059d3da5..0ae6437207 100644 --- a/openedx/core/djangoapps/discussions/tests/test_transformer.py +++ b/openedx/core/djangoapps/discussions/tests/test_transformer.py @@ -2,7 +2,7 @@ Tests for discussions course block transformer """ -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, TEST_DATA_SPLIT_MODULESTORE +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from lms.djangoapps.course_blocks.api import get_course_blocks @@ -16,7 +16,6 @@ class DiscussionsTopicLinkTransformerTestCase(TransformerRegistryTestMixin, Modu Tests behaviour of BlockCompletionTransformer """ TRANSFORMER_CLASS_TO_TEST = DiscussionsTopicLinkTransformer - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE def setUp(self): super().setUp() diff --git a/openedx/core/djangoapps/embargo/tests/test_middleware.py b/openedx/core/djangoapps/embargo/tests/test_middleware.py index f714fcdfee..d6a274b2de 100644 --- a/openedx/core/djangoapps/embargo/tests/test_middleware.py +++ b/openedx/core/djangoapps/embargo/tests/test_middleware.py @@ -9,12 +9,14 @@ from config_models.models import cache as config_cache from django.conf import settings from django.core.cache import cache as django_cache from django.urls import reverse +from edx_toggles.toggles.testutils import override_waffle_flag +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory from openedx.core.djangolib.testing.utils import skip_unless_lms from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.util.testing import UrlResetMixin -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order +from lms.djangoapps.course_home_api.toggles import COURSE_HOME_USE_LEGACY_FRONTEND from ..models import IPFilter, RestrictedCourse from ..test_utils import restrict_course @@ -22,6 +24,7 @@ from ..test_utils import restrict_course @ddt.ddt @skip_unless_lms +@override_waffle_flag(COURSE_HOME_USE_LEGACY_FRONTEND, active=True) class EmbargoMiddlewareAccessTests(UrlResetMixin, ModuleStoreTestCase): """Tests of embargo middleware country access rules. diff --git a/openedx/core/djangoapps/enrollments/tests/test_views.py b/openedx/core/djangoapps/enrollments/tests/test_views.py index 104e6e6bcf..309cce3bc7 100644 --- a/openedx/core/djangoapps/enrollments/tests/test_views.py +++ b/openedx/core/djangoapps/enrollments/tests/test_views.py @@ -9,6 +9,8 @@ import itertools import json import unittest from unittest.mock import patch +from urllib.parse import quote + import pytest import ddt import httpretty @@ -23,6 +25,8 @@ from django.urls import reverse from freezegun import freeze_time from rest_framework import status from rest_framework.test import APITestCase +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls_range from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory @@ -43,8 +47,6 @@ from common.djangoapps.student.roles import CourseStaffRole from common.djangoapps.student.tests.factories import AdminFactory, SuperuserFactory, UserFactory from common.djangoapps.util.models import RateLimitConfiguration from common.djangoapps.util.testing import UrlResetMixin -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls_range # lint-amnesty, pylint: disable=wrong-import-order class EnrollmentTestMixin: @@ -1598,6 +1600,7 @@ class CourseEnrollmentsApiListTest(APITestCase, ModuleStoreTestCase): """ Test the course enrollments list API. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE CREATED_DATA = datetime.datetime(2018, 1, 1, 0, 0, 1, tzinfo=pytz.UTC) def setUp(self): @@ -1698,12 +1701,12 @@ class CourseEnrollmentsApiListTest(APITestCase, ModuleStoreTestCase): def test_user_not_authenticated(self): self.client.logout() - response = self.client.get(self.url, {'course_id': str(self.course.id)}) + response = self.client.get(self.url, {'course_id': quote(str(self.course.id))}) assert response.status_code == status.HTTP_401_UNAUTHORIZED def test_user_not_authorized(self): self.client.login(username=self.student1.username, password='edx') - response = self.client.get(self.url, {'course_id': str(self.course.id)}) + response = self.client.get(self.url, {'course_id': quote(str(self.course.id))}) assert response.status_code == status.HTTP_403_FORBIDDEN @ddt.data( diff --git a/openedx/core/djangoapps/models/tests/test_course_details.py b/openedx/core/djangoapps/models/tests/test_course_details.py index 93daf71687..6d102ed32b 100644 --- a/openedx/core/djangoapps/models/tests/test_course_details.py +++ b/openedx/core/djangoapps/models/tests/test_course_details.py @@ -10,12 +10,12 @@ from pytz import UTC from unittest.mock import patch # lint-amnesty, pylint: disable=wrong-import-order from django.conf import settings +from xmodule.modulestore import ModuleStoreEnum +from xmodule.data import CertificatesDisplayBehaviors +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory from openedx.core.djangoapps.models.course_details import ABOUT_ATTRIBUTES, CourseDetails -from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.data import CertificatesDisplayBehaviors # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order EXAMPLE_CERTIFICATE_AVAILABLE_DATE = datetime.date(2020, 1, 1) @@ -25,6 +25,7 @@ class CourseDetailsTestCase(ModuleStoreTestCase): """ Tests the first course settings page (course dates, overview, etc.). """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE def setUp(self): super().setUp() diff --git a/openedx/core/djangoapps/programs/tests/test_utils.py b/openedx/core/djangoapps/programs/tests/test_utils.py index b9c3447780..8b0914ecaa 100644 --- a/openedx/core/djangoapps/programs/tests/test_utils.py +++ b/openedx/core/djangoapps/programs/tests/test_utils.py @@ -16,6 +16,10 @@ from django.test.utils import override_settings from django.urls import reverse from pytz import utc from testfixtures import LogCapture +from xmodule.data import CertificatesDisplayBehaviors +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory as ModuleStoreCourseFactory from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory @@ -49,12 +53,6 @@ from openedx.core.djangoapps.site_configuration.tests.factories import SiteFacto from openedx.core.djangolib.testing.utils import skip_unless_lms from common.djangoapps.student.tests.factories import AnonymousUserFactory, CourseEnrollmentFactory, UserFactory from common.djangoapps.util.date_utils import strftime_localized -from xmodule.data import CertificatesDisplayBehaviors # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order - ModuleStoreTestCase, SharedModuleStoreTestCase, TEST_DATA_SPLIT_MODULESTORE -) -from xmodule.modulestore.tests.factories import CourseFactory as ModuleStoreCourseFactory # lint-amnesty, pylint: disable=wrong-import-order ECOMMERCE_URL_ROOT = 'https://ecommerce.example.com' UTILS_MODULE = 'openedx.core.djangoapps.programs.utils' @@ -1654,7 +1652,6 @@ class TestProgramEnrollment(SharedModuleStoreTestCase): Requests to the data in the Program cache are mocked out. """ - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE MICROBACHELORS = 'microbachelors' @classmethod diff --git a/openedx/core/djangoapps/schedules/tests/test_content_highlights.py b/openedx/core/djangoapps/schedules/tests/test_content_highlights.py index a1c7ecaeef..94114fd359 100644 --- a/openedx/core/djangoapps/schedules/tests/test_content_highlights.py +++ b/openedx/core/djangoapps/schedules/tests/test_content_highlights.py @@ -1,7 +1,11 @@ # lint-amnesty, pylint: disable=missing-module-docstring import datetime from unittest.mock import patch + import pytest +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory + from openedx.core.djangoapps.schedules.content_highlights import ( course_has_highlights_from_store, get_all_course_highlights, @@ -12,14 +16,10 @@ from openedx.core.djangoapps.schedules.exceptions import CourseUpdateDoesNotExis from openedx.core.djangolib.testing.utils import skip_unless_lms from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order @skip_unless_lms class TestContentHighlights(ModuleStoreTestCase): # lint-amnesty, pylint: disable=missing-class-docstring - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - def setUp(self): super().setUp() self._setup_course() diff --git a/openedx/core/djangoapps/schedules/tests/test_resolvers.py b/openedx/core/djangoapps/schedules/tests/test_resolvers.py index 392f1fb0f4..63e2838e61 100644 --- a/openedx/core/djangoapps/schedules/tests/test_resolvers.py +++ b/openedx/core/djangoapps/schedules/tests/test_resolvers.py @@ -206,6 +206,8 @@ class TestCourseNextSectionUpdateResolver(SchedulesResolverTestMixin, ModuleStor """ Tests the TestCourseNextSectionUpdateResolver. """ + ENABLED_SIGNALS = ['course_published'] + def setUp(self): super().setUp() self.today = datetime.datetime.utcnow() diff --git a/openedx/core/djangoapps/schedules/tests/test_signals.py b/openedx/core/djangoapps/schedules/tests/test_signals.py index 8c50308157..023fbbdbaf 100644 --- a/openedx/core/djangoapps/schedules/tests/test_signals.py +++ b/openedx/core/djangoapps/schedules/tests/test_signals.py @@ -20,7 +20,7 @@ from openedx.core.djangolib.testing.utils import skip_unless_lms from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import CourseEnrollmentFactory from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order from ..models import Schedule @@ -94,7 +94,7 @@ class CreateScheduleTests(SharedModuleStoreTestCase): # lint-amnesty, pylint: d @ddt.ddt @skip_unless_lms -class UpdateScheduleTests(SharedModuleStoreTestCase): # lint-amnesty, pylint: disable=missing-class-docstring +class UpdateScheduleTests(ModuleStoreTestCase): # lint-amnesty, pylint: disable=missing-class-docstring ENABLED_SIGNALS = ['course_published'] VERIFICATION_DEADLINE_DAYS = 14 @@ -115,7 +115,7 @@ class UpdateScheduleTests(SharedModuleStoreTestCase): # lint-amnesty, pylint: d self.assert_schedule_dates(enrollment.schedule, enrollment.course.start) course.start = course.start + datetime.timedelta(days=3) # new course start changes to another future date - self.store.update_item(course, ModuleStoreEnum.UserID.test) + self.update_course(course, ModuleStoreEnum.UserID.test) enrollment = CourseEnrollment.objects.get(id=enrollment.id) self.assert_schedule_dates(enrollment.schedule, course.start) # start set to new course start @@ -125,7 +125,7 @@ class UpdateScheduleTests(SharedModuleStoreTestCase): # lint-amnesty, pylint: d self.assert_schedule_dates(enrollment.schedule, enrollment.created) course.start = course.start + datetime.timedelta(days=3) # new course start changes to another future date - self.store.update_item(course, ModuleStoreEnum.UserID.test) + self.update_course(course, ModuleStoreEnum.UserID.test) enrollment = CourseEnrollment.objects.get(id=enrollment.id) self.assert_schedule_dates(enrollment.schedule, course.start) # start set to new course start @@ -136,7 +136,7 @@ class UpdateScheduleTests(SharedModuleStoreTestCase): # lint-amnesty, pylint: d self.assert_schedule_dates(enrollment.schedule, previous_start) course.start = course.start + datetime.timedelta(days=-10) # new course start changes to a past date - self.store.update_item(course, ModuleStoreEnum.UserID.test) + self.update_course(course, ModuleStoreEnum.UserID.test) enrollment = CourseEnrollment.objects.get(id=enrollment.id) self.assert_schedule_dates(enrollment.schedule, course.start) # start set to new course start diff --git a/openedx/core/djangoapps/user_api/accounts/tests/test_utils.py b/openedx/core/djangoapps/user_api/accounts/tests/test_utils.py index eb97015016..694b5d5e36 100644 --- a/openedx/core/djangoapps/user_api/accounts/tests/test_utils.py +++ b/openedx/core/djangoapps/user_api/accounts/tests/test_utils.py @@ -122,7 +122,8 @@ class CompletionUtilsTestCase(SharedModuleStoreTestCase, CompletionWaffleTestMix self.cruft_user ) assert block_url ==\ - 'test_url:9999/courses/{org}/{course}/{run}/jump_to/i4x://{org}/{course}/vertical/{vertical_id}'.format( + 'test_url:9999/courses/course-v1:{org}+{course}+{run}/jump_to/'\ + 'block-v1:{org}+{course}+{run}+type@vertical+block@{vertical_id}'.format( org=self.course.location.course_key.org, course=self.course.location.course_key.course, run=self.course.location.course_key.run, diff --git a/openedx/core/lib/gating/tests/test_api.py b/openedx/core/lib/gating/tests/test_api.py index 0e968d82c1..13f2414a39 100644 --- a/openedx/core/lib/gating/tests/test_api.py +++ b/openedx/core/lib/gating/tests/test_api.py @@ -11,6 +11,8 @@ from ddt import data, ddt, unpack from django.conf import settings from milestones import api as milestones_api from milestones.tests.utils import MilestonesTestCaseMixin +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.gating import api as lms_gating_api @@ -20,8 +22,6 @@ from lms.djangoapps.grades.tests.base import GradeTestBase from lms.djangoapps.grades.tests.utils import mock_get_score from openedx.core.lib.gating import api as gating_api from openedx.core.lib.gating.exceptions import GatingValidationError -from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order @ddt @@ -29,9 +29,6 @@ class TestGatingApi(ModuleStoreTestCase, MilestonesTestCaseMixin): """ Tests for the gating API """ - - MODULESTORE = TEST_DATA_SPLIT_MODULESTORE - def setUp(self): """ Initial data setup @@ -354,6 +351,8 @@ class TestGatingGradesIntegration(GradeTestBase): """ Tests the integration between the gating API and our Persistent Grades framework. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') def test_get_subsection_grade_percentage(self): user = self.request.user diff --git a/openedx/core/lib/tests/test_xblock_utils.py b/openedx/core/lib/tests/test_xblock_utils.py index 0f0555c780..de9f6e2061 100644 --- a/openedx/core/lib/tests/test_xblock_utils.py +++ b/openedx/core/lib/tests/test_xblock_utils.py @@ -12,6 +12,10 @@ from django.test.client import RequestFactory from opaque_keys.edx.asides import AsideUsageKeyV1, AsideUsageKeyV2 from web_fragments.fragment import Fragment from xblock.core import XBlockAside +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory +from xmodule.modulestore.tests.test_asides import AsideTestType from openedx.core.lib.url_utils import quote_slashes from openedx.core.lib.xblock_builtin import get_css_dependencies, get_js_dependencies @@ -26,10 +30,6 @@ from openedx.core.lib.xblock_utils import ( wrap_fragment, wrap_xblock ) -from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.test_asides import AsideTestType # lint-amnesty, pylint: disable=wrong-import-order @ddt.ddt @@ -231,6 +231,7 @@ class TestXblockUtils(SharedModuleStoreTestCase): class TestXBlockAside(SharedModuleStoreTestCase): """Test the xblock aside function.""" + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE @classmethod def setUpClass(cls): diff --git a/openedx/features/content_type_gating/tests/test_access.py b/openedx/features/content_type_gating/tests/test_access.py index 4f871f2499..fd1726fe63 100644 --- a/openedx/features/content_type_gating/tests/test_access.py +++ b/openedx/features/content_type_gating/tests/test_access.py @@ -3,6 +3,7 @@ Test audit user's access to various content based on content-gating features. """ import os from datetime import datetime, timedelta +from unittest.mock import patch, Mock import ddt from django.conf import settings @@ -11,8 +12,12 @@ from django.test.utils import override_settings from django.urls import reverse from django.utils import timezone from django.contrib.auth import get_user_model -from unittest.mock import patch, Mock # lint-amnesty, pylint: disable=wrong-import-order from pyquery import PyQuery as pq +from xmodule.modulestore.tests.django_utils import ( + TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase, SharedModuleStoreTestCase, +) +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory +from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID from lms.djangoapps.course_api.blocks.api import get_blocks from common.djangoapps.course_modes.tests.factories import CourseModeFactory @@ -42,9 +47,6 @@ from openedx.features.content_type_gating.services import ContentTypeGatingServi from common.djangoapps.student.models import CourseEnrollment, FBEEnrollmentExclusion from common.djangoapps.student.roles import CourseInstructorRole from common.djangoapps.student.tests.factories import TEST_PASSWORD, CourseEnrollmentFactory, UserFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID # lint-amnesty, pylint: disable=wrong-import-order METADATA = { 'group_access': { @@ -163,6 +165,7 @@ def _assert_block_is_empty(block, user_id, course, request_factory): )) class TestProblemTypeAccess(SharedModuleStoreTestCase, MasqueradeMixin): # pylint: disable=missing-class-docstring + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE PROBLEM_TYPES = ['problem', 'openassessment', 'drag-and-drop-v2', 'done', 'edx_sga'] # 'html' is a component that just displays html, in these tests it is used to test that users who do not have access # to graded problems still have access to non-problems @@ -783,6 +786,8 @@ class TestConditionalContentAccess(TestConditionalContent): Conditional Content allows course authors to run a/b tests on course content. We want to make sure that even if one of these a/b tests are being run, the student still has the correct access to the content. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE + @classmethod def setUpClass(cls): super().setUpClass() @@ -890,6 +895,7 @@ class TestMessageDeduplication(ModuleStoreTestCase): how it's currently tested). If that method changes to use something other than the template message, this method's checks will need to be updated. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE def setUp(self): super().setUp() @@ -1099,6 +1105,7 @@ class TestContentTypeGatingService(ModuleStoreTestCase): to check whether a sequence contains content type gated blocks The content_type_gate_for_block can be used to return the content type gate for a given block """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE def setUp(self): super().setUp() diff --git a/openedx/features/course_duration_limits/tests/test_course_expiration.py b/openedx/features/course_duration_limits/tests/test_course_expiration.py index 8e10d68f6e..c66734e28d 100644 --- a/openedx/features/course_duration_limits/tests/test_course_expiration.py +++ b/openedx/features/course_duration_limits/tests/test_course_expiration.py @@ -9,6 +9,7 @@ import ddt from django.conf import settings from django.urls import reverse from django.utils.timezone import now +from edx_toggles.toggles.testutils import override_waffle_flag from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.models import CourseEnrollment, FBEEnrollmentExclusion @@ -20,6 +21,7 @@ from common.djangoapps.student.tests.factories import InstructorFactory from common.djangoapps.student.tests.factories import OrgInstructorFactory from common.djangoapps.student.tests.factories import OrgStaffFactory from common.djangoapps.student.tests.factories import StaffFactory +from lms.djangoapps.course_home_api.toggles import COURSE_HOME_USE_LEGACY_FRONTEND from lms.djangoapps.courseware.tests.helpers import MasqueradeMixin from lms.djangoapps.discussion.django_comment_client.tests.factories import RoleFactory from openedx.core.djangoapps.content.course_overviews.models import CourseOverview @@ -42,6 +44,7 @@ from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID # lint- # pylint: disable=no-member @ddt.ddt +@override_waffle_flag(COURSE_HOME_USE_LEGACY_FRONTEND, active=True) class CourseExpirationTestCase(ModuleStoreTestCase, MasqueradeMixin): """Tests to verify the get_user_course_expiration_date function is working correctly""" def setUp(self): @@ -157,7 +160,7 @@ class CourseExpirationTestCase(ModuleStoreTestCase, MasqueradeMixin): result = get_user_course_expiration_date( self.user, CourseOverview.get_from_id(future_course.id), - ) + ).replace(microsecond=0) content_availability_date = start_date.replace(microsecond=0) assert result == (content_availability_date + access_duration) diff --git a/openedx/features/course_experience/tests/views/test_course_home.py b/openedx/features/course_experience/tests/views/test_course_home.py index c24623b8eb..788d150360 100644 --- a/openedx/features/course_experience/tests/views/test_course_home.py +++ b/openedx/features/course_experience/tests/views/test_course_home.py @@ -211,6 +211,7 @@ class TestCourseHomePage(CourseHomePageTestCase): # lint-amnesty, pylint: disab self.client.get(url) @mock.patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False}) + @override_waffle_flag(COURSE_HOME_USE_LEGACY_FRONTEND, active=True) def test_start_date_handling(self): """ Verify that the course home page handles start dates correctly. @@ -238,6 +239,7 @@ class TestCourseHomePage(CourseHomePageTestCase): # lint-amnesty, pylint: disab @ddt.ddt +@override_waffle_flag(COURSE_HOME_USE_LEGACY_FRONTEND, active=True) class TestCourseHomePageAccess(CourseHomePageTestCase): """ Test access to the course home page. @@ -285,7 +287,6 @@ class TestCourseHomePageAccess(CourseHomePageTestCase): [True, COURSE_VISIBILITY_PUBLIC, CourseUserType.GLOBAL_STAFF, True, True], ) @ddt.unpack - @override_waffle_flag(COURSE_HOME_USE_LEGACY_FRONTEND, active=True) def test_home_page( self, enable_unenrolled_access, course_visibility, user_type, expected_enroll_message, expected_course_outline, @@ -821,6 +822,7 @@ class TestCourseHomePageAccess(CourseHomePageTestCase): @ddt.ddt +@override_waffle_flag(COURSE_HOME_USE_LEGACY_FRONTEND, active=True) class CourseHomeFragmentViewTests(ModuleStoreTestCase): """ Test Messages Displayed on the Course Home diff --git a/openedx/features/course_experience/tests/views/test_course_outline.py b/openedx/features/course_experience/tests/views/test_course_outline.py index 524b4f766b..5e3afdf185 100644 --- a/openedx/features/course_experience/tests/views/test_course_outline.py +++ b/openedx/features/course_experience/tests/views/test_course_outline.py @@ -21,17 +21,21 @@ from opaque_keys.edx.keys import CourseKey, UsageKey from pyquery import PyQuery as pq from pytz import UTC from waffle.models import Switch +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, SharedModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory from common.djangoapps.student.tests.factories import StaffFactory from lms.djangoapps.course_api.blocks.transformers.milestones import MilestonesAndSpecialExamsTransformer +from lms.djangoapps.courseware.toggles import COURSEWARE_USE_LEGACY_FRONTEND from lms.djangoapps.gating import api as lms_gating_api +from lms.djangoapps.course_home_api.toggles import COURSE_HOME_USE_LEGACY_FRONTEND from lms.djangoapps.courseware.tests.helpers import MasqueradeMixin from lms.urls import RESET_COURSE_DEADLINES_NAME from openedx.core.djangoapps.course_date_signals.models import SelfPacedRelativeDatesConfig from openedx.core.djangoapps.schedules.models import Schedule -from openedx.core.djangoapps.schedules.tests.factories import ScheduleFactory # pylint: disable=unused-import from openedx.core.lib.gating import api as gating_api from openedx.features.content_type_gating.models import ContentTypeGatingConfig from openedx.features.course_experience import RELATIVE_DATES_FLAG @@ -41,9 +45,6 @@ from openedx.features.course_experience.views.course_outline import ( ) from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import UserFactory -from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order from ...utils import get_course_outline_block_tree from .test_course_home import course_home_url @@ -53,11 +54,13 @@ GATING_NAMESPACE_QUALIFIER = '.gating' @ddt.ddt +@override_waffle_flag(COURSE_HOME_USE_LEGACY_FRONTEND, active=True) class TestCourseOutlinePage(SharedModuleStoreTestCase, MasqueradeMixin): """ Test the course outline view. """ + MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE ENABLED_SIGNALS = ['course_published'] @classmethod @@ -270,6 +273,7 @@ class TestCourseOutlinePage(SharedModuleStoreTestCase, MasqueradeMixin): assert updated_staff_schedule.start_date.date() == datetime.date.today() +@override_waffle_flag(COURSE_HOME_USE_LEGACY_FRONTEND, active=True) class TestCourseOutlinePageWithPrerequisites(SharedModuleStoreTestCase, MilestonesTestCaseMixin): """ Test the course outline view with prerequisites. @@ -419,6 +423,7 @@ class TestCourseOutlinePageWithPrerequisites(SharedModuleStoreTestCase, Mileston assert not says_prerequisite_required +@override_waffle_flag(COURSE_HOME_USE_LEGACY_FRONTEND, active=True) class TestCourseOutlineResumeCourse(SharedModuleStoreTestCase, CompletionWaffleTestMixin): """ Test start course and resume course for the course outline view. @@ -568,9 +573,10 @@ class TestCourseOutlineResumeCourse(SharedModuleStoreTestCase, CompletionWaffleT content = pq(response.content) problem = course.children[0].children[0].children[0].children[0] - assert content('.action-resume-course').attr('href').endswith('/problem/' + problem.url_name) + assert content('.action-resume-course').attr('href').endswith('+type@problem+block@' + problem.url_name) @override_settings(LMS_BASE='test_url:9999') + @override_waffle_flag(COURSEWARE_USE_LEGACY_FRONTEND, active=True) def test_resume_course_with_completion_api(self): """ Tests completion API resume button functionality @@ -588,7 +594,7 @@ class TestCourseOutlineResumeCourse(SharedModuleStoreTestCase, CompletionWaffleT # Test for 'resume' link URL - should be problem 1 content = pq(response.content) - assert content('.action-resume-course').attr('href').endswith('/problem/' + problem1.url_name) + assert content('.action-resume-course').attr('href').endswith('+type@problem+block@' + problem1.url_name) self.complete_sequential(self.course, problem2) # Test for 'resume' link @@ -596,7 +602,7 @@ class TestCourseOutlineResumeCourse(SharedModuleStoreTestCase, CompletionWaffleT # Test for 'resume' link URL - should be problem 2 content = pq(response.content) - assert content('.action-resume-course').attr('href').endswith('/problem/' + problem2.url_name) + assert content('.action-resume-course').attr('href').endswith('+type@problem+block@' + problem2.url_name) # visit sequential 1, make sure 'Resume Course' URL is robust against 'Last Visited' # (even though I visited seq1/vert1, 'Resume Course' still points to seq2/vert2) @@ -605,7 +611,7 @@ class TestCourseOutlineResumeCourse(SharedModuleStoreTestCase, CompletionWaffleT # Test for 'resume' link URL - should be problem 2 (last completed block, NOT last visited) response = self.visit_course_home(course, resume_count=1) content = pq(response.content) - assert content('.action-resume-course').attr('href').endswith('/problem/' + problem2.url_name) + assert content('.action-resume-course').attr('href').endswith('+type@problem+block@' + problem2.url_name) def test_resume_course_deleted_sequential(self): """ @@ -631,7 +637,7 @@ class TestCourseOutlineResumeCourse(SharedModuleStoreTestCase, CompletionWaffleT response = self.visit_course_home(course, resume_count=1) content = pq(response.content) - assert content('.action-resume-course').attr('href').endswith('/sequential/' + sequential2.url_name) + assert content('.action-resume-course').attr('href').endswith('+type@sequential+block@' + sequential2.url_name) def test_resume_course_deleted_sequentials(self): """ @@ -669,7 +675,7 @@ class TestCourseOutlineResumeCourse(SharedModuleStoreTestCase, CompletionWaffleT response = self.visit_course_home(course, start_count=1, resume_count=0) content = pq(response.content) problem = course.children[0].children[0].children[0].children[0] - assert content('.action-resume-course').attr('href').endswith('/problem/' + problem.url_name) + assert content('.action-resume-course').attr('href').endswith('+type@problem+block@' + problem.url_name) @override_waffle_switch(ENABLE_COMPLETION_TRACKING_SWITCH, active=True) def test_course_outline_auto_open(self): @@ -725,6 +731,7 @@ class TestCourseOutlineResumeCourse(SharedModuleStoreTestCase, CompletionWaffleT assert DEFAULT_COMPLETION_TRACKING_START == view._completion_data_collection_start() +@override_waffle_flag(COURSE_HOME_USE_LEGACY_FRONTEND, active=True) class TestCourseOutlinePreview(SharedModuleStoreTestCase, MasqueradeMixin): """ Unit tests for staff preview of the course outline. diff --git a/openedx/features/course_experience/tests/views/test_course_sock.py b/openedx/features/course_experience/tests/views/test_course_sock.py index ca93a073bb..a37cc02171 100644 --- a/openedx/features/course_experience/tests/views/test_course_sock.py +++ b/openedx/features/course_experience/tests/views/test_course_sock.py @@ -10,6 +10,7 @@ from edx_toggles.toggles.testutils import override_waffle_flag from common.djangoapps.course_modes.models import CourseMode from lms.djangoapps.commerce.models import CommerceConfiguration +from lms.djangoapps.course_home_api.toggles import COURSE_HOME_USE_LEGACY_FRONTEND from openedx.core.djangolib.markup import HTML from openedx.features.course_experience import DISPLAY_COURSE_SOCK_FLAG from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory @@ -24,6 +25,7 @@ TEST_VERIFICATION_SOCK_LOCATOR = '