diff --git a/openedx/core/djangoapps/courseware_api/tests/test_views.py b/openedx/core/djangoapps/courseware_api/tests/test_views.py index 2248023140e4..f72f32e4358f 100644 --- a/openedx/core/djangoapps/courseware_api/tests/test_views.py +++ b/openedx/core/djangoapps/courseware_api/tests/test_views.py @@ -2,6 +2,7 @@ Tests for courseware API """ +import itertools from datetime import datetime, timedelta from urllib.parse import urlencode from typing import Optional @@ -11,6 +12,7 @@ from completion.test_utils import CompletionWaffleTestMixin, submit_completions_for_testing from django.conf import settings from django.contrib.auth import get_user_model +from django.test import override_settings from django.test.client import RequestFactory from edx_django_utils.cache import TieredCache @@ -430,17 +432,16 @@ def test_can_access_proctored_exams_masquerading(self, masquerade_group_id, resu assert 'can_access_proctored_exams' in courseware_data assert courseware_data['can_access_proctored_exams'] == result - @override_waffle_flag(COURSEWARE_LEARNING_ASSISTANT, active=False) - def test_learning_assistant_enabled_disabled_waffle_flag(self): - response = self.client.get(self.url) - learning_assistant_enabled = response.json()['learning_assistant_enabled'] - self.assertFalse(learning_assistant_enabled) + @ddt.idata(itertools.product((True, False), (True, False))) + @ddt.unpack + def test_learning_assistant_enabled(self, setting_enabled, flag_enabled): + with override_settings(LEARNING_ASSISTANT_AVAILABLE=setting_enabled), \ + override_waffle_flag(COURSEWARE_LEARNING_ASSISTANT, active=flag_enabled): + response = self.client.get(self.url) - @override_waffle_flag(COURSEWARE_LEARNING_ASSISTANT, active=True) - def test_learning_assistant_enabled_enabled_waffle_flag(self): - response = self.client.get(self.url) learning_assistant_enabled = response.json()['learning_assistant_enabled'] - self.assertTrue(learning_assistant_enabled) + expected_value = setting_enabled or flag_enabled + self.assertEqual(learning_assistant_enabled, expected_value) @ddt.ddt diff --git a/openedx/core/djangoapps/courseware_api/views.py b/openedx/core/djangoapps/courseware_api/views.py index 704abdfc2df5..9360f4432a0c 100644 --- a/openedx/core/djangoapps/courseware_api/views.py +++ b/openedx/core/djangoapps/courseware_api/views.py @@ -367,7 +367,7 @@ def learning_assistant_enabled(self): """ Returns a boolean representing whether the requesting user should have access to the Xpert Learning Assistant. """ - return learning_assistant_is_active(self.course_key) + return getattr(settings, 'LEARNING_ASSISTANT_AVAILABLE', False) or learning_assistant_is_active(self.course_key) @method_decorator(transaction.non_atomic_requests, name='dispatch')