test: prepare tests for removing support for children in Old Mongo

This commit is contained in:
Sagirov Eugeniy
2022-10-28 15:53:17 +03:00
committed by David Ormsbee
parent f6870f7ae7
commit 8f88422c4a
45 changed files with 498 additions and 1063 deletions

View File

@@ -11,8 +11,7 @@ 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 xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE
from openedx.core.djangolib.testing.utils import skip_unless_lms
@@ -72,7 +71,7 @@ class BookmarksListViewTests(BookmarksViewsTestsBase):
GET /api/bookmarks/v1/bookmarks/?course_id={course_id1}
POST /api/bookmarks/v1/bookmarks
"""
MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
@ddt.data(
(1, False),
@@ -90,9 +89,7 @@ class BookmarksListViewTests(BookmarksViewsTestsBase):
expected order without optional fields.
"""
course, __, bookmarks = self.create_course_with_bookmarks_count(
bookmarks_count, store_type=ModuleStoreEnum.Type.mongo
)
course, __, bookmarks = self.create_course_with_bookmarks_count(bookmarks_count)
query_parameters = 'course_id={}&page_size={}'.format(
quote(str(course.id)), 100)
@@ -133,9 +130,7 @@ class BookmarksListViewTests(BookmarksViewsTestsBase):
Test that requesting bookmarks for a course return results with pagination 200 code.
"""
course, __, bookmarks = self.create_course_with_bookmarks_count(
bookmarks_count, store_type=ModuleStoreEnum.Type.mongo
)
course, __, bookmarks = self.create_course_with_bookmarks_count(bookmarks_count)
page_size = 5
query_parameters = 'course_id={}&page_size={}'.format(

View File

@@ -17,7 +17,7 @@ from openedx_events.tests.utils import OpenEdxEventsTestMixin
from common.djangoapps.student.models import CourseEnrollment
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 TEST_DATA_MIXED_MODULESTORE, ModuleStoreTestCase # 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 ToyCourseFactory # lint-amnesty, pylint: disable=wrong-import-order
from .. import cohorts
@@ -149,7 +149,7 @@ class TestCohorts(ModuleStoreTestCase):
"""
Test the cohorts feature
"""
MODULESTORE = TEST_DATA_MIXED_MODULESTORE
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
def setUp(self):
"""
@@ -648,7 +648,7 @@ class TestCohortsAndPartitionGroups(ModuleStoreTestCase):
"""
Test Cohorts and Partitions Groups.
"""
MODULESTORE = TEST_DATA_MIXED_MODULESTORE
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
def setUp(self):
"""

View File

@@ -12,7 +12,7 @@ from openedx.core.djangoapps.user_api.partition_schemes import RandomUserPartiti
from openedx.core.djangolib.testing.utils import skip_unless_lms
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 TEST_DATA_MIXED_MODULESTORE, ModuleStoreTestCase # 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 ToyCourseFactory # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.partitions.partitions import Group, UserPartition, UserPartitionError # lint-amnesty, pylint: disable=wrong-import-order
@@ -27,7 +27,7 @@ class TestCohortPartitionScheme(ModuleStoreTestCase):
"""
Test the logic for linking a user to a partition group based on their cohort.
"""
MODULESTORE = TEST_DATA_MIXED_MODULESTORE
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
def setUp(self):
"""
@@ -267,7 +267,7 @@ class TestGetCohortedUserPartition(ModuleStoreTestCase):
"""
Test that `get_cohorted_user_partition` returns the first user_partition with scheme `CohortPartitionScheme`.
"""
MODULESTORE = TEST_DATA_MIXED_MODULESTORE
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
def setUp(self):
"""

View File

@@ -12,7 +12,7 @@ from unittest.mock import patch # lint-amnesty, pylint: disable=wrong-import-or
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.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from openedx.core.djangoapps.models.course_details import ABOUT_ATTRIBUTES, CourseDetails
@@ -25,7 +25,7 @@ class CourseDetailsTestCase(ModuleStoreTestCase):
"""
Tests the first course settings page (course dates, overview, etc.).
"""
MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
def setUp(self):
super().setUp()
@@ -35,7 +35,7 @@ class CourseDetailsTestCase(ModuleStoreTestCase):
details = CourseDetails.fetch(self.course.id)
assert details.org == self.course.location.org, 'Org not copied into'
assert details.course_id == self.course.location.course, 'Course_id not copied into'
assert details.run == self.course.location.block_id, 'Course name not copied into'
assert details.run == self.course.location.run, 'Course run not copied into'
assert details.course_image_name == self.course.course_image
assert details.start_date.tzinfo is not None
assert details.end_date is None, ('end date somehow initialized ' + str(details.end_date))
@@ -116,7 +116,7 @@ class CourseDetailsTestCase(ModuleStoreTestCase):
jsondetails.instructor_info
def test_toggle_pacing_during_course_run(self):
self.course.start = datetime.datetime.now()
self.course.start = datetime.datetime.now(UTC)
self.store.update_item(self.course, self.user.id)
details = CourseDetails.fetch(self.course.id)

View File

@@ -11,7 +11,7 @@ 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.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from common.djangoapps.student.tests.factories import UserFactory
@@ -351,7 +351,7 @@ class TestGatingGradesIntegration(GradeTestBase):
"""
Tests the integration between the gating API and our Persistent Grades framework.
"""
MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
def test_get_subsection_grade_percentage(self):

View File

@@ -3,17 +3,14 @@ Tests for functionality in openedx/core/lib/courses.py.
"""
import ddt
from django.test.utils import override_settings
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from ..courses import course_image_url
@ddt.ddt
class CourseImageTestCase(ModuleStoreTestCase):
"""Tests for course image URLs."""
@@ -52,13 +49,12 @@ class CourseImageTestCase(ModuleStoreTestCase):
)
@override_settings(DEFAULT_COURSE_ABOUT_IMAGE_URL='test.png')
@ddt.data(ModuleStoreEnum.Type.split, ModuleStoreEnum.Type.mongo)
def test_empty_image_name(self, default_store):
def test_empty_image_name(self):
"""
Verify that if a course has empty `course_image`, `course_image_url` returns
`DEFAULT_COURSE_ABOUT_IMAGE_URL` defined in the settings.
"""
course = CourseFactory.create(course_image='', default_store=default_store)
course = CourseFactory.create(course_image='')
assert '/static/test.png' == course_image_url(course)
def test_get_banner_image_url(self):

