From 3997f62dbb990b431c5f3be2fd88a5b8844eb9f1 Mon Sep 17 00:00:00 2001 From: Rehan Dalal Date: Tue, 19 Feb 2019 15:15:22 -0500 Subject: [PATCH] Consolidate v1 API routers into a single router --- normandy/base/tests/api/test_api.py | 1 + normandy/base/urls.py | 1 - normandy/recipes/api/fields.py | 2 +- normandy/recipes/tests/api/v1/test_api.py | 2 +- normandy/recipes/tests/api/v2/test_api.py | 2 +- normandy/recipes/tests/api/v3/test_api.py | 2 +- normandy/recipes/urls.py | 17 --------------- normandy/studies/urls.py | 5 ----- normandy/urls.py | 25 +++++++++++++++++++++++ 9 files changed, 30 insertions(+), 27 deletions(-) diff --git a/normandy/base/tests/api/test_api.py b/normandy/base/tests/api/test_api.py index 948a30492..d07dfb67f 100644 --- a/normandy/base/tests/api/test_api.py +++ b/normandy/base/tests/api/test_api.py @@ -26,6 +26,7 @@ def test_it_works(self, api_client): "reciperevision-list": "http://testserver/api/v1/recipe_revision/", "classify-client": "http://testserver/api/v1/classify_client/", "approvalrequest-list": "http://testserver/api/v1/approval_request/", + "extension-list": "http://testserver/api/v1/extension/", } def test_it_redirects_classify_client_to_app_server(self, api_client, settings): diff --git a/normandy/base/urls.py b/normandy/base/urls.py index a62f81137..0967552aa 100644 --- a/normandy/base/urls.py +++ b/normandy/base/urls.py @@ -16,6 +16,5 @@ url(r"^favicon.ico", views.favicon), url(r"^api/v2/service_info/", api_views.ServiceInfoView.as_view(), name="service-info-v2"), url(r"^api/v3/service_info/", api_views.ServiceInfoView.as_view(), name="service-info"), - url(r"^api/v1/user/me/", api_views.CurrentUserView.as_view(), name="current-user"), url(r"^api/v3/", include(router.urls)), ] diff --git a/normandy/recipes/api/fields.py b/normandy/recipes/api/fields.py index c21f5cea1..f013afcbf 100644 --- a/normandy/recipes/api/fields.py +++ b/normandy/recipes/api/fields.py @@ -31,7 +31,7 @@ class ActionImplementationHyperlinkField(HyperlinkedIdentityField): This includes hashes and possibly redirects to the CDN. """ - def __init__(self, view_name="recipes:action-implementation", **kwargs): + def __init__(self, view_name="action-implementation", **kwargs): super().__init__(view_name=view_name, **kwargs) def get_url(self, obj, view_name, request, format): diff --git a/normandy/recipes/tests/api/v1/test_api.py b/normandy/recipes/tests/api/v1/test_api.py index 4c847dcfc..50bd655dd 100644 --- a/normandy/recipes/tests/api/v1/test_api.py +++ b/normandy/recipes/tests/api/v1/test_api.py @@ -31,7 +31,7 @@ def test_it_serves_actions(self, api_client): res = api_client.get("/api/v1/action/") action_url = reverse( - "recipes:action-implementation", + "action-implementation", kwargs={"name": action.name, "impl_hash": action.implementation_hash}, ) assert res.status_code == 200 diff --git a/normandy/recipes/tests/api/v2/test_api.py b/normandy/recipes/tests/api/v2/test_api.py index 412e72fa4..230a05af6 100644 --- a/normandy/recipes/tests/api/v2/test_api.py +++ b/normandy/recipes/tests/api/v2/test_api.py @@ -39,7 +39,7 @@ def test_it_serves_actions(self, api_client): res = api_client.get("/api/v2/action/") action_url = reverse( - "recipes:action-implementation", + "action-implementation", kwargs={"name": action.name, "impl_hash": action.implementation_hash}, ) assert res.status_code == 200 diff --git a/normandy/recipes/tests/api/v3/test_api.py b/normandy/recipes/tests/api/v3/test_api.py index a7c481705..aa2e953d5 100644 --- a/normandy/recipes/tests/api/v3/test_api.py +++ b/normandy/recipes/tests/api/v3/test_api.py @@ -39,7 +39,7 @@ def test_it_serves_actions(self, api_client): res = api_client.get("/api/v3/action/") action_url = reverse( - "recipes:action-implementation", + "action-implementation", kwargs={"name": action.name, "impl_hash": action.implementation_hash}, ) assert res.status_code == 200 diff --git a/normandy/recipes/urls.py b/normandy/recipes/urls.py index 2c5f66e2e..7fc963102 100644 --- a/normandy/recipes/urls.py +++ b/normandy/recipes/urls.py @@ -1,22 +1,11 @@ from django.conf.urls import url, include from normandy.base.api.routers import MixedViewRouter -from normandy.recipes.api.v1 import views as api_v1_views from normandy.recipes.api.v2 import views as api_v2_views from normandy.recipes.api.v3 import views as api_v3_views # API Router -v1_router = MixedViewRouter() -v1_router.register("action", api_v1_views.ActionViewSet) -v1_router.register("recipe", api_v1_views.RecipeViewSet) -v1_router.register("recipe_revision", api_v1_views.RecipeRevisionViewSet) -v1_router.register(r"approval_request", api_v1_views.ApprovalRequestViewSet) - -v1_router.register_view( - "classify_client", api_v1_views.ClassifyClient, name="classify-client", allow_cdn=False -) - v2_router = MixedViewRouter() v2_router.register("action", api_v2_views.ActionViewSet) v2_router.register("recipe", api_v2_views.RecipeViewSet) @@ -33,12 +22,6 @@ app_name = "recipes" urlpatterns = [ - url(r"^api/v1/", include((v1_router.urls, "recipes"), namespace="v1")), - url( - r"^api/v1/action/(?P[_\-\w]+)/implementation/(?P[a-zA-Z0-9_-]*)/$", - api_v1_views.ActionImplementationView.as_view(), - name="action-implementation", - ), url(r"^api/v2/", include((v2_router.urls, "recipes"), namespace="v2")), url( r"^api/v2/identicon/(?Pv[0-9]):(?P.{1,64})\.svg", diff --git a/normandy/studies/urls.py b/normandy/studies/urls.py index 27d059257..f0af57b44 100644 --- a/normandy/studies/urls.py +++ b/normandy/studies/urls.py @@ -1,15 +1,11 @@ from django.conf.urls import url, include from normandy.base.api.routers import MixedViewRouter -from normandy.studies.api.v1 import views as v1_views from normandy.studies.api.v2 import views as v2_views from normandy.studies.api.v3 import views as v3_views # API Router -v1_router = MixedViewRouter() -v1_router.register("extension", v1_views.ExtensionViewSet) - v2_router = MixedViewRouter() v2_router.register("extension", v2_views.ExtensionViewSet) @@ -19,7 +15,6 @@ app_name = "studies" urlpatterns = [ - url(r"^api/v1/", include((v1_router.urls, "studies"), namespace="v1")), url(r"^api/v2/", include((v2_router.urls, "studies"), namespace="v2")), url(r"^api/v3/", include((v3_router.urls, "studies"), namespace="v3")), ] diff --git a/normandy/urls.py b/normandy/urls.py index e1fa50444..0e8d9502c 100644 --- a/normandy/urls.py +++ b/normandy/urls.py @@ -4,6 +4,23 @@ from django.contrib import admin from rest_framework_swagger.views import get_swagger_view +from normandy.base.api import views as base_api_views +from normandy.base.api.routers import MixedViewRouter +from normandy.recipes.api.v1 import views as recipes_api_v1_views +from normandy.studies.api.v1 import views as studies_api_v1_views + + +# API Router +v1_router = MixedViewRouter() +v1_router.register("action", recipes_api_v1_views.ActionViewSet) +v1_router.register("recipe", recipes_api_v1_views.RecipeViewSet) +v1_router.register("recipe_revision", recipes_api_v1_views.RecipeRevisionViewSet) +v1_router.register(r"approval_request", recipes_api_v1_views.ApprovalRequestViewSet) +v1_router.register_view( + "classify_client", recipes_api_v1_views.ClassifyClient, name="classify-client", allow_cdn=False +) + +v1_router.register("extension", studies_api_v1_views.ExtensionViewSet) urlpatterns = [] @@ -17,6 +34,14 @@ url(r"", include("normandy.health.urls")), url(r"", include("normandy.studies.urls")), url(r"api/docs/", get_swagger_view()), + # v1 API + url(r"^api/v1/", include((v1_router.urls, "normandy"), namespace="v1")), + url( + r"^api/v1/action/(?P[_\-\w]+)/implementation/(?P[a-zA-Z0-9_-]*)/$", + recipes_api_v1_views.ActionImplementationView.as_view(), + name="action-implementation", + ), + url(r"^api/v1/user/me/", base_api_views.CurrentUserView.as_view(), name="current-user"), ] # static handles serving uploaded files during development; it disables