def test_register_view_takes_allow_cdn(self): router = MixedViewRouter() router.register_view("view-1", View, name="view-1", allow_cdn=True) router.register_view("view-2", View, name="view-2", allow_cdn=False) assert [v.name for v in router.registered_view_urls] == ["view-1", "view-2"] assert router.registered_view_urls[0].allow_cdn assert not router.registered_view_urls[1].allow_cdn
def test_it_doesnt_pass_the_api_root_url_to_the_api_root_view( self, mocker): mock_api_view = mocker.Mock() router = MixedViewRouter(view=mock_api_view) router.register_view('view', View, name='standalone-view') router.get_urls() assert mock_api_view.called_once_with( [Whatever(lambda v: v.name == 'standalone-view')])
from django.conf.urls import url, include from normandy.base.api.routers import MixedViewRouter from normandy.studies.api.v3 import views # API Router router = MixedViewRouter() router.register("extension", views.ExtensionViewSet) app_name = "studies" urlpatterns = [url(r"", include(router.urls))]
from django.conf.urls import include, url from normandy.base import views from normandy.base.api import views as api_views from normandy.base.api.routers import MixedViewRouter # API Router router = MixedViewRouter() router.register("user", api_views.UserViewSet) router.register("group", api_views.GroupViewSet) urlpatterns = [ url(r"^$", views.index, name="index"), 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/v3/", include(router.urls)), ]
from django.conf import settings from django.conf.urls import include, url from django.conf.urls.static import static 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 = [] if settings.ADMIN_ENABLED: urlpatterns += [url(r"^admin/", admin.site.urls)]
from django.conf.urls import url, include from normandy.base.api.routers import MixedViewRouter from normandy.recipes.api.v3 import views app_name = "recipes" # API Router router = MixedViewRouter() router.register("action", views.ActionViewSet) router.register("recipe", views.RecipeViewSet) router.register("recipe_revision", views.RecipeRevisionViewSet) router.register("approval_request", views.ApprovalRequestViewSet) router.register_view("filters", views.Filters, name="filters") urlpatterns = [ url(r"", include(router.urls)), url( r"^identicon/(?P<generation>v[0-9]):(?P<seed>.{1,64})\.svg", views.IdenticonView.as_view(), name="identicon", ), ]
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 # 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) v1_router.register_view('filters', api_v1_views.Filters, name='filters') v2_router = MixedViewRouter() v2_router.register('action', api_v2_views.ActionViewSet) v2_router.register('recipe', api_v2_views.RecipeViewSet) v2_router.register('recipe_revision', api_v2_views.RecipeRevisionViewSet) v2_router.register(r'approval_request', api_v2_views.ApprovalRequestViewSet) app_name = 'recipes' urlpatterns = [ url(r'^api/v2/', include(v2_router.urls)), url(r'^api/v1/', include(v1_router.urls)), url(r'^api/v1/action/(?P<name>[_\-\w]+)/implementation/(?P<impl_hash>[a-zA-Z0-9_-]*)/$',
def test_get_urls_includes_non_viewset_views(self): router = MixedViewRouter() router.register_view('view', View, name='standalone-view') urls = router.get_urls() assert len(urls) == 2 assert urls[0].name == 'standalone-view'
from django.conf.urls import include, url from normandy.base.api.routers import MixedViewRouter from normandy.base.api.v3 import views from normandy.base.api.views import APIRootView # API Router router = MixedViewRouter() router.register("user", views.UserViewSet) router.register("group", views.GroupViewSet) app_name = "base" urlpatterns = [ url(r"^$", APIRootView.as_view()), url(r"^service_info/", views.ServiceInfoView.as_view(), name="service-info"), url(r"", include(router.urls)), ]
def test_get_urls_includes_non_viewset_views(self): router = MixedViewRouter() router.register_view("view", View, name="standalone-view") urls = router.get_urls() assert len(urls) == 1 assert urls[0].name == "standalone-view"
def test_register_view_requires_name(self): router = MixedViewRouter() with pytest.raises(TypeError) as err: router.register_view("view", View, allow_cdn=True) assert "missing 1 required keyword-only argument: 'name'" in str(err)
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) v2_router.register("recipe_revision", api_v2_views.RecipeRevisionViewSet) v2_router.register(r"approval_request", api_v2_views.ApprovalRequestViewSet) v3_router = MixedViewRouter() v3_router.register("action", api_v3_views.ActionViewSet) v3_router.register("recipe", api_v3_views.RecipeViewSet) v3_router.register("recipe_revision", api_v3_views.RecipeRevisionViewSet) v3_router.register(r"approval_request", api_v3_views.ApprovalRequestViewSet) v3_router.register_view("filters", api_v3_views.Filters, name="filters")
from django.conf.urls import include, url from normandy.base.api.routers import MixedViewRouter from normandy.recipes.api.v1 import views app_name = "recipes" # API Router router = MixedViewRouter() router.register("action", views.ActionViewSet) router.register("recipe", views.RecipeViewSet) router.register("recipe_revision", views.RecipeRevisionViewSet) router.register("approval_request", views.ApprovalRequestViewSet) router.register_view( "classify_client", views.ClassifyClient, name="classify-client", allow_cdn=False ) urlpatterns = [ url( r"^action/(?P<name>[_\-\w]+)/implementation/(?P<impl_hash>[a-zA-Z0-9_-]*)/$", views.ActionImplementationView.as_view(), name="action-implementation", ), url(r"", include(router.urls)), ]
def test_register_view_requires_name(self): router = MixedViewRouter() with pytest.raises(TypeError) as err: router.register_view('view', View, allow_cdn=True) assert "missing 1 required keyword-only argument: 'name'" in str(err)
def test_get_urls_includes_api_root(self): router = MixedViewRouter() urls = router.get_urls() assert len(urls) == 1 assert urls[0].name == router.root_view_name
from django.conf.urls import url, include from normandy.base.api.routers import MixedViewRouter from normandy.recipes.api.views import ( ActionImplementationView, ActionViewSet, ClassifyClient, Filters, RecipeViewSet, RecipeRevisionViewSet, ) # API Router router = MixedViewRouter() router.register('action', ActionViewSet) router.register('recipe', RecipeViewSet) router.register('recipe_revision', RecipeRevisionViewSet) router.register_view('classify_client', ClassifyClient, name='classify-client', allow_cdn=False) router.register_view('filters', Filters, name='filters') app_name = 'recipes' urlpatterns = [ url(r'^api/v1/', include(router.urls)), url(r'^api/v1/action/(?P<name>[_\-\w]+)/implementation/(?P<impl_hash>[0-9a-f]{40})/$', ActionImplementationView.as_view(), name='action-implementation'),
from django.conf.urls import url, include from normandy.base.api.routers import MixedViewRouter from normandy.recipes.api.v2 import views as api_v2_views from normandy.recipes.api.v3 import views as api_v3_views # API Router v2_router = MixedViewRouter() v2_router.register("action", api_v2_views.ActionViewSet) v2_router.register("recipe", api_v2_views.RecipeViewSet) v2_router.register("recipe_revision", api_v2_views.RecipeRevisionViewSet) v2_router.register(r"approval_request", api_v2_views.ApprovalRequestViewSet) v3_router = MixedViewRouter() v3_router.register("action", api_v3_views.ActionViewSet) v3_router.register("recipe", api_v3_views.RecipeViewSet) v3_router.register("recipe_revision", api_v3_views.RecipeRevisionViewSet) v3_router.register(r"approval_request", api_v3_views.ApprovalRequestViewSet) v3_router.register_view("filters", api_v3_views.Filters, name="filters") app_name = "recipes" urlpatterns = [ 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", api_v2_views.IdenticonView.as_view(), name="identicon-v2", ), url( r"^api/v3/identicon/(?P<generation>v[0-9]):(?P<seed>.{1,64})\.svg",
from django.conf.urls import url, include from normandy.base.api.routers import MixedViewRouter from normandy.studies.api.v2 import views as v2_views from normandy.studies.api.v3 import views as v3_views # API Router v2_router = MixedViewRouter() v2_router.register("extension", v2_views.ExtensionViewSet) v3_router = MixedViewRouter() v3_router.register("extension", v3_views.ExtensionViewSet) app_name = "studies" urlpatterns = [ url(r"^api/v2/", include((v2_router.urls, "studies"), namespace="v2")), url(r"^api/v3/", include((v3_router.urls, "studies"), namespace="v3")), ]