refactor: set ENABLE_MFE_API as a top level setting

This commit is contained in:
Maria Fernanda Magallanes Zubillaga
2022-06-23 22:25:15 -04:00
parent 05b602f7dd
commit 60e6de05fc
4 changed files with 25 additions and 28 deletions

View File

@@ -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.

View File

@@ -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'):

View File

@@ -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

View File

@@ -649,4 +649,4 @@ COURSE_LIVE_GLOBAL_CREDENTIALS["BIG_BLUE_BUTTON"] = {
}
################## MFE API ####################
FEATURES['ENABLE_MFE_API'] = True
ENABLE_MFE_API = True