Coverage for rest_framework/routers : + 94% +
+
+ From 3d4bb4b5533fa281c2f11c12ceb0a9ae61aa0d54 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 21 Jun 2013 22:03:07 +0100 Subject: Ensure action kwargs properly handdled. Refs #940. --- htmlcov/rest_framework_routers.html | 595 ++++++++++++++++++++++++++++++++++++ 1 file changed, 595 insertions(+) create mode 100644 htmlcov/rest_framework_routers.html (limited to 'htmlcov/rest_framework_routers.html') diff --git a/htmlcov/rest_framework_routers.html b/htmlcov/rest_framework_routers.html new file mode 100644 index 00000000..f08d5007 --- /dev/null +++ b/htmlcov/rest_framework_routers.html @@ -0,0 +1,595 @@ + + +
+ + + + +
+
+Hot-keys on this page
++ r + m + x + p toggle line displays +
++ j + k next/prev highlighted chunk +
++ 0 (zero) top of page +
++ 1 (one) first highlighted chunk +
+| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | +
+ """ +Routers provide a convenient and consistent way of automatically +determining the URL conf for your API. ++ They are used by simply instantiating a Router class, and then registering +all the required ViewSets with that router. ++ For example, you might have a `urls.py` that looks something like this: ++ router = routers.DefaultRouter() +router.register('users', UserViewSet, 'user') +router.register('accounts', AccountViewSet, 'account') ++ urlpatterns = router.urls +""" + ++ + + + + + + + + + + + + """ +Partially format a format_string, swapping out any +'{methodname}' or '{methodnamehyphen}' components. +""" + + + + + ++ + + + + + + + + + + + """ +If `base_name` is not specified, attempt to automatically determine +it from the viewset. +""" +raise NotImplemented('get_default_base_name must be overridden') ++ + """ +Return a list of URL patterns, given the registered viewsets. +""" +raise NotImplemented('get_urls must be overridden') ++ + def urls(self): + + + ++ + + + # List route. +Route( +url=r'^{prefix}{trailing_slash}$', +mapping={ +'get': 'list', +'post': 'create' +}, +name='{basename}-list', +initkwargs={'suffix': 'List'} +), +# Detail route. +Route( +url=r'^{prefix}/{lookup}{trailing_slash}$', +mapping={ +'get': 'retrieve', +'put': 'update', +'patch': 'partial_update', +'delete': 'destroy' +}, +name='{basename}-detail', +initkwargs={'suffix': 'Instance'} +), +# Dynamically generated routes. +# Generated using @action or @link decorators on methods of the viewset. +Route( +url=r'^{prefix}/{lookup}/{methodname}{trailing_slash}$', +mapping={ +'{httpmethod}': '{methodname}', +}, +name='{basename}-{methodnamehyphen}', +initkwargs={} +), +] ++ + + + + + """ +If `base_name` is not specified, attempt to automatically determine +it from the viewset. +""" + + + + ++ + 'not automatically determine the name from the viewset, as ' \ +'it does not have a `.model` or `.queryset` attribute.' ++ + + + """ +Augment `self.routes` with any dynamically generated routes. ++ Returns a list of the Route namedtuple. +""" ++ # Determine any `@action` or `@link` decorated methods on the viewset + + + + + + ++ + + + # Dynamic routes (@link or @action decorator) + + + + +url=replace_methodname(route.url, methodname), +mapping=dict((httpmethod, methodname) for httpmethod in httpmethods), +name=replace_methodname(route.name, methodname), +initkwargs=initkwargs, +)) +else: +# Standard route + ++ + + + """ +Given a viewset, and a mapping of http methods to actions, +return a new mapping which only includes any mappings that +are actually implemented by the viewset. +""" + + + + + ++ + """ +Given a viewset, return the portion of URL regex that is used +to match against a single instance. +""" + + + ++ + """ +Use the registered viewsets to generate a list of URL patterns. +""" + ++ + + + + + + # Only actions which actually exist on the viewset will be bound + + +continue ++ # Build the url pattern + +prefix=prefix, +lookup=lookup, +trailing_slash=self.trailing_slash +) + + + ++ + + + + """ +The default router extends the SimpleRouter, but also adds in a default +API root view, and adds format suffix patterns to the URLs. +""" + + + ++ + """ +Return a view to use as the API root. +""" + + + + ++ + + + + ret = {} +for key, url_name in api_root_dict.items(): +ret[key] = reverse(url_name, request=request, format=format) +return Response(ret) ++ + + + """ +Generate the list of URL patterns, including a default root view +for the API, and appending `.json` style format suffixes. +""" + ++ + + + + + + + + + + + + |
+