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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions cms/djangoapps/contentstore/tests/test_course_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
)
from openedx.core.djangoapps.models.course_details import CourseDetails
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.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order

Expand Down Expand Up @@ -602,10 +601,9 @@ def test_fetch_grader(self):
@mock.patch('common.djangoapps.track.event_transaction_utils.uuid4')
@mock.patch('cms.djangoapps.models.settings.course_grading.tracker')
@mock.patch('cms.djangoapps.contentstore.signals.signals.GRADING_POLICY_CHANGED.send')
@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
def test_update_from_json(self, store, send_signal, tracker, uuid):
def test_update_from_json(self, send_signal, tracker, uuid):
uuid.return_value = "mockUUID"
self.course = CourseFactory.create(default_store=store)
self.course = CourseFactory.create()
test_grader = CourseGradingModel.fetch(self.course.id)
# there should be no event raised after this call, since nothing got modified
altered_grader = CourseGradingModel.update_from_json(self.course.id, test_grader.__dict__, self.user)
Expand Down Expand Up @@ -660,14 +658,13 @@ def test_update_from_json(self, store, send_signal, tracker, uuid):
)
])

@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
def test_must_fire_grading_event_and_signal_multiple_type(self, store):
def test_must_fire_grading_event_and_signal_multiple_type(self):
"""
Verifies that 'must_fire_grading_event_and_signal' ignores (returns False) if we modify
short_label and or name
use test_must_fire_grading_event_and_signal_multiple_type_2_split to run this test only
"""
self.course = CourseFactory.create(default_store=store)
self.course = CourseFactory.create()
# .raw_grader approximates what our UI sends down. It uses decimal representation of percent
# without it, the weights would be percentages
raw_grader_list = modulestore().get_course(self.course.id).raw_grader
Expand All @@ -686,14 +683,13 @@ def test_must_fire_grading_event_and_signal_multiple_type(self, store):
self.assertTrue(result)

@override_waffle_flag(MATERIAL_RECOMPUTE_ONLY_FLAG, True)
@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
def test_must_fire_grading_event_and_signal_multiple_type_waffle_on(self, store):
def test_must_fire_grading_event_and_signal_multiple_type_waffle_on(self):
"""
Verifies that 'must_fire_grading_event_and_signal' ignores (returns False) if we modify
short_label and or name
use test_must_fire_grading_event_and_signal_multiple_type_2_split to run this test only
"""
self.course = CourseFactory.create(default_store=store)
self.course = CourseFactory.create()
# .raw_grader approximates what our UI sends down. It uses decimal representation of percent
# without it, the weights would be percentages
raw_grader_list = modulestore().get_course(self.course.id).raw_grader
Expand All @@ -711,14 +707,13 @@ def test_must_fire_grading_event_and_signal_multiple_type_waffle_on(self, store)
)
self.assertFalse(result)

@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
def test_must_fire_grading_event_and_signal_return_true(self, store):
def test_must_fire_grading_event_and_signal_return_true(self):
"""
Verifies that 'must_fire_grading_event_and_signal' ignores (returns False) if we modify
short_label and or name
use _2_split suffix to run this test only
"""
self.course = CourseFactory.create(default_store=store)
self.course = CourseFactory.create()
# .raw_grader approximates what our UI sends down. It uses decimal representation of percent
# without it, the weights would be percentages
raw_grader_list = modulestore().get_course(self.course.id).raw_grader
Expand Down
23 changes: 16 additions & 7 deletions cms/djangoapps/contentstore/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
from openedx.core.djangoapps.site_configuration.tests.test_util import with_site_configuration_context
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, SharedModuleStoreTestCase # 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 # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.partitions.partitions import Group, UserPartition # lint-amnesty, pylint: disable=wrong-import-order

