Skip to content
Snippets Groups Projects
Unverified Commit af86f785 authored by Calen Pennington's avatar Calen Pennington Committed by GitHub
Browse files

Merge pull request #19333 from cpennington/enable-content-gate-partition-when-override-enabled

Enable content gate partition when override enabled
parents 352ba32c f8833e1f
No related merge requests found
......@@ -148,4 +148,8 @@ class ContentTypeGatingConfig(StackedConfigurationModel):
return bool(self.enabled and self.enabled_as_of <= target_date)
def __str__(self):
return "ContentTypeGatingConfig(enabled={!r}, enabled_as_of={!r}, studio_override_enabled={!r})"
return "ContentTypeGatingConfig(enabled={!r}, enabled_as_of={!r}, studio_override_enabled={!r})".format(
self.enabled,
self.enabled_as_of,
self.studio_override_enabled,
)
......@@ -44,7 +44,9 @@ def create_content_gating_partition(course):
Create and return the Content Gating user partition.
"""
if not ContentTypeGatingConfig.enabled_for_course(course_key=course.id):
enabled_for_course = ContentTypeGatingConfig.enabled_for_course(course_key=course.id)
studio_override_for_course = ContentTypeGatingConfig.current(course_key=course.id).studio_override_enabled
if not (enabled_for_course or studio_override_for_course):
return None
try:
......
from datetime import date
from mock import Mock, patch
from opaque_keys.edx.keys import CourseKey
from openedx.core.djangolib.testing.utils import CacheIsolationTestCase
from openedx.features.content_type_gating.partitions import create_content_gating_partition, CONTENT_GATING_PARTITION_ID
from openedx.features.content_type_gating.models import ContentTypeGatingConfig
from xmodule.partitions.partitions import UserPartitionError
class TestContentTypeGatingPartition(CacheIsolationTestCase):
def setUp(self):
self.course_key = CourseKey.from_string('course-v1:test+course+key')
def test_create_content_gating_partition_happy_path(self):
mock_course = Mock(id=self.course_key, user_partitions={})
ContentTypeGatingConfig.objects.create(enabled=True, enabled_as_of=date(2018, 1, 1))
with patch('openedx.features.content_type_gating.partitions.ContentTypeGatingPartitionScheme.create_user_partition') as mock_create:
partition = create_content_gating_partition(mock_course)
self.assertEqual(partition, mock_create.return_value)
def test_create_content_gating_partition_override_only(self):
mock_course = Mock(id=self.course_key, user_partitions={})
ContentTypeGatingConfig.objects.create(enabled=False, studio_override_enabled=True)
partition = create_content_gating_partition(mock_course)
self.assertIsNotNone(partition)
def test_create_content_gating_partition_disabled(self):
mock_course = Mock(id=self.course_key, user_partitions={})
ContentTypeGatingConfig.objects.create(enabled=False, studio_override_enabled=False)
partition = create_content_gating_partition(mock_course)
self.assertIsNone(partition)
def test_create_content_gating_partition_no_scheme_installed(self):
mock_course = Mock(id=self.course_key, user_partitions={})
ContentTypeGatingConfig.objects.create(enabled=True, enabled_as_of=date(2018, 1, 1))
with patch('openedx.features.content_type_gating.partitions.UserPartition.get_scheme', side_effect=UserPartitionError):
partition = create_content_gating_partition(mock_course)
self.assertIsNone(partition)
def test_create_content_gating_partition_partition_id_used(self):
mock_course = Mock(id=self.course_key, user_partitions={Mock(name='partition', id=CONTENT_GATING_PARTITION_ID): object()})
ContentTypeGatingConfig.objects.create(enabled=True, enabled_as_of=date(2018, 1, 1))
with patch('openedx.features.content_type_gating.partitions.LOG') as mock_log:
partition = create_content_gating_partition(mock_course)
mock_log.warning.assert_called()
self.assertIsNone(partition)
......@@ -139,4 +139,7 @@ class CourseDurationLimitConfig(StackedConfigurationModel):
return bool(self.enabled and self.enabled_as_of <= target_date)
def __str__(self):
return "CourseDurationLimits(enabled={!r}, enabled_as_of={!r})"
return "CourseDurationLimits(enabled={!r}, enabled_as_of={!r})".format(
self.enabled,
self.enabled_as_of,
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment