From 9069ce995027222601593c9031f6d3368ef72548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Fernanda=20Magallanes=20Z?= Date: Thu, 9 Jun 2022 08:53:48 -0400 Subject: [PATCH] fix: get merged response from mfe_config and mfe_config_mymfe --- lms/djangoapps/mfe_api/tests/test_views.py | 15 +++++++++++++++ lms/djangoapps/mfe_api/views.py | 16 +++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lms/djangoapps/mfe_api/tests/test_views.py b/lms/djangoapps/mfe_api/tests/test_views.py index 2b28bd87fc..a8994ab098 100644 --- a/lms/djangoapps/mfe_api/tests/test_views.py +++ b/lms/djangoapps/mfe_api/tests/test_views.py @@ -32,6 +32,21 @@ class MFEConfigTestCase(ApiTestCase): response_json = self.get_json(self.mfe_config_api_url) assert response_json == mfe_config + def test_get_mfe_config_with_queryparams(self): + """Test the get mfe config with a query params from site configuration. + + Expected result: + - Inside self.get_json pass the response is a json and the status is 200 asserts. + - The configuration obtained by the api is equal to its site configuration in the + MFE_CONFIG and MFE_CONFIG_MYMFE merged on top. + """ + mfe_config = configuration_helpers.get_value('MFE_CONFIG', {}) + mfe = "mymfe" + mfe_config.update(configuration_helpers.get_value(f'MFE_CONFIG_{mfe.upper()}', {})) + + 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}) 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 40764b4e6c..10e4c86ea5 100644 --- a/lms/djangoapps/mfe_api/views.py +++ b/lms/djangoapps/mfe_api/views.py @@ -21,11 +21,21 @@ class MFEConfigView(APIView): def get(self, request): """ GET /api/mfe/v1/config + or + GET /api/mfe/v1/config?mfe=name_of_mfe **GET Response Values** ``` { - "LOGO_URL": "https://example.com/logo.png", + "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", + "LMS_BASE_URL": "https://courses.example.com", + "LOGIN_URL": "https://courses.example.com/login", + "LOGOUT_URL": "https://courses.example.com/logout", + "STUDIO_BASE_URL": "https://studio.example.com", + "LOGO_URL": "https://courses.example.com/logo.png" } ``` """ @@ -34,9 +44,9 @@ class MFEConfigView(APIView): msg = 'MFE API not found. Try setting FEATURES["ENABLE_MFE_API"] to true.' return JsonResponse({'message': msg}, status=status.HTTP_404_NOT_FOUND) - mfe_config = {'MFE_CONFIG': configuration_helpers.get_value('MFE_CONFIG', {})} + mfe_config = configuration_helpers.get_value('MFE_CONFIG', {}) if request.query_params.get('mfe'): mfe = str(request.query_params.get('mfe')).upper() - mfe_config[f'MFE_CONFIG_{mfe}']= configuration_helpers.get_value(f'MFE_CONFIG_{mfe}',{}) + mfe_config.update(configuration_helpers.get_value(f'MFE_CONFIG_{mfe}', {})) return JsonResponse(mfe_config, status=status.HTTP_200_OK)