Skip to content

Commit

Permalink
feat: replace la waffle flag with django setting (#34236)
Browse files Browse the repository at this point in the history
  • Loading branch information
alangsto authored Feb 20, 2024
1 parent 0882832 commit 4fb1dba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions openedx/core/djangoapps/courseware_api/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Tests for courseware API
"""

import itertools
from datetime import datetime, timedelta
from urllib.parse import urlencode
from typing import Optional
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion openedx/core/djangoapps/courseware_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 4fb1dba

Please sign in to comment.