From 60e6de05fce70c817791f1c650a2df639a5145be Mon Sep 17 00:00:00 2001 From: Maria Fernanda Magallanes Zubillaga Date: Thu, 23 Jun 2022 22:25:15 -0400 Subject: [PATCH] refactor: set ENABLE_MFE_API as a top level setting --- lms/djangoapps/mfe_api/tests/test_views.py | 6 ++-- lms/djangoapps/mfe_api/views.py | 9 +++--- lms/envs/common.py | 36 +++++++++++----------- lms/envs/test.py | 2 +- 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/lms/djangoapps/mfe_api/tests/test_views.py b/lms/djangoapps/mfe_api/tests/test_views.py index a8994ab098..b17ca460dc 100644 --- a/lms/djangoapps/mfe_api/tests/test_views.py +++ b/lms/djangoapps/mfe_api/tests/test_views.py @@ -2,9 +2,7 @@ Test the use cases of the views of the mfe api. """ -from unittest.mock import patch - -from django.conf import settings +from django.test import override_settings from django.urls import reverse from rest_framework import status @@ -47,7 +45,7 @@ class MFEConfigTestCase(ApiTestCase): response_json = self.get_json(f'{self.mfe_config_api_url}?mfe={mfe}') assert response_json == mfe_config - @patch.dict(settings.FEATURES, {'ENABLE_MFE_API': False}) + @override_settings(ENABLE_MFE_API=False) def test_404_get_mfe_config(self): """Test the 404 not found response from get mfe config. diff --git a/lms/djangoapps/mfe_api/views.py b/lms/djangoapps/mfe_api/views.py index 10e4c86ea5..db874c8479 100644 --- a/lms/djangoapps/mfe_api/views.py +++ b/lms/djangoapps/mfe_api/views.py @@ -3,7 +3,7 @@ MFE API Views for useful information related to mfes. """ from django.conf import settings -from django.http import JsonResponse +from django.http import HttpResponseNotFound, JsonResponse from django.utils.decorators import method_decorator from django.views.decorators.cache import cache_page from rest_framework import status @@ -30,7 +30,7 @@ class MFEConfigView(APIView): "BASE_URL": "https://name_of_mfe.example.com", "LANGUAGE_PREFERENCE_COOKIE_NAME": "example-language-preference", "CREDENTIALS_BASE_URL": "https://credentials.example.com", - "DOSCOVERY_API_BASE_URL": "https://discovery.example.com", + "DISCOVERY_API_BASE_URL": "https://discovery.example.com", "LMS_BASE_URL": "https://courses.example.com", "LOGIN_URL": "https://courses.example.com/login", "LOGOUT_URL": "https://courses.example.com/logout", @@ -40,9 +40,8 @@ class MFEConfigView(APIView): ``` """ - if not settings.FEATURES.get('ENABLE_MFE_API'): - msg = 'MFE API not found. Try setting FEATURES["ENABLE_MFE_API"] to true.' - return JsonResponse({'message': msg}, status=status.HTTP_404_NOT_FOUND) + if not settings.ENABLE_MFE_API: + return HttpResponseNotFound() mfe_config = configuration_helpers.get_value('MFE_CONFIG', {}) if request.query_params.get('mfe'): diff --git a/lms/envs/common.py b/lms/envs/common.py index 0934236dc1..8befc45934 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1018,18 +1018,6 @@ FEATURES = { # .. toggle_target_removal_date: None # .. toggle_tickets: 'https://openedx.atlassian.net/browse/MST-1458' 'ENABLE_CERTIFICATES_IDV_REQUIREMENT': False, - - # .. toggle_name: FEATURES['ENABLE_MFE_API'] - # .. toggle_implementation: DjangoSetting - # .. toggle_default: False - # .. toggle_description: Set to True to enable MFE Config REST API. This is disabled by - # default. - # .. toggle_use_cases: open_edx - # .. toggle_creation_date: 2022-05-20 - # .. toggle_target_removal_date: None - # .. toggle_warnings: None - # .. toggle_tickets: None - 'ENABLE_MFE_API': False, } # Specifies extra XBlock fields that should available when requested via the Course Blocks API @@ -4924,12 +4912,6 @@ HIBP_LOGIN_BLOCK_PASSWORD_FREQUENCY_THRESHOLD = 5 # .. toggle_tickets: https://openedx.atlassian.net/browse/VAN-838 ENABLE_DYNAMIC_REGISTRATION_FIELDS = False -# .. setting_name: MFE_API_CONFIG_CACHE_TIMEOUT -# .. setting_default: 60*5 -# .. setting_description: The MFE_CONFIG site configuration will be cached during the -# specified time -MFE_API_CONFIG_CACHE_TIMEOUT = 60 * 5 - ############### Settings for the ace_common plugin ################# # Note that all settings are actually defined by the plugin # pylint: disable=wrong-import-position @@ -5160,3 +5142,21 @@ ENTERPRISE_BACKEND_SERVICE_EDX_OAUTH2_PROVIDER_URL = "http://127.0.0.1:8000/oaut COURSE_LIVE_GLOBAL_CREDENTIALS = {} PERSONALIZED_RECOMMENDATION_COOKIE_NAME = 'edx-user-personalized-recommendation' + +# .. toggle_name: ENABLE_MFE_API +# .. toggle_implementation: DjangoSetting +# .. toggle_default: False +# .. toggle_description: Set to True to enable MFE Config REST API. This is disabled by +# default. +# .. toggle_use_cases: open_edx +# .. toggle_creation_date: 2022-05-20 +# .. toggle_target_removal_date: None +# .. toggle_warnings: None +# .. toggle_tickets: None +ENABLE_MFE_API = False + +# .. setting_name: MFE_API_CONFIG_CACHE_TIMEOUT +# .. setting_default: 60*5 +# .. setting_description: The MFE_CONFIG site configuration will be cached during the +# specified time +MFE_API_CONFIG_CACHE_TIMEOUT = 60 * 5 diff --git a/lms/envs/test.py b/lms/envs/test.py index 4186d98e45..8d2f65ca3b 100644 --- a/lms/envs/test.py +++ b/lms/envs/test.py @@ -649,4 +649,4 @@ COURSE_LIVE_GLOBAL_CREDENTIALS["BIG_BLUE_BUTTON"] = { } ################## MFE API #################### -FEATURES['ENABLE_MFE_API'] = True +ENABLE_MFE_API = True