Skip to content

Commit d995b25

Browse files
committed
fix: make Discovery service dependency optional for discussion notifications
test: patch CatalogIntegration.is_enabled in expiration tests to restore mock behavior test: patch CatalogIntegration.is_enabled in setUp/tearDown feat: make course duration limits configurable refactor: clears ambigous name fix: remove unsued env vars
1 parent ee35515 commit d995b25

File tree

4 files changed

+52
-8
lines changed

4 files changed

+52
-8
lines changed

lms/envs/common.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,18 @@
709709
# .. setting_description: Sets the number of days after which the gradebook will freeze following the course's end.
710710
GRADEBOOK_FREEZE_DAYS = 30
711711

712+
# .. setting_name: COURSE_ACCESS_DURATION_MIN_WEEKS
713+
# .. setting_default: 4
714+
# .. setting_description: Minimum course duration in weeks when Discovery service data is unavailable or course has no
715+
# .. weeks_to_complete value. Used as fallback for course access duration calculations.
716+
COURSE_ACCESS_DURATION_MIN_WEEKS = 4
717+
718+
# .. setting_name: COURSE_ACCESS_DURATION_MAX_WEEKS
719+
# .. setting_default: 18
720+
# .. setting_description: Maximum course duration in weeks. Course access duration is bounded by this upper limit
721+
# .. regardless of Discovery service data.
722+
COURSE_ACCESS_DURATION_MAX_WEEKS = 18
723+
712724
RETRY_CALENDAR_SYNC_EMAIL_MAX_ATTEMPTS = 5
713725

714726
############################# SET PATH INFORMATION #############################

openedx/core/djangoapps/course_date_signals/utils.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,24 @@
66

77
from datetime import timedelta
88

9+
from django.conf import settings
910
from openedx.core.djangoapps.catalog.utils import get_course_run_details
11+
from openedx.core.djangoapps.catalog.models import CatalogIntegration
1012

13+
MIN_DURATION = timedelta(
14+
weeks=getattr(settings, 'COURSE_DURATION_MIN_WEEKS', 4)
15+
)
16+
MAX_DURATION = timedelta(
17+
weeks=getattr(settings, 'COURSE_DURATION_MAX_WEEKS', 18)
18+
)
1119

12-
MIN_DURATION = timedelta(weeks=4)
13-
MAX_DURATION = timedelta(weeks=18)
20+
21+
def catalog_integration_enabled():
22+
"""
23+
Check if catalog integration is enabled
24+
"""
25+
catalog_integration = CatalogIntegration.current()
26+
return catalog_integration.is_enabled()
1427

1528

1629
def get_expected_duration(course_id):
@@ -20,12 +33,13 @@ def get_expected_duration(course_id):
2033

2134
access_duration = MIN_DURATION
2235

23-
# The user course expiration date is the content availability date
24-
# plus the weeks_to_complete field from course-discovery.
25-
discovery_course_details = get_course_run_details(course_id, ['weeks_to_complete'])
26-
expected_weeks = discovery_course_details.get('weeks_to_complete')
27-
if expected_weeks:
28-
access_duration = timedelta(weeks=expected_weeks)
36+
if catalog_integration_enabled():
37+
discovery_course_details = get_course_run_details(
38+
course_id, ['weeks_to_complete']
39+
)
40+
expected_weeks = discovery_course_details.get('weeks_to_complete')
41+
if expected_weeks:
42+
access_duration = timedelta(weeks=expected_weeks)
2943

3044
# Course access duration is bounded by the min and max duration.
3145
access_duration = max(MIN_DURATION, min(MAX_DURATION, access_duration))

openedx/core/djangoapps/notifications/tests/test_filters.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44
from datetime import timedelta
55
from unittest import mock
6+
from unittest.mock import patch
67

78
import ddt
89
from django.utils.timezone import now
@@ -43,6 +44,12 @@ class CourseExpirationTestCase(ModuleStoreTestCase):
4344

4445
def setUp(self):
4546
super().setUp() # lint-amnesty, pylint: disable=super-with-arguments
47+
self.catalog_patch = patch(
48+
'openedx.core.djangoapps.catalog.models.CatalogIntegration.is_enabled',
49+
return_value=True
50+
)
51+
self.catalog_patch.start()
52+
4653
self.course = CourseFactory(
4754
start=now() - timedelta(weeks=10),
4855
)
@@ -58,6 +65,10 @@ def setUp(self):
5865
expired_audit.created = now() - timedelta(weeks=6)
5966
expired_audit.save()
6067

68+
def tearDown(self):
69+
self.catalog_patch.stop()
70+
super().tearDown()
71+
6172
@mock.patch("openedx.core.djangoapps.course_date_signals.utils.get_course_run_details")
6273
def test_audit_expired_filter_with_no_role(
6374
self,

openedx/features/course_duration_limits/tests/test_course_expiration.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from datetime import timedelta
66
from unittest import mock
7+
from unittest.mock import patch
78

89
import ddt
910
from django.conf import settings
@@ -46,6 +47,11 @@ class CourseExpirationTestCase(ModuleStoreTestCase, MasqueradeMixin):
4647
"""Tests to verify the get_user_course_expiration_date function is working correctly"""
4748
def setUp(self):
4849
super().setUp() # lint-amnesty, pylint: disable=super-with-arguments
50+
self.catalog_patch = patch(
51+
'openedx.core.djangoapps.catalog.models.CatalogIntegration.is_enabled',
52+
return_value=True
53+
)
54+
self.catalog_patch.start()
4955
self.course = CourseFactory(
5056
start=now() - timedelta(weeks=10),
5157
)
@@ -72,6 +78,7 @@ def setUp(self):
7278
add_course_mode(self.course)
7379

7480
def tearDown(self):
81+
self.catalog_patch.stop()
7582
CourseEnrollment.unenroll(self.user, self.course.id)
7683
super().tearDown() # lint-amnesty, pylint: disable=super-with-arguments
7784

0 commit comments

Comments
 (0)