View File

@@ -8,7 +8,6 @@ from django.test import TestCase
from django.test.client import RequestFactory
from django.test.utils import override_settings
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
@@ -70,113 +69,63 @@ class GetCoursewareUrlTests(SharedModuleStoreTestCase):
@classmethod
def create_test_courses(cls):
"""
We build two simple course structures (one using Split, the other Old Mongo).
Each course structure is a non-branching tree from the root Course block down
to the Component-level problem block; that is, we make one item for each course
hierarchy level.
We build simple course structures.
Course structure is a non-branching tree from the root Course block down
to the Component-level problem block;
For easy access in the test functions, we return them in a dict like this:
For easy access in the test functions, we return a dict like this:
{
"split": {
"course_run": <course block for Split Mongo course>,
"section": <chapter block in course run>
"subsection": <sequence block in section>
"unit": <vertical block in subsection>
"component": <problem block in unit>
},
"mongo": {
"course_run": <course block for (deprecated) Old Mongo course>,
... etc ...
}
"course_run": <course block for Split Mongo course>,
"section": <chapter block in course run>
"subsection": <sequence block in section>
"unit": <vertical block in subsection>
"component": <problem block in unit>
}
"""
# Make Split Mongo course.
with cls.store.default_store(ModuleStoreEnum.Type.split):
course_run = CourseFactory.create(
org='TestX',
number='UrlHelpers',
run='split',
display_name='URL Helpers Test Course',
course_run = CourseFactory.create(
org='TestX',
number='UrlHelpers',
run='split',
display_name='URL Helpers Test Course',
)
with cls.store.bulk_operations(course_run.id):
section = ItemFactory.create(
parent_location=course_run.location,
category='chapter',
display_name="Generated Section",
)
with cls.store.bulk_operations(course_run.id):
section = ItemFactory.create(
parent_location=course_run.location,
category='chapter',
display_name="Generated Section",
)
subsection = ItemFactory.create(
parent_location=section.location,
category='sequential',
display_name="Generated Subsection",
)
unit = ItemFactory.create(
parent_location=subsection.location,
category='vertical',
display_name="Generated Unit",
)
component = ItemFactory.create(
parent_location=unit.location,
category='problem',
display_name="Generated Problem Component",
)
# Make (deprecated) Old Mongo course.
with cls.store.default_store(ModuleStoreEnum.Type.mongo):
deprecated_course_run = CourseFactory.create(
org='TestX',
number='UrlHelpers',
run='mongo',
display_name='URL Helpers Test Course (Deprecated)',
subsection = ItemFactory.create(
parent_location=section.location,
category='sequential',
display_name="Generated Subsection",
)
unit = ItemFactory.create(
parent_location=subsection.location,
category='vertical',
display_name="Generated Unit",
)
component = ItemFactory.create(
parent_location=unit.location,
category='problem',
display_name="Generated Problem Component",
)
with cls.store.bulk_operations(deprecated_course_run.id):
deprecated_section = ItemFactory.create(
parent_location=deprecated_course_run.location,
category='chapter',
display_name="Generated Section",
)
deprecated_subsection = ItemFactory.create(
parent_location=deprecated_section.location,
category='sequential',
display_name="Generated Subsection",
)
deprecated_unit = ItemFactory.create(
parent_location=deprecated_subsection.location,
category='vertical',
display_name="Generated Unit",
)
deprecated_component = ItemFactory.create(
parent_location=deprecated_unit.location,
category='problem',
display_name="Generated Problem Component",
)
return {
ModuleStoreEnum.Type.split: {
'course_run': course_run,
'section': section,
'subsection': subsection,
'unit': unit,
'component': component,
},
ModuleStoreEnum.Type.mongo: {
'course_run': deprecated_course_run,
'section': deprecated_section,
'subsection': deprecated_subsection,
'unit': deprecated_unit,
'component': deprecated_component,
}
'course_run': course_run,
'section': section,
'subsection': subsection,
'unit': unit,
'component': component,
}
@ddt.data(
(
ModuleStoreEnum.Type.split,
'mfe',
'course_run',
'http://learning-mfe/course/course-v1:TestX+UrlHelpers+split'
),
(
ModuleStoreEnum.Type.split,
'mfe',
'section',
(
@@ -185,7 +134,6 @@ class GetCoursewareUrlTests(SharedModuleStoreTestCase):
),
),
(
ModuleStoreEnum.Type.split,
'mfe',
'subsection',
(
@@ -194,7 +142,6 @@ class GetCoursewareUrlTests(SharedModuleStoreTestCase):
),
),
(
ModuleStoreEnum.Type.split,
'mfe',
'unit',
(
@@ -204,7 +151,6 @@ class GetCoursewareUrlTests(SharedModuleStoreTestCase):
),
),
(
ModuleStoreEnum.Type.split,
'mfe',
'component',
(
@@ -214,58 +160,29 @@ class GetCoursewareUrlTests(SharedModuleStoreTestCase):
),
),
(
ModuleStoreEnum.Type.split,
'legacy',
'course_run',
'/courses/course-v1:TestX+UrlHelpers+split/courseware',
),
(
ModuleStoreEnum.Type.split,
'legacy',
'subsection',
'/courses/course-v1:TestX+UrlHelpers+split/courseware/Generated_Section/Generated_Subsection/',
),
(
ModuleStoreEnum.Type.split,
'legacy',
'unit',
'/courses/course-v1:TestX+UrlHelpers+split/courseware/Generated_Section/Generated_Subsection/1',
),
(
ModuleStoreEnum.Type.split,
'legacy',
'component',
'/courses/course-v1:TestX+UrlHelpers+split/courseware/Generated_Section/Generated_Subsection/1',
),
(
ModuleStoreEnum.Type.mongo,
'legacy',
'course_run',
'/courses/TestX/UrlHelpers/mongo/courseware',
),
(
ModuleStoreEnum.Type.mongo,
'legacy',
'subsection',
'/courses/TestX/UrlHelpers/mongo/courseware/Generated_Section/Generated_Subsection/',
),
(
ModuleStoreEnum.Type.mongo,
'legacy',
'unit',
'/courses/TestX/UrlHelpers/mongo/courseware/Generated_Section/Generated_Subsection/1',
),
(
ModuleStoreEnum.Type.mongo,
'legacy',
'component',
'/courses/TestX/UrlHelpers/mongo/courseware/Generated_Section/Generated_Subsection/1',
),
)
)
@ddt.unpack
def test_get_courseware_url(
self,
store_type,
active_experience,
structure_level,
expected_path,
@@ -278,10 +195,10 @@ class GetCoursewareUrlTests(SharedModuleStoreTestCase):
check that the expected path (URL without querystring) is returned by `get_courseware_url`.
"""
block = self.items[store_type][structure_level]
block = self.items[structure_level]
with _patch_courseware_mfe_is_active(active_experience == 'mfe') as mock_mfe_is_active:
url = url_helpers.get_courseware_url(block.location)
path = url.split('?')[0]
assert path == expected_path
course_run = self.items[store_type]['course_run']
course_run = self.items['course_run']
mock_mfe_is_active.assert_called_once()

View File

@@ -28,9 +28,6 @@ class CompletionBatchTestCase(CompletionWaffleTestMixin, ModuleStoreTestCase):
UNENROLLED_USERNAME = 'unenrolled_user'
COURSE_KEY = 'course-v1:TestX+101+Test'
BLOCK_KEY = 'block-v1:TestX+101+Test+type@problem+block@Test_Problem'
# And for old mongo:
COURSE_KEY_DEPRECATED = 'TestX/201/Test'
BLOCK_KEY_DEPRECATED = 'i4x://TestX/201/problem/Test_Problem'
def setUp(self):
"""
@@ -52,17 +49,6 @@ class CompletionBatchTestCase(CompletionWaffleTestMixin, ModuleStoreTestCase):
parent=self.course, category="problem", display_name="Test Problem", publish_item=False,
)
assert str(self.problem.location) == self.BLOCK_KEY
# And an old mongo course:
self.course_deprecated = CourseFactory.create(
org='TestX', number='201', display_name='Test',
default_store=ModuleStoreEnum.Type.mongo,
)
assert str(self.course_deprecated.id) == self.COURSE_KEY_DEPRECATED
self.problem_deprecated = ItemFactory.create(
parent=self.course_deprecated, category="problem", display_name="Test Problem",
publish_item=False,
)
assert str(self.problem_deprecated.location) == self.BLOCK_KEY_DEPRECATED
# Create users
self.staff_user = UserFactory(is_staff=True)
@@ -71,7 +57,6 @@ class CompletionBatchTestCase(CompletionWaffleTestMixin, ModuleStoreTestCase):
# Enrol one user in the course
CourseEnrollmentFactory.create(user=self.enrolled_user, course_id=self.course.id)
CourseEnrollmentFactory.create(user=self.enrolled_user, course_id=self.course_deprecated.id)
# Login the enrolled user by for all tests
self.client = APIClient()
@@ -101,16 +86,6 @@ class CompletionBatchTestCase(CompletionWaffleTestMixin, ModuleStoreTestCase):
}
}, 200, {'detail': 'ok'}
),
# Valid submission (old mongo)
(
{
'username': ENROLLED_USERNAME,
'course_key': COURSE_KEY_DEPRECATED,
'blocks': {
BLOCK_KEY_DEPRECATED: 1.0,
}
}, 200, {'detail': 'ok'}
),
# Blocks list can be empty, though it's a no-op
(
{
@@ -222,16 +197,6 @@ class CompletionBatchTestCase(CompletionWaffleTestMixin, ModuleStoreTestCase):
}
}, 200, {'detail': 'ok'}
),
# Staff can submit completion on behalf of other users (old mongo)
(
{
'username': ENROLLED_USERNAME,
'course_key': COURSE_KEY_DEPRECATED,
'blocks': {
BLOCK_KEY_DEPRECATED: 1.0,
}
}, 200, {'detail': 'ok'}
),
# User must be enrolled in the course
(
{