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_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')])
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'
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 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)] urlpatterns += [ url(r"", include("normandy.base.urls")), url(r"", include("normandy.recipes.urls")), url(r"", include("normandy.selfrepair.urls")), url(r"", include("normandy.health.urls")), url(r"", include("normandy.studies.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 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", api_v2_views.IdenticonView.as_view(), name="identicon", ),
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 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'), ]
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)), ]
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_-]*)/$',