示例#1
0
 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
示例#2
0
 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')])
示例#3
0
 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'
示例#4
0
 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
示例#5
0
 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)
示例#6
0
文件: urls.py 项目: mythmon/normandy
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))]
示例#7
0
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",
示例#8
0
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_-]*)/$',