From f6f66d0f391e0459ef9cf06e8f0e425d834bc5d0 Mon Sep 17 00:00:00 2001 From: Maria Fernanda Magallanes Zubillaga Date: Mon, 4 Jul 2022 17:58:16 -0400 Subject: [PATCH] refactor!: change the api naming and url --- .github/workflows/pylint-checks.yml | 2 +- .github/workflows/unit-test-shards.json | 2 +- lms/djangoapps/mfe_api/urls.py | 10 ---------- .../{mfe_api => mfe_config_api}/__init__.py | 0 .../{mfe_api => mfe_config_api}/tests/__init__.py | 0 .../{mfe_api => mfe_config_api}/tests/test_views.py | 12 ++++++------ lms/djangoapps/mfe_config_api/urls.py | 10 ++++++++++ lms/djangoapps/{mfe_api => mfe_config_api}/views.py | 8 ++++---- lms/envs/common.py | 10 +++++----- lms/envs/test.py | 2 +- lms/urls.py | 2 +- 11 files changed, 29 insertions(+), 29 deletions(-) delete mode 100644 lms/djangoapps/mfe_api/urls.py rename lms/djangoapps/{mfe_api => mfe_config_api}/__init__.py (100%) rename lms/djangoapps/{mfe_api => mfe_config_api}/tests/__init__.py (100%) rename lms/djangoapps/{mfe_api => mfe_config_api}/tests/test_views.py (91%) create mode 100644 lms/djangoapps/mfe_config_api/urls.py rename lms/djangoapps/{mfe_api => mfe_config_api}/views.py (89%) diff --git a/.github/workflows/pylint-checks.yml b/.github/workflows/pylint-checks.yml index 43677f6bc1..9494fa60f0 100644 --- a/.github/workflows/pylint-checks.yml +++ b/.github/workflows/pylint-checks.yml @@ -17,7 +17,7 @@ jobs: - module-name: lms-1 path: "lms/djangoapps/badges/ lms/djangoapps/branding/ lms/djangoapps/bulk_email/ lms/djangoapps/bulk_enroll/ lms/djangoapps/bulk_user_retirement/ lms/djangoapps/ccx/ lms/djangoapps/certificates/ lms/djangoapps/commerce/ lms/djangoapps/course_api/ lms/djangoapps/course_blocks/ lms/djangoapps/course_home_api/ lms/djangoapps/course_wiki/ lms/djangoapps/coursewarehistoryextended/ lms/djangoapps/debug/ lms/djangoapps/courseware/ lms/djangoapps/course_goals/ lms/djangoapps/rss_proxy/ lms/djangoapps/save_for_later/" - module-name: lms-2 - path: "lms/djangoapps/gating/ lms/djangoapps/grades/ lms/djangoapps/instructor/ lms/djangoapps/instructor_analytics/ lms/djangoapps/discussion/ lms/djangoapps/edxnotes/ lms/djangoapps/email_marketing/ lms/djangoapps/experiments/ lms/djangoapps/instructor_task/ lms/djangoapps/learner_dashboard/ lms/djangoapps/lms_initialization/ lms/djangoapps/lms_xblock/ lms/djangoapps/lti_provider/ lms/djangoapps/mailing/ lms/djangoapps/mobile_api/ lms/djangoapps/monitoring/ lms/djangoapps/ora_staff_grader/ lms/djangoapps/program_enrollments/ lms/djangoapps/rss_proxy lms/djangoapps/static_template_view/ lms/djangoapps/staticbook/ lms/djangoapps/support/ lms/djangoapps/survey/ lms/djangoapps/teams/ lms/djangoapps/tests/ lms/djangoapps/user_tours/ lms/djangoapps/verify_student/ lms/djangoapps/mfe_api/ lms/envs/ lms/lib/ lms/tests.py" + path: "lms/djangoapps/gating/ lms/djangoapps/grades/ lms/djangoapps/instructor/ lms/djangoapps/instructor_analytics/ lms/djangoapps/discussion/ lms/djangoapps/edxnotes/ lms/djangoapps/email_marketing/ lms/djangoapps/experiments/ lms/djangoapps/instructor_task/ lms/djangoapps/learner_dashboard/ lms/djangoapps/lms_initialization/ lms/djangoapps/lms_xblock/ lms/djangoapps/lti_provider/ lms/djangoapps/mailing/ lms/djangoapps/mobile_api/ lms/djangoapps/monitoring/ lms/djangoapps/ora_staff_grader/ lms/djangoapps/program_enrollments/ lms/djangoapps/rss_proxy lms/djangoapps/static_template_view/ lms/djangoapps/staticbook/ lms/djangoapps/support/ lms/djangoapps/survey/ lms/djangoapps/teams/ lms/djangoapps/tests/ lms/djangoapps/user_tours/ lms/djangoapps/verify_student/ lms/djangoapps/mfe_config_api/ lms/envs/ lms/lib/ lms/tests.py" - module-name: openedx-1 path: "openedx/core/types/ openedx/core/djangoapps/ace_common/ openedx/core/djangoapps/agreements/ openedx/core/djangoapps/api_admin/ openedx/core/djangoapps/auth_exchange/ openedx/core/djangoapps/bookmarks/ openedx/core/djangoapps/cache_toolbox/ openedx/core/djangoapps/catalog/ openedx/core/djangoapps/ccxcon/ openedx/core/djangoapps/commerce/ openedx/core/djangoapps/common_initialization/ openedx/core/djangoapps/common_views/ openedx/core/djangoapps/config_model_utils/ openedx/core/djangoapps/content/ openedx/core/djangoapps/content_libraries/ openedx/core/djangoapps/contentserver/ openedx/core/djangoapps/cookie_metadata/ openedx/core/djangoapps/cors_csrf/ openedx/core/djangoapps/course_apps/ openedx/core/djangoapps/course_date_signals/ openedx/core/djangoapps/course_groups/ openedx/core/djangoapps/courseware_api/ openedx/core/djangoapps/crawlers/ openedx/core/djangoapps/credentials/ openedx/core/djangoapps/credit/ openedx/core/djangoapps/dark_lang/ openedx/core/djangoapps/debug/ openedx/core/djangoapps/demographics/ openedx/core/djangoapps/discussions/ openedx/core/djangoapps/django_comment_common/ openedx/core/djangoapps/embargo/ openedx/core/djangoapps/enrollments/ openedx/core/djangoapps/external_user_ids/ openedx/core/djangoapps/zendesk_proxy/ openedx/core/djangolib/ openedx/core/lib/ openedx/core/tests/ openedx/core/djangoapps/course_live/" - module-name: openedx-2 diff --git a/.github/workflows/unit-test-shards.json b/.github/workflows/unit-test-shards.json index c63ce0f97c..81a618f1e6 100644 --- a/.github/workflows/unit-test-shards.json +++ b/.github/workflows/unit-test-shards.json @@ -71,7 +71,7 @@ "lms/djangoapps/tests/", "lms/djangoapps/user_tours/", "lms/djangoapps/verify_student/", - "lms/djangoapps/mfe_api/", + "lms/djangoapps/mfe_config_api/", "lms/envs/", "lms/lib/", "lms/tests.py" diff --git a/lms/djangoapps/mfe_api/urls.py b/lms/djangoapps/mfe_api/urls.py deleted file mode 100644 index 5cc5152345..0000000000 --- a/lms/djangoapps/mfe_api/urls.py +++ /dev/null @@ -1,10 +0,0 @@ -""" URLs configuration for the mfe api.""" - -from django.urls import path - -from lms.djangoapps.mfe_api.views import MFEConfigView - -app_name = 'mfe_api' -urlpatterns = [ - path('v1/config', MFEConfigView.as_view(), name='config'), -] diff --git a/lms/djangoapps/mfe_api/__init__.py b/lms/djangoapps/mfe_config_api/__init__.py similarity index 100% rename from lms/djangoapps/mfe_api/__init__.py rename to lms/djangoapps/mfe_config_api/__init__.py diff --git a/lms/djangoapps/mfe_api/tests/__init__.py b/lms/djangoapps/mfe_config_api/tests/__init__.py similarity index 100% rename from lms/djangoapps/mfe_api/tests/__init__.py rename to lms/djangoapps/mfe_config_api/tests/__init__.py diff --git a/lms/djangoapps/mfe_api/tests/test_views.py b/lms/djangoapps/mfe_config_api/tests/test_views.py similarity index 91% rename from lms/djangoapps/mfe_api/tests/test_views.py rename to lms/djangoapps/mfe_config_api/tests/test_views.py index 8084f563a1..4e57907f06 100644 --- a/lms/djangoapps/mfe_api/tests/test_views.py +++ b/lms/djangoapps/mfe_config_api/tests/test_views.py @@ -17,10 +17,10 @@ class MFEConfigTestCase(APITestCase): Test the use case that exposes the site configuration with the mfe api. """ def setUp(self): - self.mfe_config_api_url = reverse("mfe_api:config") + self.mfe_config_api_url = reverse("mfe_config_api:config") return super().setUp() - @patch("lms.djangoapps.mfe_api.views.configuration_helpers") + @patch("lms.djangoapps.mfe_config_api.views.configuration_helpers") def test_get_mfe_config(self, configuration_helpers_mock): """Test the get mfe config from site configuration with the mfe api. @@ -37,7 +37,7 @@ class MFEConfigTestCase(APITestCase): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json(), {"EXAMPLE_VAR": "value"}) - @patch("lms.djangoapps.mfe_api.views.configuration_helpers") + @patch("lms.djangoapps.mfe_config_api.views.configuration_helpers") def test_get_mfe_config_with_queryparam(self, configuration_helpers_mock): """Test the get mfe config with a query param from site configuration. @@ -56,7 +56,7 @@ class MFEConfigTestCase(APITestCase): configuration_helpers_mock.get_value.assert_has_calls(calls) self.assertEqual(response.json(), {"EXAMPLE_VAR": "mymfe_value", "OTHER": "other"}) - @patch("lms.djangoapps.mfe_api.views.configuration_helpers") + @patch("lms.djangoapps.mfe_config_api.views.configuration_helpers") @ddt.data( [{}, {}, {}], [{"EXAMPLE_VAR": "value"}, {}, {"EXAMPLE_VAR": "value"}], @@ -93,8 +93,8 @@ class MFEConfigTestCase(APITestCase): configuration_helpers_mock.get_value.assert_has_calls(calls) self.assertEqual(response.json(), expected_response) - @patch("lms.djangoapps.mfe_api.views.configuration_helpers") - @override_settings(ENABLE_MFE_API=False) + @patch("lms.djangoapps.mfe_config_api.views.configuration_helpers") + @override_settings(ENABLE_MFE_CONFIG_API=False) def test_404_get_mfe_config(self, configuration_helpers_mock): """Test the 404 not found response from get mfe config. diff --git a/lms/djangoapps/mfe_config_api/urls.py b/lms/djangoapps/mfe_config_api/urls.py new file mode 100644 index 0000000000..8f63406a9a --- /dev/null +++ b/lms/djangoapps/mfe_config_api/urls.py @@ -0,0 +1,10 @@ +""" URLs configuration for the mfe api.""" + +from django.urls import path + +from lms.djangoapps.mfe_config_api.views import MFEConfigView + +app_name = 'mfe_config_api' +urlpatterns = [ + path('', MFEConfigView.as_view(), name='config'), +] diff --git a/lms/djangoapps/mfe_api/views.py b/lms/djangoapps/mfe_config_api/views.py similarity index 89% rename from lms/djangoapps/mfe_api/views.py rename to lms/djangoapps/mfe_config_api/views.py index db874c8479..932109b728 100644 --- a/lms/djangoapps/mfe_api/views.py +++ b/lms/djangoapps/mfe_config_api/views.py @@ -17,12 +17,12 @@ class MFEConfigView(APIView): Provides an API endpoint to get the MFE_CONFIG from site configuration. """ - @method_decorator(cache_page(settings.MFE_API_CONFIG_CACHE_TIMEOUT)) + @method_decorator(cache_page(settings.MFE_CONFIG_API_CACHE_TIMEOUT)) def get(self, request): """ - GET /api/mfe/v1/config + GET /api/v1/mfe_config or - GET /api/mfe/v1/config?mfe=name_of_mfe + GET /api/v1/mfe_config?mfe=name_of_mfe **GET Response Values** ``` @@ -40,7 +40,7 @@ class MFEConfigView(APIView): ``` """ - if not settings.ENABLE_MFE_API: + if not settings.ENABLE_MFE_CONFIG_API: return HttpResponseNotFound() mfe_config = configuration_helpers.get_value('MFE_CONFIG', {}) diff --git a/lms/envs/common.py b/lms/envs/common.py index 8befc45934..631dc57a2d 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -3253,7 +3253,7 @@ INSTALLED_APPS = [ 'blockstore.apps.bundles', # MFE API - 'lms.djangoapps.mfe_api', + 'lms.djangoapps.mfe_config_api', ] ######################### CSRF ######################################### @@ -5143,7 +5143,7 @@ COURSE_LIVE_GLOBAL_CREDENTIALS = {} PERSONALIZED_RECOMMENDATION_COOKIE_NAME = 'edx-user-personalized-recommendation' -# .. toggle_name: ENABLE_MFE_API +# .. toggle_name: ENABLE_MFE_CONFIG_API # .. toggle_implementation: DjangoSetting # .. toggle_default: False # .. toggle_description: Set to True to enable MFE Config REST API. This is disabled by @@ -5153,10 +5153,10 @@ PERSONALIZED_RECOMMENDATION_COOKIE_NAME = 'edx-user-personalized-recommendation' # .. toggle_target_removal_date: None # .. toggle_warnings: None # .. toggle_tickets: None -ENABLE_MFE_API = False +ENABLE_MFE_CONFIG_API = False -# .. setting_name: MFE_API_CONFIG_CACHE_TIMEOUT +# .. setting_name: MFE_CONFIG_API_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 +MFE_CONFIG_API_CACHE_TIMEOUT = 60 * 5 diff --git a/lms/envs/test.py b/lms/envs/test.py index 8d2f65ca3b..8164e8abb2 100644 --- a/lms/envs/test.py +++ b/lms/envs/test.py @@ -649,4 +649,4 @@ COURSE_LIVE_GLOBAL_CREDENTIALS["BIG_BLUE_BUTTON"] = { } ################## MFE API #################### -ENABLE_MFE_API = True +ENABLE_MFE_CONFIG_API = True diff --git a/lms/urls.py b/lms/urls.py index 974e14bc27..c7669bf9ea 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -1025,5 +1025,5 @@ urlpatterns += [ # MFE API urls urlpatterns += [ - path('api/mfe/', include(('lms.djangoapps.mfe_api.urls', 'lms.djangoapps.mfe_api'), namespace='mfe_api')) + path('api/v1/mfe_config', include(('lms.djangoapps.mfe_config_api.urls', 'lms.djangoapps.mfe_config_api'), namespace='mfe_config_api')) ]