Skip to content
This repository was archived by the owner on Jan 29, 2025. It is now read-only.

Commit

Permalink
Merge #1748
Browse files Browse the repository at this point in the history
1748: Consolidate v1 API routers into a single router r=mythmon a=rehandalal

r?

Co-authored-by: Rehan Dalal <[email protected]>
  • Loading branch information
bors[bot] and rehandalal committed Feb 19, 2019
2 parents 2ff5bb2 + 3997f62 commit ef585c6
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 27 deletions.
1 change: 1 addition & 0 deletions normandy/base/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion normandy/base/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
]
2 changes: 1 addition & 1 deletion normandy/recipes/api/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion normandy/recipes/tests/api/v1/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion normandy/recipes/tests/api/v2/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion normandy/recipes/tests/api/v3/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 0 additions & 17 deletions normandy/recipes/urls.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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<name>[_\-\w]+)/implementation/(?P<impl_hash>[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/(?P<generation>v[0-9]):(?P<seed>.{1,64})\.svg",
Expand Down
5 changes: 0 additions & 5 deletions normandy/studies/urls.py
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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")),
]
25 changes: 25 additions & 0 deletions normandy/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand All @@ -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<name>[_\-\w]+)/implementation/(?P<impl_hash>[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
Expand Down

0 comments on commit ef585c6

Please sign in to comment.