From e249a6c243e7bc15fab9f804d19f55637657e8ea Mon Sep 17 00:00:00 2001 From: Shadi Naif Date: Mon, 9 Dec 2024 09:50:27 +0300 Subject: [PATCH] fix: duplication in URL routes --- futurex_openedx_extensions/__init__.py | 2 +- futurex_openedx_extensions/dashboard/urls.py | 11 ++++++----- tests/test_dashboard/test_views.py | 15 +++++++-------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/futurex_openedx_extensions/__init__.py b/futurex_openedx_extensions/__init__.py index 2e4f1496..4dad3d16 100644 --- a/futurex_openedx_extensions/__init__.py +++ b/futurex_openedx_extensions/__init__.py @@ -1,3 +1,3 @@ """One-line description for README and other doc files.""" -__version__ = '0.9.16' +__version__ = '0.9.17' diff --git a/futurex_openedx_extensions/dashboard/urls.py b/futurex_openedx_extensions/dashboard/urls.py index 46178db6..85de3c3a 100644 --- a/futurex_openedx_extensions/dashboard/urls.py +++ b/futurex_openedx_extensions/dashboard/urls.py @@ -13,9 +13,10 @@ QUERY_ALLOWED_SCOPES = '|'.join(ClickhouseQuery.allowed_scopes()) -router = DefaultRouter() -router.register(r'user_roles', views.UserRolesManagementView, basename='user-roles') -router.register(r'tasks', views.DataExportManagementView, basename='data-export-tasks') +roles_router = DefaultRouter() +roles_router.register(r'user_roles', views.UserRolesManagementView, basename='user-roles') +export_router = DefaultRouter() +export_router.register(r'tasks', views.DataExportManagementView, basename='data-export-tasks') urlpatterns = [ re_path(r'^api/fx/accessible/v1/info/$', views.AccessibleTenantsInfoView.as_view(), name='accessible-info'), @@ -38,8 +39,8 @@ name='learner-courses' ), re_path(r'^api/fx/roles/v1/my_roles/$', views.MyRolesView.as_view(), name='my-roles'), - re_path(r'^api/fx/roles/v1/', include(router.urls)), - re_path(r'^api/fx/export/v1/', include(router.urls)), + re_path(r'^api/fx/roles/v1/', include(roles_router.urls)), + re_path(r'^api/fx/export/v1/', include(export_router.urls)), re_path(r'^api/fx/statistics/v1/course_statuses/$', views.CourseStatusesView.as_view(), name='course-statuses'), re_path(r'^api/fx/statistics/v1/rating/$', views.GlobalRatingView.as_view(), name='statistics-rating'), re_path(r'^api/fx/statistics/v1/total_counts/$', views.TotalCountsView.as_view(), name='total-counts'), diff --git a/tests/test_dashboard/test_views.py b/tests/test_dashboard/test_views.py index 0c92cb0a..890151f0 100644 --- a/tests/test_dashboard/test_views.py +++ b/tests/test_dashboard/test_views.py @@ -46,10 +46,6 @@ def setUp(self): self.view_name = self.VIEW_NAME self.url_args = [] self.staff_user = 2 - self.registry = {} - for _, viewset, basename in urls.router.registry: - self.registry[basename] = viewset - self.viewset_base = None @property def url(self): @@ -466,17 +462,20 @@ class TestDataExportTasksView(BaseTestViewMixin): def set_action(self, action, task_id=1): """Set the viewname and client method""" - self.viewset_base = 'data-export-tasks' - self.view_name = f'fx_dashboard:{self.viewset_base}-{action}' + self.view_name = f'fx_dashboard:data-export-tasks-{action}' self.url_args = [] if action == 'detail': self.url_args = [task_id] def test_permission_classes(self): """Verify that the view has the correct permission classes""" + registry = {} + for _, viewset, basename in urls.export_router.registry: + registry[basename] = viewset + for action in self.view_actions: self.set_action(action) - view_class = self.registry['data-export-tasks'] + view_class = registry['data-export-tasks'] self.assertEqual(view_class.permission_classes, [FXHasTenantCourseAccess]) def test_unauthorized(self): @@ -1018,7 +1017,7 @@ def test_permission_classes(self, action): self.set_action(action) registry = {} - for _, viewset, basename in urls.router.registry: + for _, viewset, basename in urls.roles_router.registry: registry[basename] = viewset view_class = registry['user-roles'] self.assertEqual(view_class.permission_classes, [FXHasTenantAllCoursesAccess])