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.
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 = '<div class="verification-sock"'
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
@override_waffle_flag(COURSE_HOME_USE_LEGACY_FRONTEND, active=True)
|
||||
class TestCourseSockView(SharedModuleStoreTestCase):
|
||||
"""
|
||||
Tests for the course verification sock fragment view.
|
||||
|
||||
@@ -3,6 +3,7 @@ Tests for masquerading functionality on course_experience
|
||||
"""
|
||||
|
||||
from edx_toggles.toggles.testutils import override_waffle_flag
|
||||
from lms.djangoapps.course_home_api.toggles import COURSE_HOME_USE_LEGACY_FRONTEND
|
||||
from lms.djangoapps.courseware.tests.helpers import MasqueradeMixin
|
||||
from openedx.features.course_experience import DISPLAY_COURSE_SOCK_FLAG, SHOW_UPGRADE_MSG_ON_COURSE_HOME
|
||||
from common.djangoapps.student.roles import CourseStaffRole
|
||||
@@ -66,6 +67,7 @@ class TestVerifiedUpgradesWithMasquerade(MasqueradeTestBase):
|
||||
Tests for the course verification upgrade messages while the user is being masqueraded.
|
||||
"""
|
||||
|
||||
@override_waffle_flag(COURSE_HOME_USE_LEGACY_FRONTEND, active=True)
|
||||
@override_waffle_flag(DISPLAY_COURSE_SOCK_FLAG, active=True)
|
||||
@override_waffle_flag(SHOW_UPGRADE_MSG_ON_COURSE_HOME, active=True)
|
||||
def test_masquerade_as_student(self):
|
||||
@@ -75,6 +77,7 @@ class TestVerifiedUpgradesWithMasquerade(MasqueradeTestBase):
|
||||
self.assertContains(response, TEST_VERIFICATION_SOCK_LOCATOR, html=False)
|
||||
self.assertContains(response, UPGRADE_MESSAGE_CONTAINER, html=False)
|
||||
|
||||
@override_waffle_flag(COURSE_HOME_USE_LEGACY_FRONTEND, active=True)
|
||||
@override_waffle_flag(DISPLAY_COURSE_SOCK_FLAG, active=True)
|
||||
def test_masquerade_as_verified_student(self):
|
||||
user_group_id = self.get_group_id_by_course_mode_name(
|
||||
@@ -87,6 +90,7 @@ class TestVerifiedUpgradesWithMasquerade(MasqueradeTestBase):
|
||||
self.assertNotContains(response, TEST_VERIFICATION_SOCK_LOCATOR, html=False)
|
||||
self.assertNotContains(response, UPGRADE_MESSAGE_CONTAINER, html=False)
|
||||
|
||||
@override_waffle_flag(COURSE_HOME_USE_LEGACY_FRONTEND, active=True)
|
||||
@override_waffle_flag(DISPLAY_COURSE_SOCK_FLAG, active=True)
|
||||
def test_masquerade_as_masters_student(self):
|
||||
user_group_id = self.get_group_id_by_course_mode_name(
|
||||
|
||||
@@ -20,6 +20,7 @@ from opaque_keys.edx.keys import CourseKey, UsageKey
|
||||
|
||||
from common.djangoapps.student.models import CourseEnrollment
|
||||
from common.djangoapps.student.tests.factories import UserFactory
|
||||
from lms.djangoapps.course_home_api.toggles import COURSE_HOME_USE_LEGACY_FRONTEND
|
||||
from openedx.core.djangolib.testing.utils import skip_unless_lms
|
||||
from openedx.features.enterprise_support.tests import FEATURES_WITH_ENTERPRISE_ENABLED
|
||||
from openedx.features.enterprise_support.tests.factories import (
|
||||
@@ -638,6 +639,7 @@ class TestCourseAccessed(SharedModuleStoreTestCase, CompletionWaffleTestMixin):
|
||||
}
|
||||
)
|
||||
|
||||
@override_waffle_flag(COURSE_HOME_USE_LEGACY_FRONTEND, active=True)
|
||||
def test_course_accessed_for_visit_course_home(self):
|
||||
"""
|
||||
Test that a visit to course home does not fall under course access
|
||||
|
||||
Reference in New Issue
Block a user