示例#1
0
    def test_get_urls_missing_methods(self):
        class EmptyView(ViewSet):
            serializer_class = TrunkSerializer

        router = Router(trailing_slash=False)
        urls = router.get_urls_for_viewset("prefix", EmptyView, "basename")
        self.assertEqual(urls, [])
示例#2
0
 def test_get_urls_for_viewset(self):
     router = Router(trailing_slash=False)
     # router.register(LeafViewSet)
     urls = router.get_urls_for_viewset("prefix", LeafViewSet, "basename")
     base_names = [url.name for url in urls]
     self.assertListEqual(
         base_names,
         ["basename-list", "basename-detail", "basename-relationships-branch"],
     )
示例#3
0
 def test_get_routes_read_only(self):
     router = Router(trailing_slash=False)
     routes = {route.name: route.mapping for route in router.get_routes(LeafViewSet)}
     self.assertIn("{basename}-relationships-branch", routes)
     mappings = routes["{basename}-relationships-branch"]
     self.assertNotIn("post", mappings)
     self.assertNotIn("put", mappings)
     self.assertNotIn("patch", mappings)
     self.assertNotIn("delete", mappings)
示例#4
0
 def test_get_urls_no_root_view(self):
     router = Router(trailing_slash=False)
     router.include_root_view = False
     router.register(LeafViewSet)
     urls = router.get_urls()
     base_names = [url.name for url in urls]
     self.assertNotIn("api-root", base_names)
示例#5
0
 def test_get_urls_no_format_suffixes(self):
     router = Router(trailing_slash=False)
     router.include_format_suffixes = False
     router.register(LeafViewSet)
     urls = router.get_urls()
     patterns = [url.pattern._regex for url in urls]  # noqa
     for pattern in patterns:
         self.assertNotIn(".(?P<format>[a-z0-9]+)", pattern)
示例#6
0
from drf_jsonapi.routers import Router

from .views import TrunkViewSet, LeafViewSet

router = Router(trailing_slash=False)
router.register(TrunkViewSet)
router.register(LeafViewSet)
urlpatterns = router.urls
示例#7
0
    openapi.Info(
        title="Vacasa Housekeeping API",
        default_version="v1",
        contact=openapi.Contact(email="*****@*****.**"),
    ),
    validators=[],
    public=True,
    permission_classes=(AllowAny, ),
    generator_class=OpenAPISchemaGenerator,
)

urlpatterns = [
    re_path(
        r"swagger(?P<format>.json|.yaml)$",
        schema_view.without_ui(cache_timeout=1),
        name="schema-json",
    ),
    path("spec",
         schema_view.with_ui("redoc", cache_timeout=1),
         name="schema-redoc"),
]

router = Router(trailing_slash=False)
router.register(TestView)
urlpatterns += router.urls

non_standard_endpoint = path("nonstandard/<uuid>",
                             NonStandardViewSet.as_view({"get": "get_item"}))

urlpatterns += [non_standard_endpoint]
示例#8
0
 def test_url_segment_kwarg_overrides_relationship_name(self):
     router = Router(trailing_slash=False)
     urls = router.get_urls_for_viewset("prefix", TrunkViewSet, "basename")
     patterns = [url.pattern._regex for url in urls]  # noqa
     self.assertIn("^prefix/(?P<pk>[^/.]+)/relationships/tree-roots$", patterns)