Expand Down Expand Up @@ -337,15 +341,16 @@ class GroupVisibilityTest(CourseTestCase):
Test content group access rules.
"""

MODULESTORE = TEST_DATA_SPLIT_MODULESTORE

def setUp(self):
super().setUp()

chapter = ItemFactory.create(category='chapter', parent_location=self.course.location)
sequential = ItemFactory.create(category='sequential', parent_location=chapter.location)
vertical = ItemFactory.create(category='vertical', parent_location=sequential.location)
html = ItemFactory.create(category='html', parent_location=vertical.location)
chapter = ItemFactory.create(category='chapter', parent=self.course)
sequential = ItemFactory.create(category='sequential', parent=chapter)
vertical = ItemFactory.create(category='vertical', parent=sequential)
html = ItemFactory.create(category='html', parent=vertical)
problem = ItemFactory.create(
category='problem', parent_location=vertical.location, data="<problem></problem>"
category='problem', parent=vertical, data="<problem></problem>"
)
self.sequential = self.store.get_item(sequential.location)
self.vertical = self.store.get_item(vertical.location)
Expand Down Expand Up @@ -417,6 +422,10 @@ def test_sequential_and_problem_have_group_access(self):
# This is a no-op.
self.set_group_access(self.vertical, {1: []})
self.set_group_access(self.problem, {2: [3, 4]})
# get updated sequential/vertical/problem
self.sequential = self.store.get_item(self.sequential.location)
self.vertical = self.store.get_item(self.vertical.location)
self.problem = self.store.get_item(self.problem.location)

# Note that "has_children_visible_to_specific_partition_groups" only checks immediate children.
self.assertFalse(utils.has_children_visible_to_specific_partition_groups(self.sequential))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from openedx.features.content_type_gating.helpers import CONTENT_GATING_PARTITION_ID
from openedx.features.content_type_gating.partitions import CONTENT_TYPE_GATING_SCHEME
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 TEST_DATA_SPLIT_MODULESTORE
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID, Group, UserPartition # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.validation import StudioValidation, StudioValidationMessage # lint-amnesty, pylint: disable=wrong-import-order
Expand Down Expand Up @@ -64,9 +64,9 @@ def _create_content_experiment(self, cid=-1, group_id=None, cid_for_problem=None
parent_location=sequential.location,
display_name=f'Test Unit {name_suffix}'
)
c0_url = self.course.id.make_usage_key("vertical", "split_test_cond0")
c1_url = self.course.id.make_usage_key("vertical", "split_test_cond1")
c2_url = self.course.id.make_usage_key("vertical", "split_test_cond2")
c0_url = self.course.id.make_usage_key("vertical", f"split_test_cond0_{name_suffix}")
c1_url = self.course.id.make_usage_key("vertical", f"split_test_cond1_{name_suffix}")
c2_url = self.course.id.make_usage_key("vertical", f"split_test_cond2_{name_suffix}")
split_test = ItemFactory.create(
category='split_test',
parent_location=vertical.location,
Expand Down Expand Up @@ -693,6 +693,7 @@ class GroupConfigurationsUsageInfoTestCase(CourseTestCase, HelperMethods):
"""
Tests for usage information of configurations and content groups.
"""
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE

def _get_user_partition(self, scheme):
"""
Expand Down Expand Up @@ -770,30 +771,21 @@ def test_can_get_correct_usage_info_for_content_groups(self):

self.assertEqual(actual, expected)

@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
def test_can_get_correct_usage_info_with_orphan(self, module_store_type):
def test_can_get_correct_usage_info_with_orphan(self):
"""
Test if content group json updated successfully with usage information
even if there is an orphan in content group.
"""
self.course = CourseFactory.create(default_store=module_store_type)
self.course = CourseFactory.create()
self._add_user_partitions(count=1, scheme_id='cohort')
vertical, __ = self._create_problem_with_content_group(cid=0, group_id=1, name_suffix='0', orphan=True)

# Assert that there is an orphan in the course, and that it's the vertical
self.assertEqual(len(self.store.get_orphans(self.course.id)), 1)
self.assertIn(vertical.location, self.store.get_orphans(self.course.id))

# Get the expected content group information based on module store.
if module_store_type == ModuleStoreEnum.Type.mongo:
expected = self._get_expected_content_group(usage_for_group=[
{
'url': f'/container/{vertical.location}',
'label': 'Test Unit 0 / Test Problem 0'
}
])
else:
expected = self._get_expected_content_group(usage_for_group=[])
# Get the expected content group information.
expected = self._get_expected_content_group(usage_for_group=[])

# Get the actual content group information
actual = self._get_user_partition('cohort')
Expand All @@ -807,8 +799,8 @@ def test_can_use_one_content_group_in_multiple_problems(self):
content group.
"""
self._add_user_partitions(scheme_id='cohort')
vertical, __ = self._create_problem_with_content_group(cid=0, group_id=1, name_suffix='0')
vertical1, __ = self._create_problem_with_content_group(cid=0, group_id=1, name_suffix='1')
vertical, __ = self._create_problem_with_content_group(cid=0, group_id=1, name_suffix='0')

actual = self._get_user_partition('cohort')

Expand Down Expand Up @@ -868,6 +860,7 @@ def test_can_get_correct_usage_info_for_split_test(self):
),
]
self.store.update_item(self.course, ModuleStoreEnum.UserID.test)
self.reload_course()

__, split_test, problem = self._create_content_experiment(cid=0, name_suffix='0', group_id=3, cid_for_problem=1) # lint-amnesty, pylint: disable=unused-variable

Expand Down Expand Up @@ -1066,14 +1059,13 @@ def test_can_handle_without_parent(self):
"""
self._add_user_partitions()
# Create split test without parent.
with modulestore().branch_setting(ModuleStoreEnum.Branch.published_only):
orphan = modulestore().create_item(
ModuleStoreEnum.UserID.test,
self.course.id, 'split_test',
)
orphan.user_partition_id = 0
orphan.display_name = 'Test Content Experiment'
modulestore().update_item(orphan, ModuleStoreEnum.UserID.test)
orphan = self.store.create_item(
ModuleStoreEnum.UserID.test,
self.course.id, 'split_test',
)
orphan.user_partition_id = 0
orphan.display_name = 'Test Content Experiment'
self.store.update_item(orphan, ModuleStoreEnum.UserID.test)

self.save_course()
actual = GroupConfiguration.get_content_experiment_usage_info(self.store, self.course)
Expand Down
Loading