From d05d789afab1daa52cda82c22746f93b729e0951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Fernanda=20Magallanes=20Z?= Date: Mon, 23 May 2022 16:04:09 -0400 Subject: [PATCH 1/3] test: add mfe config tests --- .../djangoapps/mfe_api/tests/test_views.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 openedx/core/djangoapps/mfe_api/tests/test_views.py diff --git a/openedx/core/djangoapps/mfe_api/tests/test_views.py b/openedx/core/djangoapps/mfe_api/tests/test_views.py new file mode 100644 index 000000000000..57b974c862f3 --- /dev/null +++ b/openedx/core/djangoapps/mfe_api/tests/test_views.py @@ -0,0 +1,30 @@ +""" +Test the MFE API +""" + +from django.conf import settings +from rest_framework import status + +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from openedx.core.lib.api.test_utils import ApiTestCase + + + +class MFEConfigTestCase(ApiTestCase): + """ + Test the MFE API + """ + + def setUp(self): + self.mfe_config_api_url = '/api/mfe/v1/config' + return super().setUp() + + def test_get_mfe_config(self): + """Test the get mfe config from MFE API.""" + response = self.client.get(self.mfe_config_api_url) + if settings.FEATURES.get('ENABLE_MFE_CONFIG_API'): + mfe_config = configuration_helpers.get_value('MFE_CONFIG',{}) + response_json = self.get_json(self.mfe_config_api_url) + assert response_json == mfe_config + else: + assert status.HTTP_404_NOT_FOUND == response.status_code From 6a5302969a0067bb776e07d64f573dfd4de22f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Fernanda=20Magallanes=20Z?= Date: Tue, 24 May 2022 09:01:10 -0400 Subject: [PATCH 2/3] test: fix it and simplify it --- .../djangoapps/mfe_api/tests/test_views.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/openedx/core/djangoapps/mfe_api/tests/test_views.py b/openedx/core/djangoapps/mfe_api/tests/test_views.py index 57b974c862f3..21ff3a2789b0 100644 --- a/openedx/core/djangoapps/mfe_api/tests/test_views.py +++ b/openedx/core/djangoapps/mfe_api/tests/test_views.py @@ -2,29 +2,27 @@ Test the MFE API """ +from unittest.mock import patch + from django.conf import settings +from django.urls import reverse from rest_framework import status from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.lib.api.test_utils import ApiTestCase - class MFEConfigTestCase(ApiTestCase): """ Test the MFE API """ - + @patch.dict(settings.FEATURES, {'ENABLE_MFE_CONFIG_API': True}) def setUp(self): - self.mfe_config_api_url = '/api/mfe/v1/config' + self.mfe_config_api_url = reverse('mfe_config_api') return super().setUp() def test_get_mfe_config(self): """Test the get mfe config from MFE API.""" - response = self.client.get(self.mfe_config_api_url) - if settings.FEATURES.get('ENABLE_MFE_CONFIG_API'): - mfe_config = configuration_helpers.get_value('MFE_CONFIG',{}) - response_json = self.get_json(self.mfe_config_api_url) - assert response_json == mfe_config - else: - assert status.HTTP_404_NOT_FOUND == response.status_code + mfe_config = configuration_helpers.get_value('MFE_CONFIG',{}) + response_json = self.get_json(self.mfe_config_api_url) + assert response_json == mfe_config From 6e7cd182c8c77125961be177ca15b4c757439027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Fernanda=20Magallanes=20Z?= Date: Tue, 24 May 2022 09:40:45 -0400 Subject: [PATCH 3/3] test: correct pylint issues --- openedx/core/djangoapps/mfe_api/tests/test_views.py | 1 - openedx/core/djangoapps/mfe_api/urls.py | 6 ++---- openedx/core/djangoapps/mfe_api/views.py | 4 ++++ 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/openedx/core/djangoapps/mfe_api/tests/test_views.py b/openedx/core/djangoapps/mfe_api/tests/test_views.py index 21ff3a2789b0..b9a286618145 100644 --- a/openedx/core/djangoapps/mfe_api/tests/test_views.py +++ b/openedx/core/djangoapps/mfe_api/tests/test_views.py @@ -6,7 +6,6 @@ from django.conf import settings from django.urls import reverse -from rest_framework import status from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.lib.api.test_utils import ApiTestCase diff --git a/openedx/core/djangoapps/mfe_api/urls.py b/openedx/core/djangoapps/mfe_api/urls.py index 6763594c1dec..129821f019f3 100644 --- a/openedx/core/djangoapps/mfe_api/urls.py +++ b/openedx/core/djangoapps/mfe_api/urls.py @@ -1,11 +1,9 @@ """ URL configuration for the mfe API """ - -from django.conf import settings -from django.urls import path, re_path +from django.urls import re_path from openedx.core.djangoapps.mfe_api.views import MFEConfigView urlpatterns = [ - re_path(fr'^v1/config', MFEConfigView.as_view(), name='mfe_config_api',) + re_path(r'^v1/config', MFEConfigView.as_view(), name='mfe_config_api',) ] diff --git a/openedx/core/djangoapps/mfe_api/views.py b/openedx/core/djangoapps/mfe_api/views.py index c046bb2c509a..b907effe6065 100644 --- a/openedx/core/djangoapps/mfe_api/views.py +++ b/openedx/core/djangoapps/mfe_api/views.py @@ -1,3 +1,7 @@ +""" +MFE API Views. +""" + from django.conf import settings from django.utils.decorators import method_decorator from django.views.decorators.cache import cache_page