Add StackedConfigurationModels for managing content_type_gating and course_duration_limits
This commit is contained in:
@@ -30,7 +30,7 @@ from openedx.core.djangoapps.catalog.utils import get_currency_data
|
||||
from openedx.core.djangoapps.embargo import api as embargo_api
|
||||
from openedx.core.djangoapps.programs.utils import ProgramDataExtender, ProgramProgressMeter
|
||||
from openedx.core.djangoapps.waffle_utils import WaffleFlag, WaffleFlagNamespace
|
||||
from openedx.features.course_duration_limits.config import CONTENT_TYPE_GATING_FLAG
|
||||
from openedx.features.content_type_gating.models import ContentTypeGatingConfig
|
||||
from student.models import CourseEnrollment
|
||||
from util.db import outer_atomic
|
||||
from xmodule.modulestore.django import modulestore
|
||||
@@ -188,7 +188,7 @@ class ChooseModeView(View):
|
||||
"error": error,
|
||||
"responsive": True,
|
||||
"nav_hidden": True,
|
||||
"content_gating_enabled": CONTENT_TYPE_GATING_FLAG.is_enabled(),
|
||||
"content_gating_enabled": ContentTypeGatingConfig.enabled_for_course(course_key=course_key),
|
||||
}
|
||||
context.update(
|
||||
get_experiment_user_metadata_context(
|
||||
|
||||
@@ -1309,7 +1309,7 @@ class CourseEnrollment(models.Model):
|
||||
return enrollment
|
||||
|
||||
@classmethod
|
||||
def get_enrollment(cls, user, course_key):
|
||||
def get_enrollment(cls, user, course_key, select_related=None):
|
||||
"""Returns a CourseEnrollment object.
|
||||
|
||||
Args:
|
||||
@@ -1324,7 +1324,10 @@ class CourseEnrollment(models.Model):
|
||||
if user.is_anonymous:
|
||||
return None
|
||||
try:
|
||||
return cls.objects.get(
|
||||
query = cls.objects
|
||||
if select_related is not None:
|
||||
query = query.select_related(*select_related)
|
||||
return query.get(
|
||||
user=user,
|
||||
course_id=course_key
|
||||
)
|
||||
|
||||
@@ -5,7 +5,7 @@ import itertools
|
||||
import json
|
||||
import re
|
||||
import unittest
|
||||
from datetime import timedelta
|
||||
from datetime import timedelta, date
|
||||
|
||||
import ddt
|
||||
from completion.test_utils import submit_completions_for_testing, CompletionWaffleTestMixin
|
||||
@@ -31,7 +31,7 @@ from openedx.core.djangoapps.schedules.config import COURSE_UPDATE_WAFFLE_FLAG
|
||||
from openedx.core.djangoapps.schedules.tests.factories import ScheduleFactory
|
||||
from openedx.core.djangoapps.user_authn.cookies import _get_user_info_cookie_data
|
||||
from openedx.core.djangoapps.waffle_utils.testutils import override_waffle_flag
|
||||
from openedx.features.course_duration_limits.config import CONTENT_TYPE_GATING_FLAG
|
||||
from openedx.features.course_duration_limits.models import CourseDurationLimitConfig
|
||||
from student.helpers import DISABLE_UNENROLL_CERT_STATES
|
||||
from student.models import CourseEnrollment, UserProfile
|
||||
from student.signals import REFUND_ORDER
|
||||
@@ -723,13 +723,13 @@ class StudentDashboardTests(SharedModuleStoreTestCase, MilestonesTestCaseMixin,
|
||||
)
|
||||
|
||||
@override_waffle_flag(COURSE_UPDATE_WAFFLE_FLAG, True)
|
||||
@override_waffle_flag(CONTENT_TYPE_GATING_FLAG, True)
|
||||
def test_content_gating_course_card_changes(self):
|
||||
"""
|
||||
When a course is expired, the links on the course card should be removed.
|
||||
Links will be removed from the course title, course image and button (View Course/Resume Course).
|
||||
The course card should have an access expired message.
|
||||
"""
|
||||
CourseDurationLimitConfig.objects.create(enabled=True, enabled_as_of=date(2018, 1, 1))
|
||||
self.override_waffle_switch(True)
|
||||
|
||||
course = CourseFactory.create(start=self.THREE_YEARS_AGO)
|
||||
|
||||
@@ -3,7 +3,8 @@ Test the partitions and partitions service
|
||||
|
||||
"""
|
||||
|
||||
from unittest import TestCase
|
||||
from datetime import date
|
||||
from django.test import TestCase
|
||||
from mock import Mock, patch
|
||||
|
||||
from opaque_keys.edx.locator import CourseLocator
|
||||
@@ -15,6 +16,7 @@ from xmodule.partitions.partitions import (
|
||||
from xmodule.partitions.partitions_service import (
|
||||
PartitionService, get_all_partitions_for_course, FEATURES
|
||||
)
|
||||
from openedx.features.content_type_gating.models import ContentTypeGatingConfig
|
||||
|
||||
|
||||
class TestGroup(TestCase):
|
||||
@@ -435,17 +437,11 @@ class PartitionServiceBaseClass(PartitionTestCase):
|
||||
def setUp(self):
|
||||
super(PartitionServiceBaseClass, self).setUp()
|
||||
|
||||
content_gating_flag_patcher = patch(
|
||||
'openedx.features.content_type_gating.partitions.CONTENT_TYPE_GATING_FLAG.is_enabled',
|
||||
return_value=True,
|
||||
).start()
|
||||
self.addCleanup(content_gating_flag_patcher.stop)
|
||||
content_gating_ui_flag_patcher = patch(
|
||||
'openedx.features.content_type_gating.partitions.CONTENT_TYPE_GATING_STUDIO_UI_FLAG.is_enabled',
|
||||
return_value=True,
|
||||
).start()
|
||||
self.addCleanup(content_gating_ui_flag_patcher.stop)
|
||||
|
||||
ContentTypeGatingConfig.objects.create(
|
||||
enabled=True,
|
||||
enabled_as_of=date(2018, 1, 1),
|
||||
studio_override_enabled=True
|
||||
)
|
||||
self.course = Mock(id=CourseLocator('org_0', 'course_0', 'run_0'))
|
||||
self.partition_service = self._create_service("ma")
|
||||
|
||||
|
||||
@@ -129,16 +129,12 @@ class SplitTestModuleLMSTest(SplitTestModuleTest):
|
||||
|
||||
def setUp(self):
|
||||
super(SplitTestModuleLMSTest, self).setUp()
|
||||
|
||||
content_gating_flag_patcher = patch(
|
||||
'openedx.features.content_type_gating.partitions.CONTENT_TYPE_GATING_FLAG.is_enabled',
|
||||
return_value=False,
|
||||
'openedx.features.content_type_gating.partitions.ContentTypeGatingConfig.current',
|
||||
return_value=Mock(enabled=False, studio_override_enabled=False),
|
||||
).start()
|
||||
self.addCleanup(content_gating_flag_patcher.stop)
|
||||
content_gating_ui_flag_patcher = patch(
|
||||
'openedx.features.content_type_gating.partitions.CONTENT_TYPE_GATING_STUDIO_UI_FLAG.is_enabled',
|
||||
return_value=False,
|
||||
).start()
|
||||
self.addCleanup(content_gating_ui_flag_patcher.stop)
|
||||
|
||||
@ddt.data((0, 'split_test_cond0'), (1, 'split_test_cond1'))
|
||||
@ddt.unpack
|
||||
|
||||
Reference in New Issue
Block a user